open-telemetry / open-telemetry/opentelemetry-python-contrib

asyncpg: ability to silence connection cleanup when using a pool

Open
#4,264 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature-request
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.