Skip to content

Commit d793280

Browse files
t3dotggclaude
andcommitted
fix(observability): record only known git subcommands on process spans
process.subcommand now comes from a fixed allowlist of git subcommands, so an unknown word, path, or option value is never recorded. Also skip the values of --namespace, --config-env, --shallow-file, and --attr-source when looking for the subcommand. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent d333af1 commit d793280

2 files changed

Lines changed: 72 additions & 4 deletions

File tree

‎apps/server/src/processRunner.test.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,11 +438,20 @@ describe("processSpanAttributes", () => {
438438
expect(
439439
ProcessRunner.processSpanAttributes("git", ["--git-dir", "/repo/.git", "fetch"]),
440440
).toEqual({ "process.command": "git", "process.subcommand": "fetch" });
441+
expect(
442+
ProcessRunner.processSpanAttributes("git", ["--namespace", "customer-a", "status"]),
443+
).toEqual({ "process.command": "git", "process.subcommand": "status" });
441444
});
442445

443-
it("never records a path or value as the git subcommand", () => {
446+
it("records only known git subcommands", () => {
444447
expect(ProcessRunner.processSpanAttributes("git", ["--unknown", "/Users/me/secret"])).toEqual({
445448
"process.command": "git",
446449
});
450+
expect(ProcessRunner.processSpanAttributes("git", ["--unknown", "private-repo"])).toEqual({
451+
"process.command": "git",
452+
});
453+
expect(ProcessRunner.processSpanAttributes("git", ["customer-secret"])).toEqual({
454+
"process.command": "git",
455+
});
447456
});
448457
});

‎apps/server/src/processRunner.ts‎

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,67 @@ function finalizeRunProcess<R>(
286286
}
287287

288288
// Git global options that take the next argument as their value, as in `git -C <path> status`.
289-
const GIT_OPTIONS_WITH_VALUE = new Set(["-C", "-c", "--git-dir", "--work-tree"]);
289+
const GIT_OPTIONS_WITH_VALUE = new Set([
290+
"-C",
291+
"-c",
292+
"--git-dir",
293+
"--work-tree",
294+
"--namespace",
295+
"--config-env",
296+
"--shallow-file",
297+
"--attr-source",
298+
]);
299+
300+
// Git subcommands T3 runs, plus common ones. Only these are recorded, so a misread path,
301+
// option value, or unknown word never reaches the span.
302+
const GIT_SUBCOMMANDS = new Set([
303+
"add",
304+
"apply",
305+
"branch",
306+
"cat-file",
307+
"check-ignore",
308+
"checkout",
309+
"cherry-pick",
310+
"clean",
311+
"clone",
312+
"commit",
313+
"commit-tree",
314+
"config",
315+
"diff",
316+
"fetch",
317+
"for-each-ref",
318+
"hash-object",
319+
"init",
320+
"log",
321+
"ls-files",
322+
"ls-remote",
323+
"ls-tree",
324+
"merge",
325+
"merge-base",
326+
"pull",
327+
"push",
328+
"read-tree",
329+
"rebase",
330+
"remote",
331+
"reset",
332+
"restore",
333+
"rev-list",
334+
"rev-parse",
335+
"show",
336+
"show-ref",
337+
"sparse-checkout",
338+
"stash",
339+
"status",
340+
"submodule",
341+
"switch",
342+
"symbolic-ref",
343+
"tag",
344+
"update-index",
345+
"update-ref",
346+
"version",
347+
"worktree",
348+
"write-tree",
349+
]);
290350

291351
function gitSubcommand(args: ReadonlyArray<string>): string | undefined {
292352
let skipNext = false;
@@ -296,8 +356,7 @@ function gitSubcommand(args: ReadonlyArray<string>): string | undefined {
296356
} else if (arg.startsWith("-")) {
297357
skipNext = GIT_OPTIONS_WITH_VALUE.has(arg);
298358
} else {
299-
// Only a plain word counts, so a misread path or option value is never recorded.
300-
return /^[a-z][a-z0-9-]*$/.test(arg) ? arg : undefined;
359+
return GIT_SUBCOMMANDS.has(arg) ? arg : undefined;
301360
}
302361
}
303362
return undefined;

0 commit comments

Comments
 (0)