-
Notifications
You must be signed in to change notification settings - Fork 542
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
feat(pg): support hooking into span when query is started #1307
Conversation
7286646
to
0993f7b
Compare
Maybe I am missing something, but the query text is currently always captured into |
Yup, exactly. I need to duplicate the value into the |
593cf15
to
f171555
Compare
Are you using OpenTelemetry Collector to send spans to DD? there is the attributesprocessor which does just that If you can't modify this value in collector or prefer to use instrumentation hook that is fine and I can review this PR. |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #1307 +/- ##
==========================================
- Coverage 96.08% 95.80% -0.28%
==========================================
Files 14 18 +4
Lines 893 1217 +324
Branches 191 259 +68
==========================================
+ Hits 858 1166 +308
- Misses 35 51 +16
|
Unfortunately I'm using the DD agent's built-in support for receiving Otel data (this approach), so that I don't have to run a standalone instance of the collector. I think that the DD agent doesn't support attribute processors (or it doesn't expose that support), so a hook seems easier. |
plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts
Outdated
Show resolved
Hide resolved
f171555
to
fc54650
Compare
@blumamir Ok, I think I addressed all your comments. I also ended up renaming the hook from |
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.
LGTM 🥇
fc54650
to
dd3f8ba
Compare
Which problem is this PR solving?
Right now, it's possible to modify the span generated for a query after results are returned for the query, using the
responseHook
. However, it isn't possible to modify the span at the start of the query, based on the information available when the query is issued (i.e., the args passed toclient.query
), because that information isn't passed to theresponseHook
.For my use case, I'm using Datadog and am tracing an app that issues relatively few distinct queries. Therefore, it makes sense to identify each query as a distinct Datadog "resource", by adding a
resource.name
attribute to each span, where the value of the attribute is the query text. However, this is currently impossible, because the query text isn't available in theresponseHook
, and there's no other hook where it is available.Short description of the changes
queryHook
param to support the above use case.NB: this PR shares the first two commits with #1306, so it may be simpler to review that first. It relies on the code cleanup from #1306 to simplify implementing the
queryHook
here. (The code cleanup now allows the main code path in_getClientQueryPatch
to have a single, normalizedqueryConfig
object that can be passed to thequeryHook
.)