Skip to content

Support passing tracer provider in aiohttp server instrumentation lib#3819

Merged
xrmx merged 32 commits intoopen-telemetry:mainfrom
bisgaard-itis:3801-support-passing-TracerProvider-in-aiohttp-server-instrumentation-lib
Dec 22, 2025
Merged

Support passing tracer provider in aiohttp server instrumentation lib#3819
xrmx merged 32 commits intoopen-telemetry:mainfrom
bisgaard-itis:3801-support-passing-TracerProvider-in-aiohttp-server-instrumentation-lib

Conversation

@bisgaard-itis
Copy link
Contributor

@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 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
Contributor 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
Contributor 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>
@tammy-baylis-swi
Copy link
Contributor

Great, thanks a lot @tammy-baylis-swi. Do you know if I need to do anything to get a maintainer to review it?

Nothing needed since it's on the triage project board 👍 It just takes time since we're always in need of more contributors and approvers! If you do want to bring this PR up more synchronously, you can check out #otel-python on the CNCF Slack or attend the Thursday meetings (all linked here).

@xrmx xrmx moved this from Ready for review to Approved PRs that need fixes in Python PR digest Nov 28, 2025
…acerProvider-in-aiohttp-server-instrumentation-lib
@bisgaard-itis bisgaard-itis force-pushed the 3801-support-passing-TracerProvider-in-aiohttp-server-instrumentation-lib branch from a934b0c to ca8ece2 Compare December 2, 2025 10:56
@bisgaard-itis bisgaard-itis requested a review from xrmx December 2, 2025 11:01
@bisgaard-itis bisgaard-itis force-pushed the 3801-support-passing-TracerProvider-in-aiohttp-server-instrumentation-lib branch from b438f24 to dd31778 Compare December 15, 2025 08:36
@bisgaard-itis bisgaard-itis force-pushed the 3801-support-passing-TracerProvider-in-aiohttp-server-instrumentation-lib branch from 83fe32f to e39dd4d Compare December 19, 2025 07:04
@xrmx xrmx merged commit 77373f8 into open-telemetry:main Dec 22, 2025
663 checks passed
@github-project-automation github-project-automation bot moved this from Approved PRs that need fixes to Done in Python PR digest Dec 22, 2025
herin049 pushed a commit to herin049/opentelemetry-python-contrib that referenced this pull request Dec 22, 2025
…open-telemetry#3819)

* allow to pass tracer_provider when instrumenting aiohttp server

* minor fix

* add note to indicate backwards compatibility

* small fix

* add test

* update changelog

* Only decode JSON input buffer in Anthropic Claude streaming  (open-telemetry#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

* aiohttp-client: add support for url exclusions (open-telemetry#3850)

* 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>

* update changelog

* @tammy-baylis-swi add link to PR

* create factory for instrumented application

* run precommit hooks

* update readthedocs

* cleanup changelog after merge conflicts

* make pre-commit happy

* @tammy-baylis-swi add comment about optional inputs

* fix issues caused by merge

* precommit hooks

* fix typehints

* sort imports

* @xrmx removed assert

* Apply suggestions from code review

---------

Co-authored-by: Thomas Pierce <thp@amazon.com>
Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
Co-authored-by: Tammy Baylis <96076570+tammy-baylis-swi@users.noreply.github.com>
@bisgaard-itis bisgaard-itis deleted the 3801-support-passing-TracerProvider-in-aiohttp-server-instrumentation-lib branch January 5, 2026 08:27
RKest pushed a commit to RKest/opentelemetry-python-contrib that referenced this pull request Jan 12, 2026
…open-telemetry#3819)

* allow to pass tracer_provider when instrumenting aiohttp server

* minor fix

* add note to indicate backwards compatibility

* small fix

* add test

* update changelog

* Only decode JSON input buffer in Anthropic Claude streaming  (open-telemetry#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

* aiohttp-client: add support for url exclusions (open-telemetry#3850)

* 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>

* update changelog

* @tammy-baylis-swi add link to PR

* create factory for instrumented application

* run precommit hooks

* update readthedocs

* cleanup changelog after merge conflicts

* make pre-commit happy

* @tammy-baylis-swi add comment about optional inputs

* fix issues caused by merge

* precommit hooks

* fix typehints

* sort imports

* @xrmx removed assert

* Apply suggestions from code review

---------

Co-authored-by: Thomas Pierce <thp@amazon.com>
Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
Co-authored-by: Tammy Baylis <96076570+tammy-baylis-swi@users.noreply.github.com>
sightseeker added a commit to sightseeker/opentelemetry-python-contrib that referenced this pull request Mar 11, 2026
…open-telemetry#3819)

* allow to pass tracer_provider when instrumenting aiohttp server

* minor fix

* add note to indicate backwards compatibility

* small fix

* add test

* update changelog

* Only decode JSON input buffer in Anthropic Claude streaming  (open-telemetry#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

* aiohttp-client: add support for url exclusions (open-telemetry#3850)

* 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>

* update changelog

* @tammy-baylis-swi add link to PR

* create factory for instrumented application

* run precommit hooks

* update readthedocs

* cleanup changelog after merge conflicts

* make pre-commit happy

* @tammy-baylis-swi add comment about optional inputs

* fix issues caused by merge

* precommit hooks

* fix typehints

* sort imports

* @xrmx removed assert

* Apply suggestions from code review

---------

Co-authored-by: Thomas Pierce <thp@amazon.com>
Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
Co-authored-by: Tammy Baylis <96076570+tammy-baylis-swi@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Allow passing a TracerProvider when instrumenting an aiohttp server

10 participants