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

`opentelemetry-instrumentation-asyncpg`: allow opting out of instrumentation for async cursors

Open
#3,109 1 comment 1 reaction 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?

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:

Screenshot 2024-12-13 at 2 24 58 PM
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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.