()
| 428 | }; |
| 429 | |
| 430 | function createExecTraceContext(): ExecTraceContext { |
| 431 | const diagnosticsMeta = getDiagnosticsMeta(); |
| 432 | const diagnosticsDebugEnabled = diagnosticsMeta.debug === true; |
| 433 | const envTraceEnabled = parseBooleanLiteral(process.env.AGENT_DEVICE_EXEC_TRACE ?? '') === true; |
| 434 | if (!diagnosticsDebugEnabled && !envTraceEnabled) { |
| 435 | return createDisabledExecTraceContext(); |
| 436 | } |
| 437 | if (envTraceEnabled && diagnosticsMeta.flushOnSuccess !== true) { |
| 438 | updateDiagnosticsScope({ flushOnSuccess: true }); |
| 439 | } |
| 440 | const startedAtMs = Date.now(); |
| 441 | let completionEmitted = false; |
| 442 | return { |
| 443 | emitForegroundCompletion: (cmd, args) => { |
| 444 | if (completionEmitted) return; |
| 445 | completionEmitted = true; |
| 446 | emitExecCommandDiagnostic({ |
| 447 | cmd, |
| 448 | args, |
| 449 | startedAtMs, |
| 450 | }); |
| 451 | }, |
| 452 | emitBackgroundSpawn: (cmd, args) => { |
| 453 | emitExecCommandDiagnostic({ |
| 454 | cmd, |
| 455 | args, |
| 456 | data: { event: 'spawn' }, |
| 457 | }); |
| 458 | }, |
| 459 | emitBackgroundCompletion: (cmd, args, event) => { |
| 460 | if (completionEmitted) return; |
| 461 | completionEmitted = true; |
| 462 | emitExecCommandDiagnostic({ |
| 463 | cmd, |
| 464 | args, |
| 465 | startedAtMs, |
| 466 | data: { event }, |
| 467 | }); |
| 468 | }, |
| 469 | }; |
| 470 | } |
| 471 | |
| 472 | function createDisabledExecTraceContext(): ExecTraceContext { |
| 473 | return { |
no test coverage detected