@@ -33,31 +33,27 @@ if (isNodeJsTooOld()) {
3333 // @ts -ignore TS1108 (return can only be used within a function body)
3434 return ;
3535}
36-
37- let isMainThread = true ;
38- try {
39- isMainThread = require ( 'worker_threads' ) . isMainThread ;
40- } catch ( err ) {
41- // Worker threads are not available, so we know that this is the main thread.
42- }
43-
36+ const skipPinoWorker = require ( './util/skipPinoWorker' ) ;
4437// Skip Instana instrumentation in Pino thread-stream workers.
4538// Pino uses internal worker threads for its "thread-stream" transport.
4639// These threads are not part of the main application logic and should
4740// not be instrumented.
4841//
4942// This prevents errors when the collector is loaded via NODE_OPTIONS in worker threads.
50- const { workerData } = require ( 'worker_threads' ) ;
51- if ( ! isMainThread && workerData && typeof workerData === 'object' ) {
52- const dataString = Object . values ( workerData ) . join ( ' ' ) . toLowerCase ( ) ;
53- if ( dataString . includes ( 'thread-stream' ) ) {
54- // eslint-disable-next-line no-console
55- console . warn ( '[Instana] Skipping instrumentation in thread-stream worker.' ) ;
56- module . exports = function noOp ( ) { } ;
57- module . exports . default = function noOp ( ) { } ;
58- // @ts -ignore
59- return ;
60- }
43+ if ( skipPinoWorker ( ) ) {
44+ // eslint-disable-next-line no-console
45+ console . warn ( '[Instana] Skipping instrumentation in Pino thread-stream worker.' ) ;
46+ module . exports = function noOp ( ) { } ;
47+ module . exports . default = function noOp ( ) { } ;
48+ // @ts -ignore
49+ return ;
50+ }
51+
52+ let isMainThread = true ;
53+ try {
54+ isMainThread = require ( 'worker_threads' ) . isMainThread ;
55+ } catch ( err ) {
56+ // Worker threads are not available, so we know that this is the main thread.
6157}
6258
6359const path = require ( 'path' ) ;
0 commit comments