-
Notifications
You must be signed in to change notification settings - Fork 529
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(instr-undici): fix issue with config in constructor #2395
fix(instr-undici): fix issue with config in constructor #2395
Conversation
@@ -113,16 +106,6 @@ export class UndiciInstrumentation extends InstrumentationBase<UndiciInstrumenta | |||
this.subscribeToChannel('undici:request:error', this.onError.bind(this)); | |||
} | |||
|
|||
override setConfig(config: UndiciInstrumentationConfig = {}): void { |
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.
Note for reviewer: here I was mixing UndiciInstrumentationConfig
with InstrumentationConfig
. This side effect shouldn't be there
this._channelSubs.forEach(sub => sub.channel.unsubscribe(sub.onMessage)); | ||
this._channelSubs.length = 0; | ||
super.disable(); |
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.
Note for reviewer: no need to call super since the parent class method deals with patching/unpatching and does not apply here
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.
super.disable() is also setting this._enabled = false
, so I wonder if it still should be called.
Those calls to super.
in the enable() and disable() were added in this PR: https://github.com/open-telemetry/opentelemetry-js-contrib/pull/2289/files#diff-8e6dd9963dd47a60e25c9ac92d7a5ae25ce79c40340cb4721eefd203bec81a60R86
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.
I've restored the super.disable()
and super.enable()
calls, to allow InstrumentationBase to maintain its internal this._enabled
setting.
@@ -57,6 +54,9 @@ describe('UndiciInstrumentation `fetch` tests', function () { | |||
this.skip(); | |||
} | |||
|
|||
instrumentation = new UndiciInstrumentation(); |
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.
Note for reviewer: the test runner was loading all the test suites at once and also evaluating the 1st describe
block. As a consequence there were 3 instances of the instrumentation before any test was ran. Leading to errors because all instances where getting messages from diagnostics channels
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.
Nice find!
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2395 +/- ##
==========================================
- Coverage 90.97% 90.52% -0.45%
==========================================
Files 146 157 +11
Lines 7492 7622 +130
Branches 1502 1571 +69
==========================================
+ Hits 6816 6900 +84
- Misses 676 722 +46
|
Slightly related, I've opened open-telemetry/opentelemetry-js#4941 to eventually deal with a confusion that can come from using |
Here is my test script for manual testing of the usage via NodeSDK, with getNodeAutoInstrumentations (as shown in the original reported issue), and without
const path = require('path');
const {NodeSDK} = require('@opentelemetry/sdk-node');
const {getNodeAutoInstrumentations} = require('@opentelemetry/auto-instrumentations-node');
const {UndiciInstrumentation} = require('./');
// Instrument undici.
process.env.OTEL_TRACES_EXPORTER = 'console'
const sdk = new NodeSDK({
serviceName: path.parse(process.argv[1]).name,
instrumentations: [
// 1.
// new UndiciInstrumentation(),
// 2.
// new UndiciInstrumentation({enabled: false}),
// 3.
// new UndiciInstrumentation({enabled: true}),
// 4.
getNodeAutoInstrumentations({
'@opentelemetry/instrumentation-undici': {
enabled: true,
},
}),
],
});
process.once('beforeExit', () => {
sdk.shutdown();
});
sdk.start();
// Use undici.
const undici = require('undici');
async function main() {
const res = await undici.request('http://www.google.com/');
console.log('response: %s', res.statusCode);
const body = await res.body.text();
console.log('response body: %s...', body.slice(0, 40));
}
main(); All four cases work as I'd expect. Case 3 results in no undici span; all other cases result in an undici span. |
... they work after I get the commit in that I had. Still trying to get that pushed. |
…s this._enabled state can be maintained; explain some of the confusion with enabled state handling in InstrumentationBase and go back to using config.enabled to decide whether to generate instrumentation One tweak on using config.enabled is that I'm checking `!== false` in case the config object doesn't have "enabled" defined -- currently possible if `instr.setConfig({})` is called. I opened open-telemetry/opentelemetry-js#4941 for that.
Which problem is this PR solving?
Fixes: #2391
Short description of the changes
enabled
internal config from the logic of the instrumentation. Now it relies only in enable/disable methods