opentelemetry-instrumentation-psycopg
claims to work for async queries, but doesn't record time
#2486
Labels
bug
Something isn't working
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:
![image](https://private-user-images.githubusercontent.com/4039449/327140793-4dbfd834-9fe8-4dd3-a4d1-802e7b153aad.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5NzExMjksIm5iZiI6MTczODk3MDgyOSwicGF0aCI6Ii80MDM5NDQ5LzMyNzE0MDc5My00ZGJmZDgzNC05ZmU4LTRkZDMtYTRkMS04MDJlN2IxNTNhYWQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDdUMjMyNzA5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9Mjk2YjQ1NzIxMmRjNTZkNmU4N2Y3YmFhNTAxYTUwYmQ0NzFmZGI4YTI0ODU2NzFjM2ZhM2ZkODcxNjNmNDllNCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.RbI38APlndcBWj59SG7oIDylAE_sZEwltBy0BWhkBFg)
when we'd expect something similar to what's observed with sync calls:
![image](https://private-user-images.githubusercontent.com/4039449/327140890-8b9770ef-61c6-4418-a9a4-0827ef7167ce.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5NzExMjksIm5iZiI6MTczODk3MDgyOSwicGF0aCI6Ii80MDM5NDQ5LzMyNzE0MDg5MC04Yjk3NzBlZi02MWM2LTQ0MTgtYTlhNC0wODI3ZWY3MTY3Y2UucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDdUMjMyNzA5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YjVjYjgzZWJiZDkyZjkwY2VjMWJmNGVhNjBhMGRkMzc4ZjcyODY0ZjMwZTZhNTk4YjJjZDIxOWIzZTEyYjliNSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.Uw1HPPvqHL2W45TR1LB0OEgTr2vSUHdu59DDGG3k0eA)
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: