feature: hydrate AsyncPG span attributes at creation#3841
feature: hydrate AsyncPG span attributes at creation#3841xrmx merged 12 commits intoopen-telemetry:mainfrom
Conversation
4a779d1 to
881bc76
Compare
The sampler now receives DB system/name/user, DB statement (and parameters when capture_parameters is on), and peer host/port/transport because we hydrate attributes before start_as_current_span. Added tests covering execute and cursor paths with non-recording spans to ensure those attributes are present for sampling decisions, and added a changelog entry |
|
Thanks for contributing! Please also have a look at the docker-tests, and do a |
Hi! Thanks for the feedback — I’ve addressed the formatting issues and updated the docker tests as requested. |
tests/opentelemetry-docker-tests/tests/asyncpg/test_asyncpg_functional.py
Outdated
Show resolved
Hide resolved
tests/opentelemetry-docker-tests/tests/asyncpg/test_asyncpg_functional.py
Outdated
Show resolved
Hide resolved
tammy-baylis-swi
left a comment
There was a problem hiding this comment.
Thanks for revisions, lgtm!
…3841) * feature: hydrate AsyncPG span attributes at creation (open-telemetry#3643) * opentelemetry-instrumentation-asyncpg: ensure sampler sees span attributes * tests: fix import order in asyncpg docker tests * tests: expect net.transport in asyncpg sampler attributes * tests: use sdk tracer in asyncpg sampling checks * changelog: move asyncpg fix to Unreleased * Update CHANGELOG.md * Update CHANGELOG.md --------- Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
…3841) * feature: hydrate AsyncPG span attributes at creation (open-telemetry#3643) * opentelemetry-instrumentation-asyncpg: ensure sampler sees span attributes * tests: fix import order in asyncpg docker tests * tests: expect net.transport in asyncpg sampler attributes * tests: use sdk tracer in asyncpg sampling checks * changelog: move asyncpg fix to Unreleased * Update CHANGELOG.md * Update CHANGELOG.md --------- Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
…3841) * feature: hydrate AsyncPG span attributes at creation (open-telemetry#3643) * opentelemetry-instrumentation-asyncpg: ensure sampler sees span attributes * tests: fix import order in asyncpg docker tests * tests: expect net.transport in asyncpg sampler attributes * tests: use sdk tracer in asyncpg sampling checks * changelog: move asyncpg fix to Unreleased * Update CHANGELOG.md * Update CHANGELOG.md --------- Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
Description
This change enables filtering of AsyncPG spans by moving attribute hydration from inside the span context to before span creation. Previously, spans were created with no attributes and attributes were added after span creation using
span.set_attribute(), which prevented samplers from filtering based on request attributes.The fix moves the
_hydrate_span_from_args()call outside the span context and passes the hydrated attributes directly tostart_as_current_span()using theattributesparameter. This ensures that database attributes (system, name, user, statement, network info) are available during span creation for sampling decisions.Fixes #3643
Type of change
How Has This Been Tested?
The changes were tested by:
attributesparameter is properly passed tostart_as_current_span()in both_do_executeand_do_cursor_executemethodsThe implementation maintains backward compatibility and does not change the external API.
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.