|
14 | 14 | const excludePattern = /^.*\/(?:npm(?:\.js)?|npm-cli(?:\.js)?|yarn(?:\.js)?|yarn\/lib\/cli(?:\.js)?)$/i; |
15 | 15 |
|
16 | 16 | /** |
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. |
18 | 19 | * @returns {boolean} |
19 | 20 | */ |
20 | 21 | function isPinoThreadStreamWorker() { |
@@ -47,30 +48,31 @@ function isPinoThreadStreamWorker() { |
47 | 48 | module.exports = exports = function isExcludedFromInstrumentation() { |
48 | 49 | const mainModule = process.argv[1]; |
49 | 50 | let excludedFromInstrumentation = typeof mainModule === 'string' && excludePattern.test(mainModule); |
50 | | - let exclusionReason = 'npm or yarn'; |
| 51 | + let reason = 'npm-yarn'; |
51 | 52 |
|
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. |
56 | 53 | if (!excludedFromInstrumentation && isPinoThreadStreamWorker()) { |
57 | 54 | excludedFromInstrumentation = true; |
58 | | - exclusionReason = 'Pino thread-stream worker'; |
| 55 | + reason = 'pino-thread-stream'; |
59 | 56 | } |
60 | 57 |
|
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())); |
67 | 61 |
|
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 { |
69 | 71 | // eslint-disable-next-line no-console |
70 | 72 | console.log( |
71 | 73 | `[Instana] INFO: Not instrumenting process ${process.pid}: ${process.argv[0]} ${mainModule}` + |
72 | 74 | // 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" ' + |
74 | 76 | '_will_ be instrumented, but not npm or yarn itself.' |
75 | 77 | ); |
76 | 78 | } |
|
0 commit comments