Skip to content

Commit f3acfba

Browse files
committed
chore: fine tuning
1 parent fcc9e4a commit f3acfba

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

packages/core/src/util/excludedFromInstrumentation.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
const excludePattern = /^.*\/(?:npm(?:\.js)?|npm-cli(?:\.js)?|yarn(?:\.js)?|yarn\/lib\/cli(?:\.js)?)$/i;
1515

1616
/**
17-
* Check if the current process is a Pino thread-stream worker thread
17+
* Determines if the current process is a Pino thread-stream worker.
18+
* Pino uses background worker threads for "thread-stream" logging, which should not be instrumented.
1819
* @returns {boolean}
1920
*/
2021
function isPinoThreadStreamWorker() {
@@ -47,30 +48,31 @@ function isPinoThreadStreamWorker() {
4748
module.exports = exports = function isExcludedFromInstrumentation() {
4849
const mainModule = process.argv[1];
4950
let excludedFromInstrumentation = typeof mainModule === 'string' && excludePattern.test(mainModule);
50-
let exclusionReason = 'npm or yarn';
51+
let reason = 'npm-yarn';
5152

52-
// Skip Instana instrumentation in Pino thread-stream workers.
53-
// Pino uses internal worker threads for its "thread-stream" transport.
54-
// These threads are not part of the main application logic and should
55-
// not be instrumented.
5653
if (!excludedFromInstrumentation && isPinoThreadStreamWorker()) {
5754
excludedFromInstrumentation = true;
58-
exclusionReason = 'Pino thread-stream worker';
55+
reason = 'pino-thread-stream';
5956
}
6057

61-
if (excludedFromInstrumentation) {
62-
const logLevelIsDebugOrInfo =
63-
process.env.INSTANA_DEBUG ||
64-
(process.env.INSTANA_LOG_LEVEL &&
65-
(process.env.INSTANA_LOG_LEVEL.toLowerCase() === 'info' ||
66-
process.env.INSTANA_LOG_LEVEL.toLowerCase() === 'debug'));
58+
const logEnabled =
59+
process.env.INSTANA_DEBUG ||
60+
(process.env.INSTANA_LOG_LEVEL && ['info', 'debug'].includes(process.env.INSTANA_LOG_LEVEL.toLowerCase()));
6761

68-
if (logLevelIsDebugOrInfo) {
62+
if (excludedFromInstrumentation && logEnabled) {
63+
if (reason === 'pino-thread-stream') {
64+
// eslint-disable-next-line no-console
65+
console.log(
66+
// eslint-disable-next-line max-len
67+
`[Instana] INFO: Skipping instrumentation for process ${process.pid} - detected as a Pino thread-stream worker. ` +
68+
'Logging threads do not require instrumentation.'
69+
);
70+
} else {
6971
// eslint-disable-next-line no-console
7072
console.log(
7173
`[Instana] INFO: Not instrumenting process ${process.pid}: ${process.argv[0]} ${mainModule}` +
7274
// eslint-disable-next-line max-len
73-
` - this Node.js process seems to be ${exclusionReason}. A child process started via "npm start" or "yarn start" ` +
75+
' - this Node.js process seems to be npm or yarn. A child process started via "npm start" or "yarn start" ' +
7476
'_will_ be instrumented, but not npm or yarn itself.'
7577
);
7678
}

0 commit comments

Comments
 (0)