Skip to content

Observability: OTel GenAI spans from the orchestrator + cross-thread failure-mode clustering - #333

Merged
currentbits merged 14 commits into
mainfrom
coder/observability-otel-spans-from-the-orches-63d5e2
Aug 17, 2026
Merged

currentbits merged 14 commits into
mainfrom
coder/observability-otel-spans-from-the-orches-63d5e2

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Closes #280.

Solenta drives claude/codex/kimi/grok/opencode from the outside, so it is the only place a cross-provider trace tree exists. This makes that tree exportable, and mines the event log it already keeps for recurring failures.

Spans

electron/otel.js emits OTLP/HTTP with a JSON body (POST <endpoint>/v1/traces). There is deliberately no @opentelemetry/* dependency: OTLP/JSON is a stable documented encoding, so the exporter is a batched fetch of a plain object, and the batching mirrors the existing session-record.js fire-and-forget pattern. package.json is unchanged.

Ids are derived, never stored: traceId from the ROOT thread (walking handoffFrom, cycle-guarded), so an orchestrator and its entire forked crew share one trace and a restart mid-thread keeps it. spanId from the run id, tool span ids from runId:toolId — so a tool span can name its parent with no registry.

Attributes follow the OTel GenAI semantic conventions: gen_ai.operation.name, gen_ai.provider.name, gen_ai.agent.id (provider+profile), gen_ai.request.model, gen_ai.usage.{input,output}_tokens, and session.id = the thread id, plus solenta.* for cost, project and orch-worker.

Emission lives in electron/runner.js at the choke points that already existed, so all five provider paths are covered by one call site each rather than five parallel implementations:

  • startRun opens the run span; notifyRunTerminal closes it with status and usage.
  • Tool spans are bracketed by appendMessage — the one place every adapter mints a tool message, therefore the only place a tool start is observable — and closed by noteToolSpan at the four adapter result sites.
  • The orchestrator fork gets its own span parenting the worker's run, so a crew reads as one tree.

Claude Code's native metrics

Redirected rather than received. otel.claudeEnv() returns CLAUDE_CODE_ENABLE_TELEMETRY=1 plus OTEL_EXPORTER_OTLP_* pointed at the same collector, spread into the spawn through a new claude.js envExtra option (the same shape codex.js already had). Because that is env-only it joins the warm-CLI reuse key in startClaudeRun — otherwise a kept-alive process spawned before the toggle would silently mask it.

This is ~10 lines instead of standing up an in-process OTLP receiver. The metrics land beside our spans in the user's collector, correlated by session.id. Displaying them inside Solenta would be the follow-up.

Failure-mode clustering

electron/failuremodes.js groups errored/stalled/retried threads by a normalized error signature — paths, uuids, hex ids, long digit runs, quoted strings, timestamps, durations and byte counts all redacted — so the same failure across six threads reads as one mode with six offenders instead of six unrelated errors. HTTP statuses stay distinct (404 and 500 are two modes); exit codes collapse. Signatures that normalize down to nothing meaningful are discarded rather than forming one giant useless bucket, and one-offs are filtered since they are not yet recurring. Ranked by count, then recency, with a stable tiebreak so the order never flickers.

Deterministic, no LLM and no embeddings, computed on demand at insights:failureModes. Surfaced in a new Insights view with click-through to each offending thread, and the OTLP endpoint / headers / Claude-metrics fields added to Settings.

Behaviour when off

Everything is inert while settings.otel.endpoint is null: nothing buffered, no timer armed, no request made, and no exception path into a run. Every exporter method swallows its own failures, so a dead collector cannot affect a run.

Deliberate deviation from the issue

#280 asks for a periodic automation for the clustering. This computes on demand instead — it is deterministic and runs in milliseconds over the whole store, so a scheduler would add stored state and a retention policy without producing any additional information. The tradeoff: a mode is visible when you open the view, rather than proactively telling you something has now failed six times. automations.js already has the minute-ticker if that notification turns out to be worth it.

Tests

+38 new, all four suites run:

Suite Result
core 38/38
renderer 789/789
memory 122/122
electron 913/914

The single electron failure is wireClient × webBridge over a real socket > reconnect, which fails identically on main — a pre-existing baseline, not a regression.

New coverage: otel.test.js (8, exporter against injected fetch/thread/clock — derived id stability, nanosecond string timestamps, fork trace sharing, error status, no-endpoint inertness), failuremodes.test.js (10, clustering/normalization/ranking/corrupt input), otel-runner.test.js (4, a real run through the runner reaching a stubbed collector with the tool span parented to the run span in one trace, an ERROR span carrying stderr, nothing posted with no endpoint, and the telemetry env actually arriving in the spawned CLI), plus 16 renderer tests for the view, the settings fields and header parsing.

  • PR created by the Claude Code agent

Willem and others added 13 commits August 17, 2026 15:42
Shared plumbing only — no behavior. Lets the three implementation files be
written independently without touching the same layers:

- AppSettings.otel (endpoint, headers, claudeMetrics) + FailureMode types
- store.js normalizeOtel + setSettings validation (http(s) URL or null)
- insights:failureModes wired through ipc/preload/wireClient/devCoder
- electron/otel.js: documented no-op skeleton (createOtel API)
- electron/failuremodes.js: clusterFailureModes signature returning []

Co-Authored-By: Claude Opus 5 <[email protected]>
Span emission for every provider path through the two choke points that
already exist: startRun opens the run span, notifyRunTerminal closes it with
status and usage. Tool spans hang off appendMessage (the one place every
adapter mints a tool message, so it is the only place a tool START is
visible) and are closed by noteToolSpan at the four adapter result sites.

The orchestrator fork gets its own span and parents the worker's run, so a
crew reads as one trace tree — the cross-provider view only Solenta has.

claude.js gains envExtra (same shape codex.js already had) so Claude Code's
native OTel metrics can be pointed at the same collector. It is env-only, so
it joins the warm-CLI reuse key: toggling the setting must not be masked by a
kept-alive process spawned before it.

All of it is inert while settings.otel.endpoint is null.

Co-Authored-By: Claude Opus 5 <[email protected]>
Normalized-signature grouping of failed, stalled, and retried
threads so the same diagnostic (paths and ids redacted) ranks as
one mode with offenders. Deterministic, no LLM.
Emit invoke_agent and execute_tool spans over OTLP/HTTP JSON with no
@opentelemetry/* dependency. The wire format is a documented stable
encoding, so a batched fetch of a plain object is enough; an SDK would
only pay off for sampling, context propagation into the CLIs, or metrics.

Ids are sha256-derived (never stored) so a fork crew shares one trace
and a tool span can name its parent run without a registry. Export is
inert when endpoint is null.
…into coder/observability-otel-spans-from-the-orches-63d5e2
…into coder/observability-otel-spans-from-the-orches-63d5e2
otel.js: `i()` -> `intValue()`, `kv()` -> `attr()`, and a new `unixNano()` that
also fixes a real gap — toolCall never validated its timestamps, so a missing
one produced "undefined000000" and a collector rejects the whole batch. dest()
is pure now; dropping the buffer when export is switched off is explicit in
enqueue rather than a side effect of reading config.

otel-runner.test.js covers the half unit tests cannot: a real run through the
runner reaching a collector, the tool span parented to the run span in one
trace, an ERROR span carrying the stderr reason, nothing posted with no
endpoint, and the Claude telemetry env actually arriving in the spawned CLI.

Co-Authored-By: Claude Opus 5 <[email protected]>
The three-digit HTTP rule cannot distinguish a 404 from a SIGINT exit 130 by
shape, so 'exit 130' was forming its own failure mode while exit 1 and 2
collapsed — contradicting the comment above it. Normalizing 'exit <digits>'
first makes both claims true: exit codes collapse, 404 vs 500 stay separate.

Co-Authored-By: Claude Opus 5 <[email protected]>
Ranked failure-mode list with click-through to offending threads,
and OTLP endpoint/headers/Claude-metrics fields in Settings.
…into coder/observability-otel-spans-from-the-orches-63d5e2
A Record<FailureKind, string> mapping each kind to its own name, plus a
?? fallback to the same value. Rendering offender.kind is identical.

Co-Authored-By: Claude Opus 5 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Eight conflicts, all the same shape: main landed the morning digest (#323),
worktree GC (#316) and the verification gate (#296) in the same additive slots
this branch used for insights/otel. Both sides kept everywhere —

- preload/ipc/wireClient/shared-ipc: insights:failureModes alongside digest:*
- devCoder: both fixtures
- App/Sidebar: "insights" and "digest" both in the view union, both nav
  buttons with their own icons, both open callbacks
- SettingsModal: OtelSettings alongside the Gc* types

No behavioral reconciliation was needed — the two features do not interact.

core 38/38, renderer 822/822, memory 144/144, electron 966/967 (the one
failure is the pre-existing wireClient/webBridge reconnect baseline).

Co-Authored-By: Claude Opus 5 <[email protected]>
@currentbits
currentbits merged commit 17ecb16 into main Aug 17, 2026
1 check failed
@currentbits
currentbits deleted the coder/observability-otel-spans-from-the-orches-63d5e2 branch October 3, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Observability: OTel spans from the orchestrator + failure-mode clustering across threads

1 participant