TypeScript
feat(observability): name the command on subprocess spans (#13701)
Theo Browne20885cecf77e
diff --git a/apps/server/src/processRunner.test.ts b/apps/server/src/processRunner.test.tsindex e264ba7849d..d7f3799e103 100644--- a/apps/server/src/processRunner.test.ts+++ b/apps/server/src/processRunner.test.ts@@ -412,3 +412,11 @@ describe("isWindowsCommandNotFound", () => {}),);});++describe("commandName", () => {+ it("drops the directory from POSIX and Windows paths", () => {+ expect(ProcessRunner.commandName("/Users/me/.local/bin/claude")).toBe("claude");+ expect(ProcessRunner.commandName("C:\\Program Files\\nodejs\\npx.cmd")).toBe("npx.cmd");+ expect(ProcessRunner.commandName("git")).toBe("git");+ });+});diff --git a/apps/server/src/processRunner.ts b/apps/server/src/processRunner.tsindex 0a9bb9b04a4..36bb5b649f0 100644--- a/apps/server/src/processRunner.ts+++ b/apps/server/src/processRunner.ts@@ -285,10 +285,14 @@ function finalizeRunProcess<R>();}+/** The executable name without its directory, recorded as `process.command` on process spans. */+export const commandName = (command: string) => command.replace(/^.*[\\/]/, "");+const runProcessCore = Effect.fn("processRunner.runProcessCore")(function* (spawner: ChildProcessSpawner.ChildProcessSpawner["Service"],input: ProcessRunInput,): Effect.fn.Return<ProcessRunOutput, ProcessRunError, Scope.Scope> {+ yield* Effect.annotateCurrentSpan("process.command", commandName(input.command));const maxOutputBytes = input.maxOutputBytes ?? DEFAULT_MAX_OUTPUT_BYTES;const outputMode = input.outputMode ?? "error";const truncatedMarker = input.truncatedMarker ?? "";