@@ -80,62 +80,70 @@ export class ComputeWorkloadManager implements WorkloadManager {
8080
8181 const url = `${ this . opts . gatewayUrl } /api/sandboxes` ;
8282
83+ // Wide event: single canonical log line emitted in finally
8384 const event : Record < string , unknown > = {
85+ // High-cardinality identifiers
8486 runId : opts . runFriendlyId ,
8587 runnerId,
88+ envId : opts . envId ,
89+ envType : opts . envType ,
90+ orgId : opts . orgId ,
91+ projectId : opts . projectId ,
92+ deploymentVersion : opts . deploymentVersion ,
93+ machine : opts . machine . name ,
94+ // Environment
95+ instanceName : env . TRIGGER_WORKER_INSTANCE_NAME ,
96+ // Request
8697 image : imageRef ,
8798 url,
8899 } ;
89100
90101 const startMs = performance . now ( ) ;
91102
92- const [ fetchError , response ] = await tryCatch (
93- fetch ( url , {
94- method : "POST" ,
95- headers,
96- signal : AbortSignal . timeout ( this . opts . gatewayTimeoutMs ) ,
97- body : JSON . stringify ( {
98- image : imageRef ,
99- env : envVars ,
100- } ) ,
101- } )
102- ) ;
103-
104- event . durationMs = Math . round ( performance . now ( ) - startMs ) ;
105-
106- if ( fetchError ) {
107- event . ok = false ;
108- event . error = fetchError instanceof Error ? fetchError . message : String ( fetchError ) ;
109- event . errorType =
110- fetchError instanceof DOMException && fetchError . name === "TimeoutError"
111- ? "timeout"
112- : "fetch" ;
113- this . logger . error ( "create sandbox" , event ) ;
114- return ;
103+ try {
104+ const [ fetchError , response ] = await tryCatch (
105+ fetch ( url , {
106+ method : "POST" ,
107+ headers,
108+ signal : AbortSignal . timeout ( this . opts . gatewayTimeoutMs ) ,
109+ body : JSON . stringify ( {
110+ image : imageRef ,
111+ env : envVars ,
112+ } ) ,
113+ } )
114+ ) ;
115+
116+ if ( fetchError ) {
117+ event . error = fetchError instanceof Error ? fetchError . message : String ( fetchError ) ;
118+ event . errorType =
119+ fetchError instanceof DOMException && fetchError . name === "TimeoutError"
120+ ? "timeout"
121+ : "fetch" ;
122+ return ;
123+ }
124+
125+ event . status = response . status ;
126+
127+ if ( ! response . ok ) {
128+ const [ bodyError , body ] = await tryCatch ( response . text ( ) ) ;
129+ event . responseBody = bodyError ? undefined : body ;
130+ return ;
131+ }
132+
133+ const [ parseError , data ] = await tryCatch ( response . json ( ) ) ;
134+
135+ if ( parseError ) {
136+ event . error = parseError instanceof Error ? parseError . message : String ( parseError ) ;
137+ event . errorType = "parse" ;
138+ return ;
139+ }
140+
141+ event . sandboxId = data . id ;
142+ event . ok = true ;
143+ } finally {
144+ event . durationMs = Math . round ( performance . now ( ) - startMs ) ;
145+ event . ok ??= false ;
146+ this . logger . info ( "create sandbox" , event ) ;
115147 }
116-
117- event . status = response . status ;
118-
119- if ( ! response . ok ) {
120- const [ bodyError , body ] = await tryCatch ( response . text ( ) ) ;
121- event . ok = false ;
122- event . responseBody = bodyError ? undefined : body ;
123- this . logger . error ( "create sandbox" , event ) ;
124- return ;
125- }
126-
127- const [ parseError , data ] = await tryCatch ( response . json ( ) ) ;
128-
129- if ( parseError ) {
130- event . ok = false ;
131- event . error = parseError instanceof Error ? parseError . message : String ( parseError ) ;
132- event . errorType = "parse" ;
133- this . logger . error ( "create sandbox" , event ) ;
134- return ;
135- }
136-
137- event . ok = true ;
138- event . sandboxId = data . id ;
139- this . logger . log ( "create sandbox" , event ) ;
140148 }
141149}
0 commit comments