Skip to content

Commit b3a3ee1

Browse files
committed
Fix instrument_connection to use async cursor factory for AsyncConnection
1 parent 1d97282 commit b3a3ee1

File tree

1 file changed

+8
-3
lines changed
  • instrumentation/opentelemetry-instrumentation-psycopg/src/opentelemetry/instrumentation/psycopg

1 file changed

+8
-3
lines changed

instrumentation/opentelemetry-instrumentation-psycopg/src/opentelemetry/instrumentation/psycopg/__init__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,14 @@ def instrument_connection(
268268
setattr(
269269
connection, _OTEL_CURSOR_FACTORY_KEY, connection.cursor_factory
270270
)
271-
connection.cursor_factory = _new_cursor_factory(
272-
tracer_provider=tracer_provider
273-
)
271+
if isinstance(connection, psycopg.AsyncConnection):
272+
connection.cursor_factory = _new_cursor_async_factory(
273+
tracer_provider=tracer_provider
274+
)
275+
else:
276+
connection.cursor_factory = _new_cursor_factory(
277+
tracer_provider=tracer_provider
278+
)
274279
connection._is_instrumented_by_opentelemetry = True
275280
else:
276281
_logger.warning(

0 commit comments

Comments
 (0)