Skip to content

feat(bedrock): Migrate AWS Bedrock Runtime instrumentation#93

Draft
williazz wants to merge 6 commits into
open-telemetry:mainfrom
williazz:fix/bedrock-instrumentation-scaffold
Draft

feat(bedrock): Migrate AWS Bedrock Runtime instrumentation#93
williazz wants to merge 6 commits into
open-telemetry:mainfrom
williazz:fix/bedrock-instrumentation-scaffold

Conversation

@williazz
Copy link
Copy Markdown

@williazz williazz commented May 26, 2026

Summary

  • Adds opentelemetry-instrumentation-genai-bedrock as a new package in this monorepo
  • Instruments the Bedrock Runtime Converse and ConverseStream APIs using the modern TelemetryHandler/InferenceInvocation lifecycle from opentelemetry-util-genai
  • Patches botocore.client.BaseClient._make_api_call directly (no dependency on opentelemetry-instrumentation-botocore)

Provenance

This is extracted from the existing Bedrock instrumentation in opentelemetry-python-contrib, originally authored by @riccardo-magliocchetti:

Source modules:

Upstream PRs:

  • #3161 — Basic instrumentation for Bedrock runtime Converse API
  • #3258 — Add Bedrock GenAI user events and lazy initialize tracers

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

  • Package scaffold with pyproject.toml, entry points, and changelog support
  • Non-streaming (Converse) instrumentation with full attribute extraction
  • Streaming (ConverseStream) instrumentation with event accumulation
  • Request/response attribute extraction (model, tokens, finish reasons, server address)
  • Input/output message capture (text and tool use)
  • Basic tests using botocore Stubber
  • tox environment and workspace integration

What's NOT included yet (follow-up work)

  • VCR cassette-based integration tests with real recordings
  • Conformance tests (Weaver live-check scenarios)
  • InvokeModel / InvokeModelWithResponseStream support (model-specific formats)
  • Pyright type checking integration

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

  • pytest passes for all 6 tests (instrumentor lifecycle + Converse span attributes, error handling, content capture)
  • ruff lint passes
  • CI pipeline (pending merge queue)

williazz added 3 commits May 26, 2026 17:21
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
@williazz
Copy link
Copy Markdown
Author

Pushed fixes for CI failures:

  • tests: Added boto3 to test requirements (tests use boto3.client() with the Stubber)
  • misc/precommit: Applied ruff format, updated uv.lock
  • misc/generate: Regenerated instrumentation/README.md
  • changelog: Added .changelog/93.added fragment

The changelog job will still show a warning because this PR creates a new CHANGELOG.md file (required for towncrier in a new package). This is expected for the initial package creation PR — could use the "Skip Changelog" label to bypass, or I can remove the empty CHANGELOG.md and add it separately.

williazz added 2 commits May 26, 2026 17:57
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
@williazz
Copy link
Copy Markdown
Author

cc: @xrmx @lmolkova

put this together to help with bedrock migration. gating it as draft release right now because while we figure out if there's any decisions we need to make

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
@williazz williazz changed the title feat(bedrock): Add standalone AWS Bedrock Runtime instrumentation package feat(bedrock): Migrate AWS Bedrock Runtime instrumentation May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant