Claude Code. Any Model. The most powerful AI coding agent now speaks every language.
feat(stats): add request_role to StatsEvent and its OTLP record
Jack Rudenko1cf14f6e042f
diff --git a/packages/cli/src/stats-otlp.test.ts b/packages/cli/src/stats-otlp.test.tsindex 8dcf64e2..66722230 100644--- a/packages/cli/src/stats-otlp.test.ts+++ b/packages/cli/src/stats-otlp.test.ts@@ -289,6 +289,11 @@ const OPTIONAL_WIRE = {sample: "handoff",value: { stringValue: "handoff" },},+ request_role: {+ attribute: "llm.request_role",+ sample: "advisor",+ value: { stringValue: "advisor" },+ },} satisfies Record<OptionalStatsKey, { attribute: string; sample: unknown; value: unknown }>;const OPTIONAL_ENTRIES = Object.entries(OPTIONAL_WIRE) as Array<diff --git a/packages/cli/src/stats-otlp.ts b/packages/cli/src/stats-otlp.tsindex 9545cda9..5f4a2b7e 100644--- a/packages/cli/src/stats-otlp.ts+++ b/packages/cli/src/stats-otlp.ts@@ -121,6 +121,15 @@ export interface StatsEvent {*/leg_retries?: number;+ /**+ * Who issued the request. `"advisor"` marks an `--advisor` panel or collector+ * call, made by claudish itself rather than by Claude Code; absent on every+ * main request. `estimated_cost` keeps one meaning for both: the emitting+ * handler's running total, so a launch's advisor spend is the largest+ * `estimated_cost` per `(model_id, provider_name)` with this field set.+ */+ request_role?: "advisor";+// Invocationinvocation_mode: string; // "profile" | "explicit-model" | "auto-route" | "env-var" | "model-map"@@ -315,6 +324,9 @@ export function eventToLogRecord(event: StatsEvent): OtlpLogRecord {if (event.leg_retries !== undefined) {attributes.push(intAttr("llm.leg_retries", event.leg_retries));}+ if (event.request_role !== undefined) {+ attributes.push(stringAttr("llm.request_role", event.request_role));+ }return {timeUnixNano,diff --git a/packages/cli/src/stats.ts b/packages/cli/src/stats.tsindex 11ac9b24..1e622db4 100644--- a/packages/cli/src/stats.ts+++ b/packages/cli/src/stats.ts@@ -218,6 +218,8 @@ export function recordStats(partial: Partial<StatsEvent>): void {if (partial.recovery_outcome !== undefined) event.recovery_outcome = partial.recovery_outcome;// Same half-the-job rule: also pushed in `eventToLogRecord`.if (partial.leg_retries !== undefined) event.leg_retries = partial.leg_retries;+ // Same rule again: `request_role` is pushed in `eventToLogRecord` too.+ if (partial.request_role !== undefined) event.request_role = partial.request_role;appendEvent(event);