-
Notifications
You must be signed in to change notification settings - Fork 534
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
fix(pg): Do not add SQLCommenter comments to prepared statements #2456
fix(pg): Do not add SQLCommenter comments to prepared statements #2456
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2456 +/- ##
==========================================
+ Coverage 90.85% 90.86% +0.01%
==========================================
Files 161 161
Lines 7859 7858 -1
Branches 1614 1612 -2
==========================================
Hits 7140 7140
+ Misses 719 718 -1
|
can you explain a little more on this? why the comment would be only valid for the first execution of the query? what makes the following executions different? |
The comments contain the trace context at the time the query is created. So with prepared statements, when executing the query for the first time the comment will be created with the current trace context, but every subsequent execution will use that same trace context since the query is cached on the database side. So the comment now forever references a trace and span that have long stopped existing. It makes a lot more sense when you look at how prepared statements actually work at the database level. It's actually a two step process, one |
@pichlermarc is this consider a breaking change? Just want to make sure everything is properly flagged before giving any approvals |
Wouldn't this be a bugfix rather than a breaking change given this behaviour is always incorrect ? I doubt anyone is depending on the instrumentation producing spans that are just totally invalid. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for contributing this fix @raphael-theriault-swi
This LGTM, added 2 nits. I don't think this is a breaking change, as current behavior is a bug.
plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for working on these changes and the feedback!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the contribution.
Which problem is this PR solving?
Currently the
pg
instrumentation will add SQLCommenter comments to any query it can, even prepared ones. In the case of prepared statements this usually results in the trace context within the comment being incorrect for all but the first instance of the query being run.Short description of the changes
This adds a simple check to skip adding the comment for prepared statements. See https://node-postgres.com/features/queries#prepared-statements.