@@ -37,67 +37,54 @@ const _processThreadBreadcrumbIntegration = ((options: Options = {}) => {
3737} ) satisfies IntegrationFn ;
3838
3939/**
40- * Capture breadcrumbs for child process and thread creation, exit and error .
40+ * Capture breadcrumbs for child processes and worker threads .
4141 */
4242export const processThreadBreadcrumbIntegration = defineIntegration ( _processThreadBreadcrumbIntegration ) ;
4343
4444function captureChildProcessEvents ( child : ChildProcess , options : Options ) : void {
4545 let hasExited = false ;
4646 let data : Record < string , unknown > | undefined ;
4747
48- child . on ( 'spawn' , ( ) => {
49- // This is Sentry getting macOS OS context
50- if ( child . spawnfile === '/usr/bin/sw_vers' ) {
51- hasExited = true ;
52- return ;
53- }
54-
55- data = { spawnfile : child . spawnfile } ;
56- if ( options . includeChildProcessArgs ) {
57- data . spawnargs = child . spawnargs ;
58- }
59-
60- addBreadcrumb ( {
61- category : 'child_process' ,
62- message : 'Child process spawned' ,
63- level : 'info' ,
64- data,
65- } ) ;
66- } ) ;
67-
68- child . on ( 'exit' , ( code , signal ) => {
69- if ( ! hasExited ) {
70- hasExited = true ;
48+ child
49+ . on ( 'spawn' , ( ) => {
50+ // This is Sentry getting macOS OS context
51+ if ( child . spawnfile === '/usr/bin/sw_vers' ) {
52+ hasExited = true ;
53+ return ;
54+ }
7155
72- let message = 'Child process exited' ;
73- if ( code !== null ) {
74- message += ` with code ' ${ code } '` ;
56+ data = { spawnfile : child . spawnfile } ;
57+ if ( options . includeChildProcessArgs ) {
58+ data . spawnargs = child . spawnargs ;
7559 }
76- if ( signal !== null ) {
77- message += ` with signal '${ signal } '` ;
60+ } )
61+ . on ( 'exit' , code => {
62+ if ( ! hasExited ) {
63+ hasExited = true ;
64+
65+ // Only log for non-zero exit codes
66+ if ( code !== null && code !== 0 ) {
67+ addBreadcrumb ( {
68+ category : 'child_process' ,
69+ message : `Child process exited with code '${ code } '` ,
70+ level : 'warning' ,
71+ data,
72+ } ) ;
73+ }
7874 }
79-
80- addBreadcrumb ( {
81- category : 'child_process' ,
82- message,
83- level : code !== 0 ? 'warning' : 'info' ,
84- data,
85- } ) ;
86- }
87- } ) ;
88-
89- child . on ( 'error' , error => {
90- if ( ! hasExited ) {
91- hasExited = true ;
92-
93- addBreadcrumb ( {
94- category : 'child_process' ,
95- message : `Child process errored with ${ error . message } ` ,
96- level : 'error' ,
97- data,
98- } ) ;
99- }
100- } ) ;
75+ } )
76+ . on ( 'error' , error => {
77+ if ( ! hasExited ) {
78+ hasExited = true ;
79+
80+ addBreadcrumb ( {
81+ category : 'child_process' ,
82+ message : `Child process errored with '${ error . message } '` ,
83+ level : 'error' ,
84+ data,
85+ } ) ;
86+ }
87+ } ) ;
10188}
10289
10390function captureWorkerThreadEvents ( worker : Worker ) : void {
@@ -106,26 +93,11 @@ function captureWorkerThreadEvents(worker: Worker): void {
10693 worker
10794 . on ( 'online' , ( ) => {
10895 threadId = worker . threadId ;
109-
110- addBreadcrumb ( {
111- category : 'worker_thread' ,
112- message : 'Worker thread online' ,
113- level : 'info' ,
114- data : { threadId } ,
115- } ) ;
116- } )
117- . on ( 'exit' , code => {
118- addBreadcrumb ( {
119- category : 'worker_thread' ,
120- message : `Worker thread exited with code '${ code } '` ,
121- level : code !== 0 ? 'warning' : 'info' ,
122- data : { threadId } ,
123- } ) ;
12496 } )
12597 . on ( 'error' , error => {
12698 addBreadcrumb ( {
12799 category : 'worker_thread' ,
128- message : `Worker thread errored with ${ error . message } ` ,
100+ message : `Worker thread errored with ' ${ error . message } ' ` ,
129101 level : 'error' ,
130102 data : { threadId } ,
131103 } ) ;
0 commit comments