-
Notifications
You must be signed in to change notification settings - Fork 665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
opentelemetry-instrumentation-psycopg
claims to work for async queries, but doesn't record time
#2486
Labels
bug
Something isn't working
Comments
Thanks for the ping @xrmx. Agree that this is a bug and your proposed solution sounds reasonable @samuelcolvin, happy to review your PR |
ibash
added a commit
to ibash/opentelemetry-python-contrib
that referenced
this issue
Mar 4, 2025
This copies the traced_execution of AsyncCursorTracer except query_method is awaited within the span. Fixes open-telemetry#2486
7 tasks
ibash
added a commit
to ibash/opentelemetry-python-contrib
that referenced
this issue
Mar 5, 2025
This copies the traced_execution of AsyncCursorTracer except query_method is awaited within the span. Fixes open-telemetry#2486
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was orignally reported as pydantic/logfire#65 which has version details etc.
But in summary, using
opentelemetry-instrumentation-psycopg="0.45b0"
to instrument asyncio queries, doesn't work properly.The cause is as follows:
opentelemetry-python-contrib/instrumentation/opentelemetry-instrumentation-psycopg/src/opentelemetry/instrumentation/psycopg/__init__.py
Lines 335 to 338 in 5116305
calls
opentelemetry-python-contrib/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py
Lines 472 to 475 in 5116305
calls
opentelemetry-python-contrib/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py
Lines 408 to 414 in 5116305
which isn't designed to support an awaitable
query_method
, so it immediately returns a future, which gets awaited after the span has closed, hence zero time spans:From Logfire, we see:

when we'd expect something similar to what's observed with sync calls:

I'm not clear why
TracedCursorProxy
is required rather than just usingCursorTracer
, but either way, I'd suggest implementing anasync
varient oftraced_execution
which tries to share as much logic as possible with the sync method.If you agree, I'll try to create a PR for this over the next week or so.
The text was updated successfully, but these errors were encountered: