Skip to content
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

Include sqlcomment in db.statement span attribute from DB-API instrumentation #2936

Closed
tammy-baylis-swi opened this issue Oct 29, 2024 · 0 comments · Fixed by #2935
Closed
Assignees

Comments

@tammy-baylis-swi
Copy link
Contributor

tammy-baylis-swi commented Oct 29, 2024

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.

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.

Describe alternatives you've considered

No response

Additional Context

Similar to #2938

Would you like to implement a fix?

Yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant