Skip to content
Advertisement

OpenTelemetry is not tracing SQL Statements while using cursor_factory as NamedTupleCursor

Kindly look at the code below. I’m using opentelemetry for tracing. Psycopg2Instrumentor for PostgreSQL tracing. Here only the “show server_version” SQL statement is getting traced. But the SQL statement in execute method is not traced. I think it’s because of using NamedTupleCursor cursor_factory. If I remove NamedTupleCursor, it’s tracing the main SQL statements. Could you please help me to trace the main SQL statement without removing NamedTupleCursor?

JavaScript

Advertisement

Answer

Below is the code snippet for working with Psycopg2Instrumentor for PostgreSQL tracing. The instrumentation code to be updated on passing cursor_factory in cursor parameter, rather than setting it in connection. For now, the below works for me and tracing got captured.

JavaScript

Thanks to the thread (Psycopg2Instrumentor doesn’t work for cursors with non-default cursor_factory) and @RaguramGopi

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement