Skip to content

feat(otel): emit server-side spans + traceresponse header (RIG-2889) - #713

Open
rigel-mintaka wants to merge 2 commits into
mainfrom
compass-obs/rig-2889-server-emission
Open

feat(otel): emit server-side spans + traceresponse header (RIG-2889)#713
rigel-mintaka wants to merge 2 commits into
mainfrom
compass-obs/rig-2889-server-emission

Conversation

@rigel-mintaka

@rigel-mintaka rigel-mintaka commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

This PR is part of a stack containing 2 PRs:

  1. main
  2. "feat(otel): emit server-side spans + traceresponse header (RIG-2889)" (this PR)
  3. feat(otel): emit runner client spans (RIG-2890) #714

Wire OTel emission into the compass-server binary and its RPC doors (T4b T2). The endpoint is env-only (OTEL_EXPORTER_OTLP_ENDPOINT); empty = tracing off, so the shipped socket-only path stays zero-overhead.

  • cmd/compass-server: bootstrap SetupTracerProvider/SetupMeterProvider off ServeConfig.OtelEndpoint (populated from the env knob in buildServeConfig), defer both shutdowns before Serve.
  • serve.go / network_door.go: mount otelconnect (outermost) + the trace-response interceptor on every door chain — socket + dev CompassService, CommsService, and the network shared bearer/admin-gate chain — so the RPC span envelopes the security interceptors and their ordering is unchanged relative to itself. Both interceptors are inert no-ops when no provider is installed. The interceptor + comms-handler construction lives in buildDoors (where otelIC is consumed), keeping Serve within its complexity budget.
  • comms.go: stamp compass.message.id onto the handler span in PostMessage and RespondToAsk (no-op when no span is active).
  • CORS: expose the traceresponse header on devCORS + networkCORS so a cross-origin browser can read the response trace id.

Adds connectrpc.com/otelconnect v0.9.0; refreshes the nix vendorHash for the moved module set.

Spec-impact: none. Refs RIG-2889.

Co-authored-by: Matt Wilkinson matt@rigel.build

Wire OTel emission into the compass-server binary and its RPC doors (T4b T2). The endpoint is env-only (`OTEL_EXPORTER_OTLP_ENDPOINT`); empty = tracing off, so the shipped socket-only path stays zero-overhead.

- **cmd/compass-server:** bootstrap `SetupTracerProvider`/`SetupMeterProvider` off `ServeConfig.OtelEndpoint` (populated from the env knob in `buildServeConfig`), defer both shutdowns before `Serve`.
- **serve.go / network_door.go:** mount `otelconnect` (outermost) + the trace-response interceptor on every door chain — socket + dev `CompassService`, `CommsService`, and the network shared bearer/admin-gate chain — so the RPC span envelopes the security interceptors and their ordering is unchanged relative to itself. Both interceptors are inert no-ops when no provider is installed. The interceptor + comms-handler construction lives in `buildDoors` (where `otelIC` is consumed), keeping `Serve` within its complexity budget.
- **comms.go:** stamp `compass.message.id` onto the handler span in `PostMessage` and `RespondToAsk` (no-op when no span is active).
- **CORS:** expose the `traceresponse` header on `devCORS` + `networkCORS` so a cross-origin browser can read the response trace id.

Adds `connectrpc.com/otelconnect v0.9.0`; refreshes the nix `vendorHash` for the moved module set.

Spec-impact: none. Refs RIG-2889.

Co-authored-by: Matt Wilkinson <matt@rigel.build>
@linear-code

linear-code Bot commented Aug 28, 2026

Copy link
Copy Markdown

RIG-2889

@github-actions

github-actions Bot commented Aug 28, 2026

Copy link
Copy Markdown

Compass engineering docs preview: https://compass-obs-rig-2889-server.compass-eng-docs.pages.dev

Deployed from compass-obs/rig-2889-server-emission at 84de91f.

…t (RIG-2889)

Review round 1 on PR #713.

### M1 — shutdown flush dropped on graceful drain

The deferred `traceShutdown`/`meterShutdown` ran with the signal-derived `ctx`, which is already cancelled by the time they fire (the SIGTERM that ends `Serve` is the same signal that cancels `ctx`). A cancelled ctx makes the SDK `Shutdown` abort its final `ForceFlush` immediately, so the last buffered batch of spans/metrics was silently dropped exactly on the drain path the defers exist to flush — contradicting the frozen design contract (bounded 2s shutdown flush, mirroring the agent).

Each defer now derives a fresh `context.WithTimeout(context.WithoutCancel(ctx), 2*time.Second)` at fire time (not at bootstrap, where an absolute deadline would expire mid-run), matching the `context.WithoutCancel` precedent already in `internal/runner/run.go`.

### L1 — vacuous disabled-path span assertion

`TestServerEmissionDisabledProducesNoSpansNoHeader` wired an in-memory exporter to a provider it never set global and never referenced, so its zero-spans check could never fire. Dropped the dead exporter; the traceresponse-header-absence assertion is the real disabled-path proof (no recording span ⇒ no header). Renamed to `TestServerEmissionDisabledSetsNoTraceResponseHeader` to match what it proves.

Spec-impact: none. Refs RIG-2889

Co-authored-by: Matt Wilkinson <matt@rigel.build>
@rigel-mintaka
rigel-mintaka marked this pull request as ready for review August 28, 2026 05:54
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.

1 participant