open-telemetry / open-telemetry/opentelemetry-python-contrib
asyncpg: ability to silence connection cleanup when using a pool
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 1.1k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 16
Description
What problem do you want to solve?
So whenever a pool is being used, uppon completion, asyncpg executes following statement:
SELECT pg_advisory_unlock_all();\nCLOSE ALL;\nUNLISTEN *;\nRESET ALL;
to cleanup the connection's state so it can be used for another request. I'm wondering if there's a way to exclude those from being instrumented as they can pollute traces (especially if there's a task that periodically queries the database).
Describe the solution you'd like
Perhaps additional option next to capture_parameters in the constructor? For example:
AsyncPGInstrumentor(capture_parameters=True,capture_connection_cleanup=False).instrument()
capture_connection_cleanup could default to True
Describe alternatives you've considered
I was trying to add custom sampler and reading db.statement from attributes, but at that moment the attributes are not available yet.
Additional Context
No response
Would you like to implement a fix?
None
Tip
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the AsyncPGInstrumentor constructor and its existing capture_parameters option, then locate the asyncpg instrumentation tests and the code that records connection cleanup statements. Add coverage for disabling cleanup capture while preserving the default behavior; done means the cleanup SQL no longer pollutes traces when the option is disabled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, python
- Domain
- databases, observability
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100