Skip to content

chore: drop the asyncpg OpenTelemetry instrumentor - #59

Merged
lesnik512 merged 1 commit into
mainfrom
chore/drop-asyncpg-otel
Oct 15, 2026
Merged

lesnik512 merged 1 commit into
mainfrom
chore/drop-asyncpg-otel

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Summary

The app ran two database instrumentors, so every query was traced twice. This keeps SQLAlchemyInstrumentor and removes AsyncPGInstrumentor(capture_parameters=True) and its package.

With one instrumentor left, nothing else would notice if it stopped producing spans. A new test, tests/test_tracing.py, turns tracing on, makes a request, and checks that the SQLAlchemy instrumentor records a SELECT span under the request span.

Why

Measured against Postgres 17 in Docker on the same host, with a new session per request and 100 concurrent workers:

instrumentation requests/s spans per request
none ~4.9k 0
SQLAlchemy + asyncpg ~2.4k 8
SQLAlchemy only ~3.5k 2

The extra asyncpg spans were BEGIN, ROLLBACK and the pool pre-ping queries. capture_parameters=True also copied query parameter values, user data included, into span attributes.

What we lose

  • COMMIT no longer gets its own span. Its time still shows inside the request span.
  • Failed queries keep ERROR status and the error message, but there is no exception event with a traceback.

Watch out

opentelemetry-instrumentation-sqlalchemy (0.65b0, and 0.66b1 too) declares sqlalchemy < 2.1. On SQLAlchemy 2.1 it skips instrumentation, and lite-bootstrap silences the log line that reports the conflict. Keep the sqlalchemy<2.1 pin until a release ships 2.1 support (open-telemetry/opentelemetry-python-contrib#5120). The new test fails in that case.

Test plan

  • just lint and the full test suite pass, with coverage at 100%.
  • With SQLAlchemyInstrumentor removed from build_app, the new test fails.

Keep SQLAlchemyInstrumentor as the only database instrumentor and add a
test that DB queries still produce SQLAlchemy spans.
@lesnik512
lesnik512 merged commit e96b66e into main Oct 15, 2026
2 checks passed
@lesnik512
lesnik512 deleted the chore/drop-asyncpg-otel branch October 15, 2026 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant