Skip to content

feat(asyncpg): add capture_connection_cleanup option to silence pool cleanup spans#4373

Open
RiyaChaturvedi37 wants to merge 18 commits into
open-telemetry:mainfrom
RiyaChaturvedi37:fix/asyncpg-silence-cleanup
Open

feat(asyncpg): add capture_connection_cleanup option to silence pool cleanup spans#4373
RiyaChaturvedi37 wants to merge 18 commits into
open-telemetry:mainfrom
RiyaChaturvedi37:fix/asyncpg-silence-cleanup

Conversation

@RiyaChaturvedi37
Copy link
Copy Markdown
Contributor

@RiyaChaturvedi37 RiyaChaturvedi37 commented Mar 28, 2026

Closes #4264

Description

Adds a new exclude_queries option to AsyncPGInstrumentor to allow
silencing specific queries from being traced.

When using a connection pool, asyncpg executes cleanup statements after
each invocation:

  • SELECT pg_advisory_unlock_all()
  • CLOSE ALL
  • UNLISTEN *
  • RESET ALL

These can pollute traces. Users can now exclude them:

AsyncPGInstrumentor(exclude_queries=AsyncPGInstrumentor._CLEANUP_QUERIES).instrument()

The option accepts any set of queries, making it flexible for other use cases too.

Type of change

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

@RiyaChaturvedi37 RiyaChaturvedi37 force-pushed the fix/asyncpg-silence-cleanup branch from 5547d9b to 73f9258 Compare March 28, 2026 08:49
@tammy-baylis-swi tammy-baylis-swi moved this to Ready for review in Python PR digest Mar 30, 2026
Comment thread CHANGELOG.md
@tammy-baylis-swi tammy-baylis-swi moved this from Ready for review to Reviewed PRs that need fixes in Python PR digest Mar 30, 2026
@tammy-baylis-swi tammy-baylis-swi requested a review from a team March 30, 2026 18:11
@tammy-baylis-swi
Copy link
Copy Markdown
Contributor

Thank you for this @RiyaChaturvedi37 ! I have added some comments

@RiyaChaturvedi37
Copy link
Copy Markdown
Contributor Author

Note: The large diff (+2440/-2389) is due to Windows line ending (CRLF) differences in the existing file on my local machine. The actual code changes are minimal — only 3 files with the new feature, tests, and changelog entry. I apologize for the noise!

Copy link
Copy Markdown
Contributor

@tammy-baylis-swi tammy-baylis-swi left a comment

Choose a reason for hiding this comment

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

Thank you for fixes, lgtm! Just suggested a small docs update. The Maintainers will also have to review this.

@tammy-baylis-swi tammy-baylis-swi moved this from Reviewed PRs that need fixes to Ready for review in Python PR digest Mar 31, 2026
@tammy-baylis-swi tammy-baylis-swi requested a review from a team March 31, 2026 16:39
@tammy-baylis-swi tammy-baylis-swi moved this from Ready for review to Approved PRs in Python PR digest Mar 31, 2026
@RiyaChaturvedi37
Copy link
Copy Markdown
Contributor Author

Thank you for fixes, lgtm! Just suggested a small docs update. The Maintainers will also have to review this.

Done! Added the clarifying comment as suggested.

@github-actions
Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment.
If you're still working on this, please add a comment or push new commits.

@github-actions github-actions Bot added the Stale label Apr 25, 2026
@RiyaChaturvedi37
Copy link
Copy Markdown
Contributor Author

Still actively working on this! Will resolve the CHANGELOG conflict shortly.

@RiyaChaturvedi37
Copy link
Copy Markdown
Contributor Author

Still actively working on this! Just resolved the CHANGELOG conflict and all checks are passing.

Also updated the implementation based on @xrmx's feedback — replaced capture_connection_cleanup with the more flexible exclude_queries parameter:

AsyncPGInstrumentor(exclude_queries=AsyncPGInstrumentor._CLEANUP_QUERIES).instrument()

This allows users to exclude any custom set of queries, not just the cleanup ones.

@github-actions github-actions Bot removed the Stale label Apr 26, 2026
@RiyaChaturvedi37 RiyaChaturvedi37 requested a review from xrmx May 9, 2026 01:43
@emdneto
Copy link
Copy Markdown
Member

emdneto commented May 12, 2026

Thanks for the PR!

Just a heads-up: we no longer update CHANGELOG.md directly. The changelog is now generated from changelog fragments using Towncrier.

Please add the appropriate changelog fragment for this change instead of editing CHANGELOG.md manually. You can find the instructions and expected format in CONTRIBUTING.md.

@aabmass aabmass moved this from Approved PRs to Reviewed PRs that need fixes in Python PR digest May 20, 2026
@github-actions
Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment.
If you're still working on this, please add a comment or push new commits.

@github-actions github-actions Bot added the Stale label May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Reviewed PRs that need fixes

Development

Successfully merging this pull request may close these issues.

asyncpg: ability to silence connection cleanup when using a pool

5 participants