-
Notifications
You must be signed in to change notification settings - Fork 580
fix(redis): use new tracer after setTracerProvider #2865
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(redis): use new tracer after setTracerProvider #2865
Conversation
|
||
const dbStatementSerializer = | ||
config?.dbStatementSerializer || defaultDbStatementSerializer; | ||
const span = instrumentation.tracer.startSpan( |
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.
reviewer note: this is the fix. here we use instrumentation.tracer
which gets updated in after setTracerProvider
so we always use the latest one
}, | ||
err => { | ||
if (err) { | ||
instrumentation._diag.error( |
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.
reviewer note: bug fixed here as well. using instrumentation._diag
scoped logger instead of diag
directly which aligns with best practices and other instrumentations
@@ -49,17 +28,14 @@ const endSpan = (span: Span, err?: Error | null) => { | |||
span.end(); | |||
}; | |||
|
|||
export const getTracedCreateClient = (tracer: Tracer, original: Function) => { | |||
export const getTracedCreateClient = (original: Function) => { |
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.
reviewer note: removing unused parameter (which is also locked to it's initial value and does not update on setTracerProvider
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2865 +/- ##
==========================================
- Coverage 89.69% 89.69% -0.01%
==========================================
Files 186 186
Lines 9048 9041 -7
Branches 1855 1855
==========================================
- Hits 8116 8109 -7
Misses 932 932
🚀 New features to boost your workflow:
|
Which problem is this PR solving?
This PR fixes a bug in "redis" instrumentation, where the
tracer
used to create spans is brought into closure scope once at instrumentation "create client" patch time and then used regardless of any new tracer provider being set via thesetTracerProvider
on the instrumentation instance.The function taking care of doing the patch and creating the span is now found in
utils.ts
which I think less makes sense logically and also requires passingtracer
,config
(and we should also usediag
andmeter
) to autil
function which is the cause for the current bug. This pattern is uncommon in the repo since having the function on instrumentation class guarantee simple access to providers instead of passing them as arguments.I am working on adding support for redis v5, and wanted to first consolidate
v4
into this package, and run into this bug will hooking up the multi-version support.Short description of the changes
I moved the function from
utils.ts
to a member function on the instrumentation class. the patched function now callsinstrumentation.tracer
which is a getter function that returns_tracer
which is updated on the instrumentation every timesetTracerProvider
is called.This guarantee that
startSpan
is called on a tracer from the most up-to-date tracerProvider that was set via instrumentation public api function.Added a new test to assert this change (failing before the refactor and passing after). The PR only moved the function from
utils.ts
andinstrumentation.ts
and changed thetracer
being used. the function content itself is not modified