From c8964e3183516ee245d4b0d02d22be8887a0baae Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Wed, 5 Aug 2026 17:31:36 +0000 Subject: [PATCH 1/5] Add initial opentelemetry-instrumentation-genai-bedrock boilerplate --- docs-requirements.txt | 1 + instrumentation/README.md | 1 + .../.changelog/.gitignore | 1 + .../.changelog/360.added | 1 + .../LICENSE | 201 ++++++++++++++++++ .../README.rst | 33 +++ .../pyproject.toml | 90 ++++++++ .../instrumentation/genai/bedrock/__init__.py | 40 ++++ .../instrumentation/genai/bedrock/package.py | 4 + .../instrumentation/genai/bedrock/version.py | 4 + .../tests/__init__.py | 2 + .../tests/conftest.py | 32 +++ .../tests/requirements.latest.txt | 8 + .../tests/requirements.oldest.txt | 5 + .../tests/test_instrumentor.py | 37 ++++ pyproject.toml | 5 + tox.ini | 16 ++ uv.lock | 68 ++++++ 18 files changed, 549 insertions(+) create mode 100644 instrumentation/opentelemetry-instrumentation-genai-bedrock/.changelog/.gitignore create mode 100644 instrumentation/opentelemetry-instrumentation-genai-bedrock/.changelog/360.added create mode 100644 instrumentation/opentelemetry-instrumentation-genai-bedrock/LICENSE create mode 100644 instrumentation/opentelemetry-instrumentation-genai-bedrock/README.rst create mode 100644 instrumentation/opentelemetry-instrumentation-genai-bedrock/pyproject.toml create mode 100644 instrumentation/opentelemetry-instrumentation-genai-bedrock/src/opentelemetry/instrumentation/genai/bedrock/__init__.py create mode 100644 instrumentation/opentelemetry-instrumentation-genai-bedrock/src/opentelemetry/instrumentation/genai/bedrock/package.py create mode 100644 instrumentation/opentelemetry-instrumentation-genai-bedrock/src/opentelemetry/instrumentation/genai/bedrock/version.py create mode 100644 instrumentation/opentelemetry-instrumentation-genai-bedrock/tests/__init__.py create mode 100644 instrumentation/opentelemetry-instrumentation-genai-bedrock/tests/conftest.py create mode 100644 instrumentation/opentelemetry-instrumentation-genai-bedrock/tests/requirements.latest.txt create mode 100644 instrumentation/opentelemetry-instrumentation-genai-bedrock/tests/requirements.oldest.txt create mode 100644 instrumentation/opentelemetry-instrumentation-genai-bedrock/tests/test_instrumentor.py diff --git a/docs-requirements.txt b/docs-requirements.txt index 09f9659b1..21a3ca7ee 100644 --- a/docs-requirements.txt +++ b/docs-requirements.txt @@ -9,6 +9,7 @@ wrapt>=2.2.2,<3.0.0 # Required by instrumentation packages agno>=2.8.6 anthropic>=0.120.2 +boto3>=1.40.46 claude-agent-sdk>=0.2.130 google-genai>=2.16.0 langchain>=1.3.14 diff --git a/instrumentation/README.md b/instrumentation/README.md index 5c8bb36f4..f7628d674 100644 --- a/instrumentation/README.md +++ b/instrumentation/README.md @@ -3,6 +3,7 @@ | --------------- | ------------------ | --------------- | -------------- | | [opentelemetry-instrumentation-genai-agno](./opentelemetry-instrumentation-genai-agno) | agno >= 2.0.0 | No | development | [opentelemetry-instrumentation-genai-anthropic](./opentelemetry-instrumentation-genai-anthropic) | anthropic >= 0.16.0 | No | development +| [opentelemetry-instrumentation-genai-bedrock](./opentelemetry-instrumentation-genai-bedrock) | boto3 >= 1.40.46 | No | development | [opentelemetry-instrumentation-genai-claude-agent-sdk](./opentelemetry-instrumentation-genai-claude-agent-sdk) | claude-agent-sdk >= 0.1.14 | No | development | [opentelemetry-instrumentation-genai-crewai](./opentelemetry-instrumentation-genai-crewai) | crewai >= 1.10.1 | No | development | [opentelemetry-instrumentation-genai-langchain](./opentelemetry-instrumentation-genai-langchain) | langchain >= 0.3.21 | No | development diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/.changelog/.gitignore b/instrumentation/opentelemetry-instrumentation-genai-bedrock/.changelog/.gitignore new file mode 100644 index 000000000..9755a07fb --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-genai-bedrock/.changelog/.gitignore @@ -0,0 +1 @@ + !.gitignore diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/.changelog/360.added b/instrumentation/opentelemetry-instrumentation-genai-bedrock/.changelog/360.added new file mode 100644 index 000000000..eb8575357 --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-genai-bedrock/.changelog/360.added @@ -0,0 +1 @@ +Add the initial Amazon Bedrock instrumentation package setup. diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/LICENSE b/instrumentation/opentelemetry-instrumentation-genai-bedrock/LICENSE new file mode 100644 index 000000000..261eeb9e9 --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-genai-bedrock/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/README.rst b/instrumentation/opentelemetry-instrumentation-genai-bedrock/README.rst new file mode 100644 index 000000000..b2f515bf0 --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-genai-bedrock/README.rst @@ -0,0 +1,33 @@ +OpenTelemetry Amazon Bedrock Instrumentation +============================================ + +This package provides the setup for instrumenting Amazon Bedrock with OpenTelemetry +Generative AI semantic conventions. Amazon Bedrock operation instrumentation will be +added in follow-up changes. + +Installation +------------ + +:: + + pip install opentelemetry-instrumentation-genai-bedrock + +Usage +----- + +:: + + from opentelemetry.instrumentation.genai.bedrock import BedrockInstrumentor + + BedrockInstrumentor().instrument() + +Configuration +------------- + +By default, prompts and completions are not captured. To capture message content, set the +environment variable ``OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT`` to one of +``NO_CONTENT``, ``SPAN_ONLY``, ``EVENT_ONLY``, or ``SPAN_AND_EVENT``: + +:: + + export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=SPAN_AND_EVENT diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/pyproject.toml b/instrumentation/opentelemetry-instrumentation-genai-bedrock/pyproject.toml new file mode 100644 index 000000000..0ffeb5a7e --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-genai-bedrock/pyproject.toml @@ -0,0 +1,90 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "opentelemetry-instrumentation-genai-bedrock" +dynamic = ["version"] +description = "OpenTelemetry Amazon Bedrock instrumentation" +readme = "README.rst" +license = "Apache-2.0" +requires-python = ">=3.10" +authors = [ + { name = "OpenTelemetry Authors", email = "cncf-opentelemetry-contributors@lists.cncf.io" }, +] +classifiers = [ + "Development Status :: 4 - Beta", + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3.14", +] +dependencies = [ + "opentelemetry-api ~= 1.43", + "opentelemetry-instrumentation >= 0.64b0, <1", + "opentelemetry-semantic-conventions >= 0.64b0, <1", + "opentelemetry-util-genai >= 1.0b0, <2", +] + +[project.optional-dependencies] +instruments = [ + "boto3 >= 1.40.46", +] + +[project.entry-points.opentelemetry_instrumentor] +bedrock = "opentelemetry.instrumentation.genai.bedrock:BedrockInstrumentor" + +[project.urls] +Homepage = "https://github.com/open-telemetry/opentelemetry-python-genai/tree/main/instrumentation/opentelemetry-instrumentation-genai-bedrock" +Repository = "https://github.com/open-telemetry/opentelemetry-python-genai" + +[tool.hatch.version] +path = "src/opentelemetry/instrumentation/genai/bedrock/version.py" + +[tool.hatch.build.targets.sdist] +include = ["/src", "/tests"] + +[tool.hatch.build.targets.wheel] +packages = ["src/opentelemetry"] + +[tool.pytest.ini_options] +testpaths = ["tests"] + +[tool.towncrier] +directory = ".changelog" +filename = "CHANGELOG.md" +start_string = "\n" +template = "../../scripts/changelog_template.j2" +issue_format = "[#{issue}](https://github.com/open-telemetry/opentelemetry-python-genai/pull/{issue})" +wrap = true +issue_pattern = "^(\\d+)" + +[[tool.towncrier.type]] +directory = "added" +name = "Added" +showcontent = true + +[[tool.towncrier.type]] +directory = "changed" +name = "Changed" +showcontent = true + +[[tool.towncrier.type]] +directory = "deprecated" +name = "Deprecated" +showcontent = true + +[[tool.towncrier.type]] +directory = "removed" +name = "Removed" +showcontent = true + +[[tool.towncrier.type]] +directory = "fixed" +name = "Fixed" +showcontent = true diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/src/opentelemetry/instrumentation/genai/bedrock/__init__.py b/instrumentation/opentelemetry-instrumentation-genai-bedrock/src/opentelemetry/instrumentation/genai/bedrock/__init__.py new file mode 100644 index 000000000..58bea5f00 --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-genai-bedrock/src/opentelemetry/instrumentation/genai/bedrock/__init__.py @@ -0,0 +1,40 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +"""OpenTelemetry Amazon Bedrock instrumentation.""" + +from __future__ import annotations + +from collections.abc import Collection +from typing import Any + +from opentelemetry.instrumentation.genai.bedrock.package import _instruments +from opentelemetry.instrumentation.instrumentor import BaseInstrumentor +from opentelemetry.util.genai.completion_hook import load_completion_hook +from opentelemetry.util.genai.handler import TelemetryHandler + +__all__ = ["BedrockInstrumentor"] + + +class BedrockInstrumentor(BaseInstrumentor): + """An instrumentor for Amazon Bedrock.""" + + def instrumentation_dependencies(self) -> Collection[str]: + return _instruments + + def _instrument(self, **kwargs: Any) -> None: + """Enable Amazon Bedrock instrumentation.""" + completion_hook = ( + kwargs.get("completion_hook") or load_completion_hook() + ) + TelemetryHandler( + tracer_provider=kwargs.get("tracer_provider"), + meter_provider=kwargs.get("meter_provider"), + logger_provider=kwargs.get("logger_provider"), + completion_hook=completion_hook, + ) + # Amazon Bedrock patching will be added in a follow-up change. + + def _uninstrument(self, **kwargs: Any) -> None: + """Disable Amazon Bedrock instrumentation.""" + # Amazon Bedrock unpatching will be added in a follow-up change. diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/src/opentelemetry/instrumentation/genai/bedrock/package.py b/instrumentation/opentelemetry-instrumentation-genai-bedrock/src/opentelemetry/instrumentation/genai/bedrock/package.py new file mode 100644 index 000000000..f7e6ae1d6 --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-genai-bedrock/src/opentelemetry/instrumentation/genai/bedrock/package.py @@ -0,0 +1,4 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +_instruments = ("boto3 >= 1.40.46",) diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/src/opentelemetry/instrumentation/genai/bedrock/version.py b/instrumentation/opentelemetry-instrumentation-genai-bedrock/src/opentelemetry/instrumentation/genai/bedrock/version.py new file mode 100644 index 000000000..8920c2929 --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-genai-bedrock/src/opentelemetry/instrumentation/genai/bedrock/version.py @@ -0,0 +1,4 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +__version__ = "1.1b0.dev" diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/tests/__init__.py b/instrumentation/opentelemetry-instrumentation-genai-bedrock/tests/__init__.py new file mode 100644 index 000000000..e57cf4aba --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-genai-bedrock/tests/__init__.py @@ -0,0 +1,2 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/tests/conftest.py b/instrumentation/opentelemetry-instrumentation-genai-bedrock/tests/conftest.py new file mode 100644 index 000000000..3f916eeac --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-genai-bedrock/tests/conftest.py @@ -0,0 +1,32 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +"""Test configuration for Amazon Bedrock instrumentation.""" + +from collections.abc import Iterator + +import pytest + +from opentelemetry.instrumentation.genai.bedrock import BedrockInstrumentor +from opentelemetry.sdk._logs import LoggerProvider +from opentelemetry.sdk.metrics import MeterProvider +from opentelemetry.sdk.trace import TracerProvider +from opentelemetry.test_util_genai.instrumentor import instrument + +pytest_plugins = ["opentelemetry.test_util_genai.fixtures"] + + +@pytest.fixture +def instrument_bedrock( + tracer_provider: TracerProvider, + logger_provider: LoggerProvider, + meter_provider: MeterProvider, +) -> Iterator[BedrockInstrumentor]: + """Instrument Amazon Bedrock with the shared test providers.""" + with instrument( + BedrockInstrumentor(), + tracer_provider=tracer_provider, + logger_provider=logger_provider, + meter_provider=meter_provider, + ) as instrumentor: + yield instrumentor diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/tests/requirements.latest.txt b/instrumentation/opentelemetry-instrumentation-genai-bedrock/tests/requirements.latest.txt new file mode 100644 index 000000000..94b3a5f6e --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-genai-bedrock/tests/requirements.latest.txt @@ -0,0 +1,8 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# Exercise the latest supported Amazon Bedrock (boto3) release with workspace instrumentation. +boto3 + +-e util/opentelemetry-util-genai +-e instrumentation/opentelemetry-instrumentation-genai-bedrock diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/tests/requirements.oldest.txt b/instrumentation/opentelemetry-instrumentation-genai-bedrock/tests/requirements.oldest.txt new file mode 100644 index 000000000..c97b1761d --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-genai-bedrock/tests/requirements.oldest.txt @@ -0,0 +1,5 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# The oldest tox factor resolves declared dependencies from pyproject.toml +# with UV_RESOLUTION=lowest-direct. There are no additional test-only pins. diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/tests/test_instrumentor.py b/instrumentation/opentelemetry-instrumentation-genai-bedrock/tests/test_instrumentor.py new file mode 100644 index 000000000..2a982ce7f --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-genai-bedrock/tests/test_instrumentor.py @@ -0,0 +1,37 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +"""Tests for the Amazon Bedrock instrumentor lifecycle.""" + +from opentelemetry.instrumentation.genai.bedrock import BedrockInstrumentor +from opentelemetry.sdk._logs import LoggerProvider +from opentelemetry.sdk.metrics import MeterProvider +from opentelemetry.sdk.trace import TracerProvider + + +def test_instrumentation_dependencies() -> None: + assert BedrockInstrumentor().instrumentation_dependencies() == ( + "boto3 >= 1.40.46", + ) + + +def test_instrument_uninstrument_cycle( + tracer_provider: TracerProvider, + logger_provider: LoggerProvider, + meter_provider: MeterProvider, +) -> None: + instrumentor = BedrockInstrumentor() + + for _ in range(2): + instrumentor.instrument( + tracer_provider=tracer_provider, + logger_provider=logger_provider, + meter_provider=meter_provider, + ) + instrumentor.uninstrument() + + +def test_instrument_with_global_providers() -> None: + instrumentor = BedrockInstrumentor() + instrumentor.instrument() + instrumentor.uninstrument() diff --git a/pyproject.toml b/pyproject.toml index 7ece268b7..68d8a38c9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,6 +13,7 @@ dependencies = [ "opentelemetry-util-genai", "opentelemetry-instrumentation-genai-agno[instruments]", "opentelemetry-instrumentation-genai-anthropic[instruments]", + "opentelemetry-instrumentation-genai-bedrock[instruments]", "opentelemetry-instrumentation-genai-claude-agent-sdk[instruments]", "opentelemetry-instrumentation-genai-crewai[instruments]", "opentelemetry-instrumentation-google-genai[instruments]", @@ -46,6 +47,7 @@ opentelemetry-test-util-genai = { workspace = true } opentelemetry-util-genai = { workspace = true } opentelemetry-instrumentation-genai-agno = { workspace = true } opentelemetry-instrumentation-genai-anthropic = { workspace = true } +opentelemetry-instrumentation-genai-bedrock = { workspace = true } opentelemetry-instrumentation-genai-claude-agent-sdk = { workspace = true } opentelemetry-instrumentation-genai-crewai = { workspace = true } opentelemetry-instrumentation-google-genai = { workspace = true } @@ -116,6 +118,7 @@ reportDeprecated = false # Ignore deprecation on GenAI enums in opentelemetry.s include = [ "instrumentation/opentelemetry-instrumentation-genai-agno", "instrumentation/opentelemetry-instrumentation-genai-anthropic", + "instrumentation/opentelemetry-instrumentation-genai-bedrock", "instrumentation/opentelemetry-instrumentation-genai-claude-agent-sdk", "instrumentation/opentelemetry-instrumentation-genai-crewai", "instrumentation/opentelemetry-instrumentation-genai-langchain", @@ -133,6 +136,8 @@ exclude = [ "instrumentation/opentelemetry-instrumentation-genai-agno/examples/**/*.py", "instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/**/*.py", "instrumentation/opentelemetry-instrumentation-genai-anthropic/examples/**/*.py", + "instrumentation/opentelemetry-instrumentation-genai-bedrock/tests/**/*.py", + "instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/**/*.py", "instrumentation/opentelemetry-instrumentation-genai-claude-agent-sdk/tests/**/*.py", "instrumentation/opentelemetry-instrumentation-genai-claude-agent-sdk/examples/**/*.py", "instrumentation/opentelemetry-instrumentation-genai-crewai/tests/**/*.py", diff --git a/tox.ini b/tox.ini index ce3694aa0..c3c92ff85 100644 --- a/tox.ini +++ b/tox.ini @@ -48,6 +48,11 @@ envlist = py314-test-instrumentation-genai-anthropic-conformance lint-instrumentation-genai-anthropic + ; instrumentation-genai-bedrock + py3{10,11,12,13,14}-test-instrumentation-genai-bedrock-latest + py310-test-instrumentation-genai-bedrock-oldest + lint-instrumentation-genai-bedrock + ; instrumentation-genai-claude-agent-sdk py3{10,11,12,13}-test-instrumentation-genai-claude-agent-sdk-latest py310-test-instrumentation-genai-claude-agent-sdk-oldest @@ -167,6 +172,13 @@ deps = anthropic-conformance: {[testenv]pytest_deps} anthropic-conformance: -r {toxinidir}/instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/requirements.latest.txt + bedrock-oldest: {[testenv]pytest_deps} + bedrock-oldest: -e {toxinidir}/instrumentation/opentelemetry-instrumentation-genai-bedrock[instruments] + bedrock-oldest: -r {toxinidir}/instrumentation/opentelemetry-instrumentation-genai-bedrock/tests/requirements.oldest.txt + bedrock-latest: {[testenv]test_deps} + bedrock-latest: {[testenv]pytest_deps} + bedrock-latest: -r {toxinidir}/instrumentation/opentelemetry-instrumentation-genai-bedrock/tests/requirements.latest.txt + claude-agent-sdk-oldest: {[testenv]pytest_deps} claude-agent-sdk-oldest: -e {toxinidir}/instrumentation/opentelemetry-instrumentation-genai-claude-agent-sdk[instruments] claude-agent-sdk-oldest: -r {toxinidir}/instrumentation/opentelemetry-instrumentation-genai-claude-agent-sdk/tests/requirements.oldest.txt @@ -263,6 +275,9 @@ commands = test-instrumentation-genai-anthropic-conformance: pytest {toxinidir}/instrumentation/opentelemetry-instrumentation-genai-anthropic/tests/test_conformance.py --vcr-record=none {posargs} lint-instrumentation-genai-anthropic: sh -c "cd instrumentation && ruff check opentelemetry-instrumentation-genai-anthropic" + test-instrumentation-genai-bedrock-{oldest,latest}: pytest {toxinidir}/instrumentation/opentelemetry-instrumentation-genai-bedrock/tests --vcr-record=none {posargs} + lint-instrumentation-genai-bedrock: sh -c "cd instrumentation && ruff check opentelemetry-instrumentation-genai-bedrock" + test-instrumentation-genai-claude-agent-sdk: pytest {toxinidir}/instrumentation/opentelemetry-instrumentation-genai-claude-agent-sdk/tests --vcr-record=none {posargs} lint-instrumentation-genai-claude-agent-sdk: sh -c "cd instrumentation && ruff check opentelemetry-instrumentation-genai-claude-agent-sdk" test-instrumentation-genai-crewai-{oldest,latest}: pytest {toxinidir}/instrumentation/opentelemetry-instrumentation-genai-crewai/tests --vcr-record=none {posargs} @@ -374,6 +389,7 @@ deps = -e {toxinidir}/instrumentation/opentelemetry-instrumentation-genai-agno[instruments] -e {toxinidir}/instrumentation/opentelemetry-instrumentation-genai-smolagents[instruments] -e {toxinidir}/instrumentation/opentelemetry-instrumentation-genai-anthropic[instruments] + -e {toxinidir}/instrumentation/opentelemetry-instrumentation-genai-bedrock[instruments] -e {toxinidir}/instrumentation/opentelemetry-instrumentation-genai-langchain[instruments] -e {toxinidir}/instrumentation/opentelemetry-instrumentation-genai-llama-index[instruments] -e {toxinidir}/instrumentation/opentelemetry-instrumentation-genai-claude-agent-sdk[instruments] diff --git a/uv.lock b/uv.lock index 95d954521..de69bafa9 100644 --- a/uv.lock +++ b/uv.lock @@ -18,6 +18,7 @@ resolution-markers = [ members = [ "opentelemetry-instrumentation-genai-agno", "opentelemetry-instrumentation-genai-anthropic", + "opentelemetry-instrumentation-genai-bedrock", "opentelemetry-instrumentation-genai-claude-agent-sdk", "opentelemetry-instrumentation-genai-crewai", "opentelemetry-instrumentation-genai-langchain", @@ -452,6 +453,34 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/e4/f8/972c96f5a2b6c4b3deca57009d93e946bbdbe2241dca9806d502f29dd3ee/bcrypt-5.0.0-pp311-pypy311_pp73-manylinux_2_34_x86_64.whl", hash = "sha256:6b8f520b61e8781efee73cba14e3e8c9556ccfb375623f4f97429544734545b4", size = 273375, upload-time = "2025-09-25T19:50:45.43Z" }, ] +[[package]] +name = "boto3" +version = "1.43.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "botocore" }, + { name = "jmespath" }, + { name = "s3transfer" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/b7/65/47670987f2f9e181397872c7ee6415b7b95156d711b7eab6c55f66e575bc/boto3-1.43.0.tar.gz", hash = "sha256:80d44a943ef90aba7958ab31d30c155c198acc8a9581b5846b3878b2c8951086", size = 113143, upload-time = "2026-04-29T22:07:49.084Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/b3/a0/3e6a0b1c1ea6bec76f71473727ef27abf3cd40e9709b3ebcbfbcfaae6f79/boto3-1.43.0-py3-none-any.whl", hash = "sha256:8ebe03754a4b73a5cb6ec2f14cca03ac33bd4760d0adea53da4724845130258b", size = 140497, upload-time = "2026-04-29T22:07:46.216Z" }, +] + +[[package]] +name = "botocore" +version = "1.43.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "jmespath" }, + { name = "python-dateutil" }, + { name = "urllib3" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/28/79/2f4be1896db3db7ccf44504253a175d56b6bd6b669619edc5147d1aa21ea/botocore-1.43.0.tar.gz", hash = "sha256:e933b31a2d644253e1d029d7d39e99ba41b87e29300534f189744cc438cdf928", size = 15286817, upload-time = "2026-04-29T22:07:31.723Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/bf/4b/afc1fef8a43bafb139f57f73bbd70df82807af5934321e8112ae50668827/botocore-1.43.0-py3-none-any.whl", hash = "sha256:cc5b15eaec3c6eac05d8012cb5ef17ebe891beb88a16ca13c374bfaece1241e6", size = 14970102, upload-time = "2026-04-29T22:07:27Z" }, +] + [[package]] name = "build" version = "1.5.0" @@ -3337,6 +3366,31 @@ requires-dist = [ ] provides-extras = ["instruments"] +[[package]] +name = "opentelemetry-instrumentation-genai-bedrock" +source = { editable = "instrumentation/opentelemetry-instrumentation-genai-bedrock" } +dependencies = [ + { name = "opentelemetry-api" }, + { name = "opentelemetry-instrumentation" }, + { name = "opentelemetry-semantic-conventions" }, + { name = "opentelemetry-util-genai" }, +] + +[package.optional-dependencies] +instruments = [ + { name = "boto3" }, +] + +[package.metadata] +requires-dist = [ + { name = "boto3", marker = "extra == 'instruments'", specifier = ">=1.40.46" }, + { name = "opentelemetry-api", specifier = "~=1.43" }, + { name = "opentelemetry-instrumentation", specifier = ">=0.64b0,<1" }, + { name = "opentelemetry-semantic-conventions", specifier = ">=0.64b0,<1" }, + { name = "opentelemetry-util-genai", editable = "util/opentelemetry-util-genai" }, +] +provides-extras = ["instruments"] + [[package]] name = "opentelemetry-instrumentation-genai-claude-agent-sdk" source = { editable = "instrumentation/opentelemetry-instrumentation-genai-claude-agent-sdk" } @@ -3604,6 +3658,7 @@ dependencies = [ { name = "opentelemetry-instrumentation" }, { name = "opentelemetry-instrumentation-genai-agno", extra = ["instruments"] }, { name = "opentelemetry-instrumentation-genai-anthropic", extra = ["instruments"] }, + { name = "opentelemetry-instrumentation-genai-bedrock", extra = ["instruments"] }, { name = "opentelemetry-instrumentation-genai-claude-agent-sdk", extra = ["instruments"] }, { name = "opentelemetry-instrumentation-genai-crewai", extra = ["instruments"] }, { name = "opentelemetry-instrumentation-genai-langchain", extra = ["instruments"] }, @@ -3637,6 +3692,7 @@ requires-dist = [ { name = "opentelemetry-instrumentation" }, { name = "opentelemetry-instrumentation-genai-agno", extras = ["instruments"], editable = "instrumentation/opentelemetry-instrumentation-genai-agno" }, { name = "opentelemetry-instrumentation-genai-anthropic", extras = ["instruments"], editable = "instrumentation/opentelemetry-instrumentation-genai-anthropic" }, + { name = "opentelemetry-instrumentation-genai-bedrock", extras = ["instruments"], editable = "instrumentation/opentelemetry-instrumentation-genai-bedrock" }, { name = "opentelemetry-instrumentation-genai-claude-agent-sdk", extras = ["instruments"], editable = "instrumentation/opentelemetry-instrumentation-genai-claude-agent-sdk" }, { name = "opentelemetry-instrumentation-genai-crewai", extras = ["instruments"], editable = "instrumentation/opentelemetry-instrumentation-genai-crewai" }, { name = "opentelemetry-instrumentation-genai-langchain", extras = ["instruments"], editable = "instrumentation/opentelemetry-instrumentation-genai-langchain" }, @@ -5445,6 +5501,18 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/10/85/48f0abdcef5cce4e034c7a5b0ceeceba0b01bf0d942824f4bb720afe2dec/rpds_py-2026.6.3-pp311-pypy311_pp73-musllinux_1_2_x86_64.whl", hash = "sha256:8e65860d238379ed982fd9ba690579b5e95af2f4840f99c772816dbe573cb826", size = 586486, upload-time = "2026-06-30T07:17:51.141Z" }, ] +[[package]] +name = "s3transfer" +version = "0.17.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "botocore" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/11/b3/bcdc2f58fa92592db511beda154c2c08d28f21f6c4637f06a42a24b10c21/s3transfer-0.17.1.tar.gz", hash = "sha256:042dd5e3b1b512355e35a23f0223e426b7042e80b97830ea2680ddce327fc45e", size = 159439, upload-time = "2026-05-26T19:45:01.714Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/85/dd/904873250a6554fbae40cddbf9198e3cc37a2f1319d5e1a5ce82fe269c17/s3transfer-0.17.1-py3-none-any.whl", hash = "sha256:5b9827d1044159bbb01b86ef8902760ea39281927f5de31de75e1d657177bf4c", size = 88264, upload-time = "2026-05-26T19:45:00.452Z" }, +] + [[package]] name = "setuptools" version = "83.0.0" From 30ae1ca2da6b8887d41227bdb3330d4c9623cc44 Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Wed, 5 Aug 2026 17:47:47 +0000 Subject: [PATCH 2/5] docs(bedrock): use PR 359 for changelog fragment and start version at 1.0b0.dev --- .../.changelog/{360.added => 359.added} | 0 .../src/opentelemetry/instrumentation/genai/bedrock/version.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename instrumentation/opentelemetry-instrumentation-genai-bedrock/.changelog/{360.added => 359.added} (100%) diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/.changelog/360.added b/instrumentation/opentelemetry-instrumentation-genai-bedrock/.changelog/359.added similarity index 100% rename from instrumentation/opentelemetry-instrumentation-genai-bedrock/.changelog/360.added rename to instrumentation/opentelemetry-instrumentation-genai-bedrock/.changelog/359.added diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/src/opentelemetry/instrumentation/genai/bedrock/version.py b/instrumentation/opentelemetry-instrumentation-genai-bedrock/src/opentelemetry/instrumentation/genai/bedrock/version.py index 8920c2929..cefb388ff 100644 --- a/instrumentation/opentelemetry-instrumentation-genai-bedrock/src/opentelemetry/instrumentation/genai/bedrock/version.py +++ b/instrumentation/opentelemetry-instrumentation-genai-bedrock/src/opentelemetry/instrumentation/genai/bedrock/version.py @@ -1,4 +1,4 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 -__version__ = "1.1b0.dev" +__version__ = "1.0b0.dev" From c93ba0e4ca37cb02eaf98af9bd9f15d22c33ea42 Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Wed, 5 Aug 2026 18:19:00 +0000 Subject: [PATCH 3/5] docs(bedrock): add completion hook docs and minimal examples --- .../README.rst | 12 +++++ .../examples/manual/.env | 1 + .../examples/manual/README.rst | 45 ++++++++++++++++ .../examples/manual/main.py | 54 +++++++++++++++++++ .../examples/manual/requirements.txt | 4 ++ .../examples/zero-code/.env | 1 + .../examples/zero-code/README.rst | 47 ++++++++++++++++ .../examples/zero-code/main.py | 25 +++++++++ .../examples/zero-code/requirements.txt | 5 ++ 9 files changed, 194 insertions(+) create mode 100644 instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/.env create mode 100644 instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/README.rst create mode 100644 instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/main.py create mode 100644 instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/requirements.txt create mode 100644 instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/zero-code/.env create mode 100644 instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/zero-code/README.rst create mode 100644 instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/zero-code/main.py create mode 100644 instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/zero-code/requirements.txt diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/README.rst b/instrumentation/opentelemetry-instrumentation-genai-bedrock/README.rst index b2f515bf0..1b627421c 100644 --- a/instrumentation/opentelemetry-instrumentation-genai-bedrock/README.rst +++ b/instrumentation/opentelemetry-instrumentation-genai-bedrock/README.rst @@ -31,3 +31,15 @@ environment variable ``OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT`` to o :: export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=SPAN_AND_EVENT + +Prompts and completions can also be redirected via a completion hook by +setting ``OTEL_INSTRUMENTATION_GENAI_COMPLETION_HOOK`` or by passing +``instrument(completion_hook=...)``. + +References +---------- + +* `OpenTelemetry Project `_ +* `OpenTelemetry GenAI semantic conventions `_ +* `Amazon Bedrock Documentation `_ +* `Boto3 Documentation `_ diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/.env b/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/.env new file mode 100644 index 000000000..73d8c93c7 --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/.env @@ -0,0 +1 @@ +OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/README.rst b/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/README.rst new file mode 100644 index 000000000..79d8d59e9 --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/README.rst @@ -0,0 +1,45 @@ +OpenTelemetry Amazon Bedrock Instrumentation Example +==================================================== + +This is an example of how to instrument Amazon Bedrock calls when configuring OpenTelemetry SDK and Instrumentations manually. + +When `main.py `_ is run, it exports traces and logs to an OTLP +compatible endpoint. + +Note: `.env <.env>`_ file configures additional environment variables: + +- `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true` configures + Amazon Bedrock instrumentation to capture prompt and completion contents on + events. + +Setup +----- + +An OTLP compatible endpoint should be listening for traces and logs on +http://localhost:4317. If not, update "OTEL_EXPORTER_OTLP_ENDPOINT" as well. + +Next, set up a virtual environment like this: + +:: + + python3 -m venv .venv + source .venv/bin/activate + pip install "python-dotenv[cli]" + pip install -r requirements.txt + +You will also need AWS credentials configured (e.g. via environment variables or an AWS profile): + +:: + + export AWS_DEFAULT_REGION=us-east-1 + export AWS_ACCESS_KEY_ID=your_access_key + export AWS_SECRET_ACCESS_KEY=your_secret_key + +Run +--- + +Run the example like this: + +:: + + python main.py diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/main.py b/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/main.py new file mode 100644 index 000000000..1c3b37d91 --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/main.py @@ -0,0 +1,54 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# pylint: skip-file +import json + +import boto3 + +# NOTE: OpenTelemetry Python Logs and Events APIs are in beta +from opentelemetry import _logs, trace +from opentelemetry.exporter.otlp.proto.grpc._log_exporter import ( + OTLPLogExporter, +) +from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import ( + OTLPSpanExporter, +) +from opentelemetry.instrumentation.genai.bedrock import BedrockInstrumentor +from opentelemetry.sdk._logs import LoggerProvider +from opentelemetry.sdk._logs.export import BatchLogRecordProcessor +from opentelemetry.sdk.trace import TracerProvider +from opentelemetry.sdk.trace.export import BatchSpanProcessor + +# configure tracing +trace.set_tracer_provider(TracerProvider()) +trace.get_tracer_provider().add_span_processor( + BatchSpanProcessor(OTLPSpanExporter()) +) + +# configure logging and events +_logs.set_logger_provider(LoggerProvider()) +_logs.get_logger_provider().add_log_record_processor( + BatchLogRecordProcessor(OTLPLogExporter()) +) + +# instrument Amazon Bedrock +BedrockInstrumentor().instrument() + + +def main(): + client = boto3.client("bedrock-runtime", region_name="us-east-1") + response = client.invoke_model( + modelId="amazon.titan-text-lite-v1", + body=json.dumps( + { + "inputText": "Write a short poem on OpenTelemetry.", + } + ), + ) + result = json.loads(response["body"].read()) + print(result) + + +if __name__ == "__main__": + main() diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/requirements.txt b/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/requirements.txt new file mode 100644 index 000000000..1d0b7f380 --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/requirements.txt @@ -0,0 +1,4 @@ +boto3>=1.40.46 +opentelemetry-sdk~=1.43.0 +opentelemetry-instrumentation-genai-bedrock~=1.0b0 +opentelemetry-exporter-otlp-proto-grpc~=1.43.0 diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/zero-code/.env b/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/zero-code/.env new file mode 100644 index 000000000..73d8c93c7 --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/zero-code/.env @@ -0,0 +1 @@ +OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/zero-code/README.rst b/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/zero-code/README.rst new file mode 100644 index 000000000..5765f411f --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/zero-code/README.rst @@ -0,0 +1,47 @@ +OpenTelemetry Amazon Bedrock Zero-Code Instrumentation Example +============================================================== + +This is an example of how to use OpenTelemetry's automatic instrumentation +(zero-code) capabilities with the Amazon Bedrock SDK (boto3). + +The `opentelemetry-instrument` CLI automatically instruments your Python +application without requiring code changes. When `main.py `_ is run +with the CLI, it exports traces and logs to an OTLP compatible endpoint. + +Note: `.env <.env>`_ file configures additional environment variables: + +- `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true` configures + Amazon Bedrock instrumentation to capture prompt and completion contents on + events. + +Setup +----- + +An OTLP compatible endpoint should be listening for traces and logs on +http://localhost:4317. If not, update "OTEL_EXPORTER_OTLP_ENDPOINT" as well. + +Next, set up a virtual environment like this: + +:: + + python3 -m venv .venv + source .venv/bin/activate + pip install "python-dotenv[cli]" + pip install -r requirements.txt + +You will also need AWS credentials configured (e.g. via environment variables or an AWS profile): + +:: + + export AWS_DEFAULT_REGION=us-east-1 + export AWS_ACCESS_KEY_ID=your_access_key + export AWS_SECRET_ACCESS_KEY=your_secret_key + +Run +--- + +Run the example with zero-code instrumentation like this: + +:: + + dotenv run -- opentelemetry-instrument python main.py diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/zero-code/main.py b/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/zero-code/main.py new file mode 100644 index 000000000..0ff36ffd1 --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/zero-code/main.py @@ -0,0 +1,25 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# pylint: skip-file +import json + +import boto3 + + +def main(): + client = boto3.client("bedrock-runtime", region_name="us-east-1") + response = client.invoke_model( + modelId="amazon.titan-text-lite-v1", + body=json.dumps( + { + "inputText": "Write a short poem on OpenTelemetry.", + } + ), + ) + result = json.loads(response["body"].read()) + print(result) + + +if __name__ == "__main__": + main() diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/zero-code/requirements.txt b/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/zero-code/requirements.txt new file mode 100644 index 000000000..96c9fdcb8 --- /dev/null +++ b/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/zero-code/requirements.txt @@ -0,0 +1,5 @@ +boto3>=1.40.46 +opentelemetry-sdk~=1.43.0 +opentelemetry-distro~=0.64b0 +opentelemetry-instrumentation-genai-bedrock~=1.0b0 +opentelemetry-exporter-otlp-proto-grpc~=1.43.0 From 891345586b1f45baae43bf7d8b7c5fd44c581e57 Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Wed, 5 Aug 2026 18:38:20 +0000 Subject: [PATCH 4/5] docs(bedrock): use SPAN_ONLY enum and remove Events API references in examples --- .../opentelemetry-instrumentation-genai-bedrock/README.rst | 2 +- .../examples/manual/.env | 2 +- .../examples/manual/README.rst | 4 ++-- .../examples/manual/main.py | 4 ++-- .../examples/zero-code/.env | 2 +- .../examples/zero-code/README.rst | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/README.rst b/instrumentation/opentelemetry-instrumentation-genai-bedrock/README.rst index 1b627421c..e851fc59a 100644 --- a/instrumentation/opentelemetry-instrumentation-genai-bedrock/README.rst +++ b/instrumentation/opentelemetry-instrumentation-genai-bedrock/README.rst @@ -30,7 +30,7 @@ environment variable ``OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT`` to o :: - export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=SPAN_AND_EVENT + export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=SPAN_ONLY Prompts and completions can also be redirected via a completion hook by setting ``OTEL_INSTRUMENTATION_GENAI_COMPLETION_HOOK`` or by passing diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/.env b/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/.env index 73d8c93c7..71c46f0cd 100644 --- a/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/.env +++ b/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/.env @@ -1 +1 @@ -OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true +OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=SPAN_ONLY diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/README.rst b/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/README.rst index 79d8d59e9..8da4cdde8 100644 --- a/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/README.rst +++ b/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/README.rst @@ -8,9 +8,9 @@ compatible endpoint. Note: `.env <.env>`_ file configures additional environment variables: -- `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true` configures +- `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=SPAN_ONLY` configures Amazon Bedrock instrumentation to capture prompt and completion contents on - events. + span attributes. Setup ----- diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/main.py b/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/main.py index 1c3b37d91..5215d5ba1 100644 --- a/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/main.py +++ b/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/main.py @@ -6,7 +6,7 @@ import boto3 -# NOTE: OpenTelemetry Python Logs and Events APIs are in beta +# NOTE: OpenTelemetry Python Logs API is in beta from opentelemetry import _logs, trace from opentelemetry.exporter.otlp.proto.grpc._log_exporter import ( OTLPLogExporter, @@ -26,7 +26,7 @@ BatchSpanProcessor(OTLPSpanExporter()) ) -# configure logging and events +# configure logging _logs.set_logger_provider(LoggerProvider()) _logs.get_logger_provider().add_log_record_processor( BatchLogRecordProcessor(OTLPLogExporter()) diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/zero-code/.env b/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/zero-code/.env index 73d8c93c7..71c46f0cd 100644 --- a/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/zero-code/.env +++ b/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/zero-code/.env @@ -1 +1 @@ -OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true +OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=SPAN_ONLY diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/zero-code/README.rst b/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/zero-code/README.rst index 5765f411f..995e8b264 100644 --- a/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/zero-code/README.rst +++ b/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/zero-code/README.rst @@ -10,9 +10,9 @@ with the CLI, it exports traces and logs to an OTLP compatible endpoint. Note: `.env <.env>`_ file configures additional environment variables: -- `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true` configures +- `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=SPAN_ONLY` configures Amazon Bedrock instrumentation to capture prompt and completion contents on - events. + span attributes. Setup ----- From 05258316db9d4c46f0e3d363ffbf9a22d33303ea Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Wed, 5 Aug 2026 18:44:55 +0000 Subject: [PATCH 5/5] Remove dumb comment --- .../examples/manual/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/main.py b/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/main.py index 5215d5ba1..2d262545a 100644 --- a/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/main.py +++ b/instrumentation/opentelemetry-instrumentation-genai-bedrock/examples/manual/main.py @@ -6,7 +6,6 @@ import boto3 -# NOTE: OpenTelemetry Python Logs API is in beta from opentelemetry import _logs, trace from opentelemetry.exporter.otlp.proto.grpc._log_exporter import ( OTLPLogExporter,