11// Simple format function to avoid webpack issues with node:util
22function format ( ...args : unknown [ ] ) : string {
3- return args . map ( arg => {
4- if ( typeof arg === 'string' ) return arg ;
5- if ( arg === null || arg === undefined ) return String ( arg ) ;
6- if ( typeof arg === 'object' ) {
7- try {
8- return JSON . stringify ( arg ) ;
9- } catch {
10- return String ( arg ) ;
3+ return args
4+ . map ( ( arg ) => {
5+ if ( typeof arg === 'string' ) return arg ;
6+ if ( arg === null || arg === undefined ) return String ( arg ) ;
7+ if ( typeof arg === 'object' ) {
8+ try {
9+ return JSON . stringify ( arg ) ;
10+ } catch {
11+ return String ( arg ) ;
12+ }
1113 }
12- }
13- return String ( arg ) ;
14- } ) . join ( ' ' ) ;
14+ return String ( arg ) ;
15+ } )
16+ . join ( ' ' ) ;
17+ }
18+
19+ function shouldMirrorComponentDiagnostics ( ) : boolean {
20+ return process . env . SENTRIS_DEBUG_COMPONENTS === '1' ;
1521}
1622
1723import type {
@@ -51,8 +57,21 @@ export interface CreateContextOptions {
5157}
5258
5359export function createExecutionContext ( options : CreateContextOptions ) : ExecutionContext {
54- const { runId, componentRef, metadata : metadataInput , storage, secrets, artifacts, trace, logCollector, terminalCollector, agentTracePublisher, workflowId, workflowName, organizationId } =
55- options ;
60+ const {
61+ runId,
62+ componentRef,
63+ metadata : metadataInput ,
64+ storage,
65+ secrets,
66+ artifacts,
67+ trace,
68+ logCollector,
69+ terminalCollector,
70+ agentTracePublisher,
71+ workflowId,
72+ workflowName,
73+ organizationId,
74+ } = options ;
5675 const metadata = createMetadata ( runId , componentRef , metadataInput ) ;
5776 const scopedTrace = trace ? createScopedTrace ( trace , metadata ) : undefined ;
5877
@@ -98,11 +117,15 @@ export function createExecutionContext(options: CreateContextOptions): Execution
98117 const logger : Logger = Object . freeze ( {
99118 debug : ( ...args : unknown [ ] ) => {
100119 pushLog ( 'stdout' , 'debug' , args ) ;
101- console . debug ( `[${ componentRef } ]` , ...args ) ;
120+ if ( shouldMirrorComponentDiagnostics ( ) ) {
121+ console . debug ( `[${ componentRef } ]` , ...args ) ;
122+ }
102123 } ,
103124 info : ( ...args : unknown [ ] ) => {
104125 pushLog ( 'stdout' , 'info' , args ) ;
105- console . log ( `[${ componentRef } ]` , ...args ) ;
126+ if ( shouldMirrorComponentDiagnostics ( ) ) {
127+ console . log ( `[${ componentRef } ]` , ...args ) ;
128+ }
106129 } ,
107130 warn : ( ...args : unknown [ ] ) => {
108131 pushLog ( 'stdout' , 'warn' , args ) ;
@@ -114,14 +137,15 @@ export function createExecutionContext(options: CreateContextOptions): Execution
114137 } ,
115138 } ) as Logger ;
116139
117-
118140 const emitProgress = ( progress : ProgressEventInput | string ) => {
119141 const normalized : ProgressEventInput =
120142 typeof progress === 'string' ? { message : progress , level : 'info' } : progress ;
121143 const level = normalized . level ?? 'info' ;
122144 const message = normalized . message ;
123145
124- console . log ( `[${ componentRef } ] progress [${ level } ]: ${ message } ` ) ;
146+ if ( shouldMirrorComponentDiagnostics ( ) ) {
147+ console . log ( `[${ componentRef } ] progress [${ level } ]: ${ message } ` ) ;
148+ }
125149 if ( scopedTrace ) {
126150 scopedTrace . record ( {
127151 type : 'NODE_PROGRESS' ,
@@ -169,7 +193,9 @@ export function createExecutionContext(options: CreateContextOptions): Execution
169193 timestamp : new Date ( ) . toISOString ( ) ,
170194 metadata,
171195 } ) ;
172- console . debug ( `[${ componentRef } ]` , ...args ) ;
196+ if ( shouldMirrorComponentDiagnostics ( ) ) {
197+ console . debug ( `[${ componentRef } ]` , ...args ) ;
198+ }
173199 } ,
174200 info : ( ...args : unknown [ ] ) => {
175201 logCollector ( {
@@ -181,7 +207,9 @@ export function createExecutionContext(options: CreateContextOptions): Execution
181207 timestamp : new Date ( ) . toISOString ( ) ,
182208 metadata,
183209 } ) ;
184- console . log ( `[${ componentRef } ]` , ...args ) ;
210+ if ( shouldMirrorComponentDiagnostics ( ) ) {
211+ console . log ( `[${ componentRef } ]` , ...args ) ;
212+ }
185213 } ,
186214 warn : ( ...args : unknown [ ] ) => {
187215 logCollector ( {
0 commit comments