-
Notifications
You must be signed in to change notification settings - Fork 36
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: exposed installation method in debug mode #1268
Conversation
commit messge to main:
|
For the normal commonJS instrumentation using
|
79e82dd
to
a754486
Compare
For me, this isn't a feature but rather a fix, which is useful for troubleshooting. It doesn’t add any new functionality for the customer. |
packages/core/src/util/esm.js
Outdated
@@ -66,3 +66,31 @@ exports.isESMApp = function isESMApp() { | |||
|
|||
return isESM; | |||
}; | |||
|
|||
exports.tracerInstrumentationInfo = function tracerInstrumentationInfo() { |
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.
This is only applicable for the collector package? what about the serverless packages?
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.
Right now considered only the collector package.
The serverless whole is another scope.
If we need the serverless information from args and env, then it can also be added I guess.
Instead of
includes('@instana/collector')
can check for
esm-register.mjs
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.
If we need the serverless information from args and env, then it can also be added I guess.
Instead of
includes('@instana/collector')
can check for
esm-register.mjs
I don't understand.
The serverless whole is another scope.
Ok, then we can do it later if needed.
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.
Instead of
includes('@instana/collector')
can check for
esm-register.mjs
this won't work btw
The serverless whole is another scope.
Yeah, I agree.
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 believe we need to check the flag for all our packages. Checking @instana/collector
would only apply to the collector package. We already have a similar check in place for detecting ESM, as seen here. I'm thinking of either extending or referencing this function . This approach would help us avoid maintaining flags in multiple functions. What do you think?
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.
That would be a good idea. Initially, I designed the function like this but then later decided to check for a single package for checking serverless and collector specifically.
Re-using the existing function will be a good idea, even I thought of this. But since the outputs and checks differ in the function isESMApp()
and function tracerInstrumentationInfo()
, need to decide how can we extend this. I will get back to you after that. Please share if you have any better solutions in mind
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.
Implemented a new logic!
packages/core/src/util/esm.js
Outdated
@@ -66,3 +66,31 @@ exports.isESMApp = function isESMApp() { | |||
|
|||
return isESM; | |||
}; | |||
|
|||
exports.tracerInstrumentationInfo = function tracerInstrumentationInfo() { | |||
const instrumentationMap = { |
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.
This logic should not be here, this file specific to esm.
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.
Okay will update.
packages/core/src/tracing/index.js
Outdated
@@ -197,6 +198,10 @@ exports.init = function init(_config, downstreamConnection, _processIdentityProv | |||
automaticTracingEnabled = config.tracing.automaticTracingEnabled; | |||
|
|||
if (tracingEnabled) { | |||
const loader = tracerInstrumentationInfo(); |
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.
IMO: This should be called only in debug mode. Could you explore the options to do that?
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.
If there is an issue reported and we want to check the logs, then IMO it might be helpful to know the instrumentation details.
But for that, we can do console.info
instead of console.debug
!
Whats your take on that?
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.
IMO this should only be logged if debug mode is enabled.
noFlags: 'no additional flags' | ||
}; | ||
|
||
const usingExperimentalLoaderFlag = |
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.
Qs: Why isn't there a check for @instana/collector
included here? I noticed that you added checks for other flags.
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 catching. That was not added in the checklist.
I will update this and add to checklist
I'm done with the review. Added one more comment. |
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
packages/core/src/tracing/index.js
Outdated
const method = getPackageInstallation(); | ||
|
||
// eslint-disable-next-line no-console | ||
console.debug(`The App has instrumented instana using: ${method}`); |
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.
issue: I am getting
The App has instrumented instana using: no additional flags
When doing
$ INSTANA_DEBUG=true node --require ~/dev/instana/nodejs-2/packages/collector/src/immediate.js app.js
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.
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.
The path is different. Maybe we only cover specific use cases?
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.
The reason is that you are referring to the packages directly.
The logic behind the comparison is checking for the @instana
keyword in the arguments (as the clients are using our npm package).
So in a client app perspective it should work if they are including our package in the application start arguments
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.
We could simplify the whole function by printing all values if --require
, --import
or --experimental-loader
is used.
e.g. customer uses node --import X --import X app.js
Advantages:
- less complicated logic, less checks
- covers the use case that if a customer uses multiple import values to dig down potential problems -> conflicts
- this is only debug information
- covers more use cases (such as the case I showed)
The output would be:
console.debug(`The App is using the following preload flags: ${preloadFlags}`);
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.
Yeah perfect 👍
@@ -179,6 +180,13 @@ exports.preInit = function preInit(preliminaryConfig) { | |||
* @param {CollectorPIDStore} _processIdentityProvider | |||
*/ | |||
exports.init = function init(_config, downstreamConnection, _processIdentityProvider) { | |||
if (process.env.INSTANA_DEBUG || process.env.INSTANA_LOG_LEVEL === 'debug') { |
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 like this check a lot 👍
S: It would be cool if you could raise a second PR to add a utility for that. We use this check in many places e.g.
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.
Yeah sure! 👍
packages/core/src/tracing/index.js
Outdated
const method = getPackageInstallation(); | ||
|
||
// eslint-disable-next-line no-console | ||
console.debug(`The App has instrumented instana using: ${method}`); |
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.
We could simplify the whole function by printing all values if --require
, --import
or --experimental-loader
is used.
e.g. customer uses node --import X --import X app.js
Advantages:
- less complicated logic, less checks
- covers the use case that if a customer uses multiple import values to dig down potential problems -> conflicts
- this is only debug information
- covers more use cases (such as the case I showed)
The output would be:
console.debug(`The App is using the following preload flags: ${preloadFlags}`);
6ea894a
to
b54a587
Compare
commit message:
|
process.env.NODE_OPTIONS?.includes('--require') | ||
|| process.env.NODE_OPTIONS?.includes('--import') | ||
|| process.env.NODE_OPTIONS?.includes('--experimental-loader')) { | ||
return process.env.NODE_OPTIONS; |
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.
NODE_OPTIONS can contain multiple information..
Possible update:
const flags = ['--require', '--import', '--experimental-loader'];
if (process.env.NODE_OPTIONS) {
const relevantFlags = process.env.NODE_OPTIONS.split(' ').filter(option =>
flags.some(flag => option.includes(flag))
);
if (relevantFlags.length > 0) {
return relevantFlags.join(' ');
}
}
if (process.execArgv.length > 0) {
const result = process.execArgv.find(arg =>
flags.some(flag => arg.includes(flag))
);
return result || 'noFlags';
} else {
return 'noFlags';
}
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.
NODE_OPTIONS can contain multiple information..
Thanks for sharing. I will update the same according to this suggestion 👍
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.
since Array.prototype.some() function returns a boolean, we might have to make some changes in the returning string if the whole argument list is required in the debug logs.
But as you pointed out, the arguments and NODE_OPTIONS can contain more information that might not be relevant to us in the debug log.
Let me think of other options.
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.
Any solution works :)
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.
Instead of printing out the whole, now logging only the flags (--import, --require, etc)
Also added a check for @instana
keyword which will be sufficient to verify that one/some of instana packages are passed in the argument list or as NODE_OPTIONS
LGTM! |
…ented instana/collector
…of host applications refs INSTA-778
aa82d63
to
f523ef0
Compare
JIRA card: INSTA-778
node --experimental-loader ./node_modules/@instana/collector/esm-loader.mjs ./index-esm.mjs
node --import ./node_modules/@instana/collector/esm-register.mjs ./index-esm.mjs
node --require ./node_modules/@instana/collector/src/immediate ./index.js
node ./index.js