Skip to content

Conversation

forafox
Copy link

@forafox forafox commented Oct 13, 2025

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 to start_as_current_span() using the attributes parameter. This ensures that database attributes (system, name, user, statement, network info) are available during span creation for sampling decisions.

Fixes #3643

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?

The changes were tested by:

  • Running existing AsyncPG instrumentation tests to ensure no regressions
  • Verifying that attributes are now available during span creation by examining the modified code structure
  • Confirming that the attributes parameter is properly passed to start_as_current_span() in both _do_execute and _do_cursor_execute methods

The implementation maintains backward compatibility and does not change the external API.

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

Copy link

linux-foundation-easycla bot commented Oct 13, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: forafox / name: Andrey Karabanov (881bc76)

@forafox forafox force-pushed the feature/asyncpg-attribute-hydration branch from 4a779d1 to 881bc76 Compare October 14, 2025 15:58
@xrmx xrmx moved this to Ready for review in @xrmx's Python PR digest Oct 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready for review

Development

Successfully merging this pull request may close these issues.

Support filtering AsyncPG spans

1 participant