1313// no value and also creates confusing log output, so we exclude them here explicitly.
1414const excludePattern = / ^ .* \/ (?: n p m (?: \. j s ) ? | n p m - c l i (?: \. j s ) ? | y a r n (?: \. j s ) ? | y a r n \/ l i b \/ c l i (?: \. j s ) ? ) $ / i;
1515
16+ /**
17+ * Check if the current process is a Pino thread-stream worker thread
18+ * @returns {boolean }
19+ */
20+ function isPinoThreadStreamWorker ( ) {
21+ try {
22+ const { isMainThread, workerData } = require ( 'worker_threads' ) ;
23+ if ( isMainThread ) return false ;
24+
25+ if ( workerData && typeof workerData === 'object' ) {
26+ const nested = workerData . workerData ;
27+ const isPinoWorker =
28+ typeof workerData . filename === 'string' &&
29+ nested &&
30+ nested . $context &&
31+ typeof nested . $context . threadStreamVersion === 'string' ;
32+
33+ if ( isPinoWorker ) {
34+ return true ;
35+ }
36+ }
37+ return false ;
38+ } catch {
39+ return false ;
40+ }
41+ }
42+
1643/**
1744 * @type {Function }
1845 * @returns {boolean }
1946 */
2047module . exports = exports = function isExcludedFromInstrumentation ( ) {
2148 const mainModule = process . argv [ 1 ] ;
22- const excludedFromInstrumentation = typeof mainModule === 'string' && excludePattern . test ( mainModule ) ;
49+ let excludedFromInstrumentation = typeof mainModule === 'string' && excludePattern . test ( mainModule ) ;
50+ let exclusionReason = 'npm or yarn' ;
51+
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+ if ( ! excludedFromInstrumentation && isPinoThreadStreamWorker ( ) ) {
57+ excludedFromInstrumentation = true ;
58+ exclusionReason = 'Pino thread-stream worker' ;
59+ }
2360
2461 if ( excludedFromInstrumentation ) {
2562 const logLevelIsDebugOrInfo =
@@ -32,7 +69,8 @@ module.exports = exports = function isExcludedFromInstrumentation() {
3269 // eslint-disable-next-line no-console
3370 console . log (
3471 `[Instana] INFO: Not instrumenting process ${ process . pid } : ${ process . argv [ 0 ] } ${ mainModule } ` +
35- ' - this Node.js process seems to be npm or yarn. A child process started via "npm start" or "yarn start" ' +
72+ // 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" ` +
3674 '_will_ be instrumented, but not npm or yarn itself.'
3775 ) ;
3876 }
0 commit comments