Skip to content

Add initial opentelemetry-instrumentation-genai-bedrock boilerplate - #359

Open
DylanRussell wants to merge 13 commits into
open-telemetry:mainfrom
DylanRussell:add_bedrock_instrumentation
Open

Add initial opentelemetry-instrumentation-genai-bedrock boilerplate#359
DylanRussell wants to merge 13 commits into
open-telemetry:mainfrom
DylanRussell:add_bedrock_instrumentation

Conversation

@DylanRussell

Copy link
Copy Markdown
Contributor

Description

Add initial opentelemetry-instrumentation-genai-bedrock boilerplate. boto3 doesn't have any reference to open telemetry in it's repo, so no native instrumentation.

Created the package structure targeting "boto3 >= 1.40.46" (matching openinference-instrumentation-bedrock),

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How has this been tested?

Unit tests

Checklist

  • Followed the style guidelines of this project
  • Changelog updated if the change requires an entry
  • Unit tests added
  • Documentation updated

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Aug 5, 2026

Copy link
Copy Markdown

Pull request dashboard status

Waiting on the author · refreshed 2026-08-21 01:40 UTC

Resolve merge conflicts.

Investigate required status check failures.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Should this be with reviewers? Comment /dashboard route:reviewers to route it to them.
  • Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new opentelemetry-instrumentation-genai-bedrock package scaffold to the monorepo, wiring it into the workspace and test matrix so future Bedrock (boto3) patching can be implemented incrementally.

Changes:

  • Introduces the new Bedrock instrumentation package structure (packaging, versioning, README, license, changelog fragment).
  • Adds basic lifecycle tests and tox env wiring for oldest/latest factors.
  • Registers the package in the workspace (pyproject.toml / uv.lock) and docs dependency set.

Reviewed changes

Copilot reviewed 17 out of 18 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
uv.lock Adds the new package as a workspace member and records boto3/botocore/s3transfer resolution entries.
tox.ini Adds bedrock test+lint envs and dependency wiring for oldest/latest.
pyproject.toml Registers the new package in workspace deps and pyright include/exclude lists.
instrumentation/README.md Lists the new bedrock instrumentation package and its minimum boto3 version.
docs-requirements.txt Adds boto3>=1.40.46 to doc build requirements.
instrumentation/opentelemetry-instrumentation-genai-bedrock/pyproject.toml New package metadata, dependencies, extras, and entry point registration.
instrumentation/opentelemetry-instrumentation-genai-bedrock/README.rst New package README describing installation/usage/configuration.
instrumentation/opentelemetry-instrumentation-genai-bedrock/LICENSE Adds Apache-2.0 license file for the new package.
instrumentation/opentelemetry-instrumentation-genai-bedrock/.changelog/360.added Towncrier fragment announcing initial package setup.
instrumentation/opentelemetry-instrumentation-genai-bedrock/.changelog/.gitignore Keeps the changelog directory tracked.
instrumentation/opentelemetry-instrumentation-genai-bedrock/src/opentelemetry/instrumentation/genai/bedrock/init.py Adds BedrockInstrumentor boilerplate and completion hook wiring.
instrumentation/opentelemetry-instrumentation-genai-bedrock/src/opentelemetry/instrumentation/genai/bedrock/package.py Declares _instruments dependency tuple for instrumentation_dependencies().
instrumentation/opentelemetry-instrumentation-genai-bedrock/src/opentelemetry/instrumentation/genai/bedrock/version.py Sets the package version.
instrumentation/opentelemetry-instrumentation-genai-bedrock/tests/init.py Initializes the test package.
instrumentation/opentelemetry-instrumentation-genai-bedrock/tests/conftest.py Registers shared GenAI test fixtures and provides an instrumentation fixture.
instrumentation/opentelemetry-instrumentation-genai-bedrock/tests/test_instrumentor.py Adds basic lifecycle tests for instrument/uninstrument.
instrumentation/opentelemetry-instrumentation-genai-bedrock/tests/requirements.oldest.txt Documents that oldest relies on lowest-direct resolution without extra pins.
instrumentation/opentelemetry-instrumentation-genai-bedrock/tests/requirements.latest.txt Installs latest boto3 plus editable util + instrumentation for latest-factor tests.

Comment thread instrumentation/opentelemetry-instrumentation-genai-bedrock/README.rst Outdated
@eternalcuriouslearner

Copy link
Copy Markdown
Contributor

@lmolkova Should we migrate bedrock? I was under the assumption that it is going to be left in contrib.

@DylanRussell

Copy link
Copy Markdown
Contributor Author

i dont think boto3 is instrumented in contrib.. well I see boto3 sqs is instrumented: https://github.com/open-telemetry/opentelemetry-python-contrib/blob/e5e3af0ccdb9c3d85728f6d7cb03d77c72196425/instrumentation/opentelemetry-instrumentation-boto3sqs/README.rst but that isn't the API we care about

…entation

# Conflicts:
#	docs-requirements.txt
#	instrumentation/README.md
@opentelemetry-pr-dashboard

This comment has been minimized.

@xrmx

xrmx commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

i dont think boto3 is instrumented in contrib.. well I see boto3 sqs is instrumented: https://github.com/open-telemetry/opentelemetry-python-contrib/blob/e5e3af0ccdb9c3d85728f6d7cb03d77c72196425/instrumentation/opentelemetry-instrumentation-boto3sqs/README.rst but that isn't the API we care about

The one in contrib instruments botocore that is what powers boto3. So the layer would be different but you'll still get duplicated telemetry.

The current instrumentation in -contrib instruments two classes of APIs: the old InvokeModel and the newer Converse. Both of these have a sync and stream version of the API. Does the openinference one supports both? Yes

@DylanRussell

DylanRussell commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

Hmm ok I missed that, so there's a gen ai instrumentation of the botocore library (which underlies boto3) in contrib..

It seems not great to have just 1 gen ai instrumentation in contrib and the rest in this repo going forward.. I also think it has some gaps: it doesn't use gen ai utils (is missing stuff like the completion hook and the content capture flag), and doesn't instrument aiobotocore for the gen AI stuff..

So my proposal is we deprecate that one and add one atop of boto3 here in this library.. WDYT ?

Also I think it's mostly fine that we instrument boto3 here and in the contrib repo, since the one contrib monkey patches just the SQS methods: https://github.com/open-telemetry/opentelemetry-python-contrib/blob/b4e7e098f81c3713798a5747c76e87f8c03b1e7e/instrumentation/opentelemetry-instrumentation-boto3sqs/src/opentelemetry/instrumentation/boto3sqs/__init__.py#L338-L342 -- we will instrument a different set of methods in this repo, so there's no conflict..

I think we also need to be careful of the entry point name we use for auto instrumentation boto3 has been taken --- https://github.com/open-telemetry/opentelemetry-python-contrib/blob/b4e7e098f81c3713798a5747c76e87f8c03b1e7e/instrumentation/opentelemetry-instrumentation-boto3sqs/pyproject.toml#L40 -- so we have to use something different there.. I have "bedrock" here now but we can use something else..

Proposal for how to deprecate the existing bedrock instrumentation:

Add a deprecation warning:

class _BedrockExtension:
    def __init__(self, ...):
        warnings.warn(
            "The Bedrock extension in 'opentelemetry-instrumentation-botocore' is deprecated "
            "and will be removed in a future release. "
            "Please use 'opentelemetry-instrumentation-genai-bedrock' instead.",
            category=DeprecationWarning,
            stacklevel=2,
        )

Disable BedrockExtension if opentelemetry-instrumentation-genai-bedrock is installed and enabled:

def _is_genai_bedrock_active() -> bool:
    if importlib.util.find_spec("opentelemetry.instrumentation.genai.bedrock") is None:
        return False
    try:
        from opentelemetry.instrumentation.genai.bedrock import BedrockInstrumentor
        return BedrockInstrumentor().is_instrumented_by_opentelemetry
    except Exception:
        return False
class _BedrockExtension:
    def __init__(self, ...):
        self._disabled = _is_genai_bedrock_active()
        if self._disabled:
            logger.debug(
                "opentelemetry-instrumentation-genai-bedrock is active; "
                "suppressing botocore BedrockExtension to avoid duplicate spans."
            )
    def extract_attributes(self, ...):
        if self._disabled:
            return  # No-op: let the new instrumentor handle GenAI telemetry
        ...

@xrmx

xrmx commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Hmm ok I missed that, so there's a gen ai instrumentation of the botocore library (which underlies boto3) in contrib..

It seems not great to have just 1 gen ai instrumentation in contrib and the rest in this repo going forward.. I also think it has some gaps: it doesn't use gen ai utils (is missing stuff like the completion hook and the content capture flag), and doesn't instrument aiobotocore for the gen AI stuff..

So my proposal is we deprecate that one and add one atop of boto3 here in this library.. WDYT ?

Proposal for how to deprecate the existing bedrock instrumentation:

Add a deprecation warning:
...

Disable BedrockExtension if opentelemetry-instrumentation-genai-bedrock is installed and enabled:
...

Sounds good to me but the question is when we deprecate that? I would like to do so only once this has feature parity. And also when opentelemetry-bootstrap will start offering python-genai instrumentations. Have you already discussed when to substitute the -contrib ones there?

@DylanRussell

Copy link
Copy Markdown
Contributor Author

Yeah definitely don't deprecate until feature parity + release.

I think https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4927/changes will fix that issue with opentelemetry-bootstrap

@DylanRussell
DylanRussell requested a review from lmolkova August 19, 2026 15:43
Installing shellcheck via apt in tox.ini commands_pre can fail or hang in CI when system package mirrors time out. Replace the apt installation with shellcheck-py in tox deps, and exclude virtual environment directories from the shellcheck find command.

Assisted-by: Antigravity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants