feat(bedrock): Migrate AWS Bedrock Runtime instrumentation#93
Conversation
Scaffold the opentelemetry-instrumentation-genai-bedrock package to instrument the botocore Bedrock Runtime Converse and ConverseStream APIs using the TelemetryHandler/InferenceInvocation lifecycle from opentelemetry-util-genai. The patch wraps botocore.client.BaseClient._make_api_call, filtering for bedrock-runtime service calls to Converse/ConverseStream operations. Assisted-by: Claude Opus 4.6
Register the bedrock package in the root pyproject.toml workspace, add tox test environments, and include basic tests validating span attributes, error recording, and content capture via botocore Stubber. Assisted-by: Claude Opus 4.6
- Add boto3 to test requirements (tests use boto3.client directly) - Apply ruff format to wrappers.py and test_converse.py - Regenerate instrumentation/README.md via tox -e generate - Add changelog fragment for PR open-telemetry#93 - Update uv.lock to include bedrock package Assisted-by: Claude Opus 4.6
|
Pushed fixes for CI failures:
The changelog job will still show a warning because this PR creates a new |
The changelog workflow rejects PRs that include any **/CHANGELOG.md in the diff. The .changelog/93.added fragment satisfies the requirement for a changelog entry. CHANGELOG.md will be generated by towncrier on first release.
Use GenAiSystemValues.AWS_BEDROCK enum instead of string literal "aws.bedrock" per project semconv rules. Remove unused logging import and _logger definition from patch.py. Assisted-by: Claude Opus 4.6
Add attribution to the source modules crediting Riccardo Magliocchetti (@xrmx) as the original author of the Bedrock extension in opentelemetry-python-contrib, with links to the upstream PRs. Assisted-by: Claude Opus 4.6
|
This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment. |
|
AFAIR when we discussed this in the Python SIG it was decided to keep the bedrock runtime instrumentation in the botocore instrumentation so I am surprised by this PR. I'm not opposing to such a migration though but I would like to avoid breaking users. |
Summary
opentelemetry-instrumentation-genai-bedrockas a new package in this monorepoTelemetryHandler/InferenceInvocationlifecycle fromopentelemetry-util-genaibotocore.client.BaseClient._make_api_calldirectly (no dependency onopentelemetry-instrumentation-botocore)Provenance
This is extracted from the existing Bedrock instrumentation in
opentelemetry-python-contrib, originally authored by @riccardo-magliocchetti:Source modules:
extensions/bedrock.pyextensions/bedrock_utils.pytests/test_botocore_bedrock.pyUpstream PRs:
The code has been rewritten to use the shared GenAI utilities (
TelemetryHandler,InferenceInvocation, semconv enums) in this repo rather than the botocore extension pattern.What's included
pyproject.toml, entry points, and changelog supportConverse) instrumentation with full attribute extractionConverseStream) instrumentation with event accumulationWhat's NOT included yet (follow-up work)
InvokeModel/InvokeModelWithResponseStreamsupport (model-specific formats)Context
Per discussion in the GenAI SIG, Bedrock GenAI instrumentation should live in this repo rather than the general-purpose botocore instrumentation in
opentelemetry-python-contrib. This PR is a proposal/draft to get early feedback on the approach before we coordinate deprecation of the Bedrock-specific code in the botocore extension.Test plan
pytestpasses for all 6 tests (instrumentor lifecycle + Converse span attributes, error handling, content capture)rufflint passes