Skip to content

Conversation

@bisgaard-itis
Copy link

@bisgaard-itis bisgaard-itis commented Oct 8, 2025

Description

Support passing a TracerProvider when using the aiohttp server instrumentation library. This gives users of the library the possibility to provide their own TracerProvider instead of relying on the global one. This is in particular useful for testing.

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • I added the test test_non_global_tracer_provider which checks that a non-global TracerProvider can be provided when instrumenting the aiohttp server. I check that the non-global TracerProvider is used by the instrumentation library by setting a non-default sampling probability in that provider and checking that the corresponding number of traces are collected.

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 8, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@bisgaard-itis bisgaard-itis changed the title 3801 support passing tracer provider in aiohttp server instrumentation lib Support passing tracer provider in aiohttp server instrumentation lib Oct 8, 2025
@xrmx xrmx moved this to Reviewed PRs that need fixes in @xrmx's Python PR digest Oct 10, 2025
@xrmx
Copy link
Contributor

xrmx commented Oct 10, 2025

@bisgaard-itis You need to sign the CLA in order to contribute to OpenTelemetry, thanks.

@bisgaard-itis
Copy link
Author

@bisgaard-itis You need to sign the CLA in order to contribute to OpenTelemetry, thanks.

Perfect, thanks a lot for pointing this out @xrmx. I have signed it.

@bisgaard-itis bisgaard-itis requested a review from a team as a code owner October 26, 2025 21:34
@bisgaard-itis
Copy link
Author

@krnr this PR has been hanging for some time. Can I convince you to to review it? 🙏🏻

@krnr
Copy link
Contributor

krnr commented Oct 27, 2025

@krnr this PR has been hanging for some time. Can I convince you to to review it? 🙏🏻

i see no issues, the code is pretty much straight-forward - the same middleware logic, but the middleware itself is created on-the-fly. i like it 👍

@tammy-baylis-swi
Copy link
Contributor

Also:

  1. precommit is failing; please run tox -e ruff on your local and commit changes.
  2. Some aiohttp-server tests are failing, please take a look.

bisgaard-itis and others added 11 commits November 3, 2025 09:39
…lemetry#3875)

* Only decode JSON input buffer in Anthropic Claude streaming

_decode_tool_use was only used when _tool_json_input_buf was found, but we were decoding the entire _content_block after adding _tool_json_input_buf to it. The _content_block overall which could contain non-JSON elements (e.g. {}), causing failures. To fix this, we have removed _decode_tool_use helper function and inlined JSON decoding logic directly into content_block_stop handler in _process_anthropic_claude_chunk, where we only use it to decode _tool_json_input_buf before appending to _content_block.

* Update test_botocore_bedrock.py

Fix lint: `opentelemetry-instrumentation-botocore/tests/test_botocore_bedrock.py:2990:4: C0415: Import outside toplevel (opentelemetry.instrumentation.botocore.extensions.bedrock_utils.InvokeModelWithResponseStreamWrapper) (import-outside-toplevel)`

* Update test_botocore_bedrock.py

Remove extra line

* fix lint issue
* Stop using deprecated span.instrumentation_info

* aiohttp-client: add support for OTEL_PYTHON_EXCLUDED_URLS / OTEL_PYTHON_HTTPX_EXCLUDED_URLS

* Add docs

* Add changelog

* Please lint

* Update CHANGELOG.md

Co-authored-by: Tammy Baylis <96076570+tammy-baylis-swi@users.noreply.github.com>

* Test for both env vars

* Assert at each iteration

---------

Co-authored-by: Tammy Baylis <96076570+tammy-baylis-swi@users.noreply.github.com>
@bisgaard-itis bisgaard-itis force-pushed the 3801-support-passing-TracerProvider-in-aiohttp-server-instrumentation-lib branch from a5bada0 to 4a57b3e Compare November 3, 2025 08:42
@bisgaard-itis
Copy link
Author

Thanks a lot for the review @tammy-baylis-swi 🙏🏻. I have done the changes you requested.

from opentelemetry.sdk.trace.sampling import ParentBased, TraceIdRatioBased
AioHttpServerInstrumentor().instrument()
resource = Resource(attributes={"service.name": "my-aiohttp-service"})
Copy link
Contributor

Choose a reason for hiding this comment

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

Great! I would also add a comment so newer/quickstart users know that these are optional:

Suggested change
resource = Resource(attributes={"service.name": "my-aiohttp-service"})
# Optional: configure non-default TracerProvider, resource, sampler
resource = Resource(attributes={"service.name": "my-aiohttp-service"})

@tammy-baylis-swi
Copy link
Contributor

For the current pypy test failure in CI/CD, a couple of the definitions like tracer_provider: trace.TracerProvider | None = None, will need to change to tracer_provider: Optional[trace.TracerProvider] = None,

The GenAI test fail is unrelated to the changes in this PR and will be patched by the maintainers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Reviewed PRs that need fixes

Development

Successfully merging this pull request may close these issues.

Allow passing a TracerProvider when instrumenting an aiohttp server

10 participants