open-telemetry / open-telemetry/opentelemetry-python-contrib
`opentelemetry-instrumentation-asyncpg`: allow opting out of instrumentation for async cursors
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?
Currently, the AsyncPGInstrumentor instruments these async methods, including CursorIterator.__anext__.
In conjunction with this, it means that a span is fired for every single row that is iterated over from an async cursor. This causes certain traces to become unsustainably large and contain a massive number of spans like the one below:
Describe the solution you'd like
Allow opting out of instrumentation for CursorIterator.__anext__, or implement instrumentation at the network request level so that every fetch to the database triggers a span rather than every single row that is iterated over.
Describe alternatives you've considered
No response
Additional Context
No response
Would you like to implement a fix?
None
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 in instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/init.py, reviewing the instrumented async methods around lines 129–137 and the logic around line 186. Trace how CursorIterator.anext creates spans and inspect nearby tests if available. Done means the issue’s chosen approach prevents an unsustainable span for every iterated row while preserving the intended asyncpg instrumentation behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- databases, observability
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100