You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
psycopg2 and psycopg instrumentors use the DB-API instrumentor for sqlcommenting, an opt-in feature (docs here and here, respectively). This works to insert OTel context into PostgreSQL general logs, e.g.
2024-10-29 19:17:30 UTC,4/3,0,LOG,00000,"statement: SELECT * FROM city WHERE id = '1818' /*db_driver='psycopg2%3A2.9.9',traceparent='00-acbdad825030e4fc58260b2bd9861eb3-451dac2c63520272-01'*/",,,,,,,,,"","client backend",,0
For correlation of db queries to corresponding query spans, it would be convenient to also include the sqlcomment in the db.statement attribute of those spans, e.g.
ScopeSpans #0
ScopeSpans SchemaURL:
InstrumentationScope opentelemetry.instrumentation.psycopg2 0.49b0.dev
Span #0
Trace ID : acbdad825030e4fc58260b2bd9861eb3
Parent ID : b1b7f10bb5c841ff
ID : 451dac2c63520272
Name : SELECT
Kind : Client
Start time : 2024-10-29 19:17:38.333191847 +0000 UTC
End time : 2024-10-29 19:17:38.335095514 +0000 UTC
Status code : Unset
Status message :
Attributes:
-> db.system: Str(postgresql)
-> db.name: Str(world-db)
-> db.statement: Str(SELECT * FROM city WHERE id = %s /*db_driver='psycopg2%%3A2.9.9',traceparent='00-acbdad825030e4fc58260b2bd9861eb3-451dac2c63520272-01'*/)
-> db.user: Str(world)
-> net.peer.name: Str(postgres-world-db)
-> net.peer.port: Int(5432)
Describe the solution you'd like
Include the sqlcomment in db.statement span attribute from DB-API instrumentation.
What problem do you want to solve?
psycopg2 and psycopg instrumentors use the DB-API instrumentor for sqlcommenting, an opt-in feature (docs here and here, respectively). This works to insert OTel context into PostgreSQL general logs, e.g.
2024-10-29 19:17:30 UTC,4/3,0,LOG,00000,"statement: SELECT * FROM city WHERE id = '1818' /*db_driver='psycopg2%3A2.9.9',traceparent='00-acbdad825030e4fc58260b2bd9861eb3-451dac2c63520272-01'*/",,,,,,,,,"","client backend",,0
For correlation of db queries to corresponding query spans, it would be convenient to also include the sqlcomment in the
db.statement
attribute of those spans, e.g.Describe the solution you'd like
Include the sqlcomment in
db.statement
span attribute from DB-API instrumentation.Describe alternatives you've considered
No response
Additional Context
Similar to #2938
Would you like to implement a fix?
Yes
The text was updated successfully, but these errors were encountered: