Task — engineering-spec@1

"W3C TraceContext correlation (SDK + ai-gateway middleware + auth JWT)"

doneTASK-OBS-005
module obs · class product · priority p0 · created 2026-05-15 · shipped null
depends on TASK-OBS-001, TASK-OBS-003 · blocks none

TASK-OBS-005: W3C TraceContext correlation

Summary

Propagate W3C TraceContext across CyberOS services and embed trace_id into structured logs and RED histogram exemplars. As-built surface lives in services/shared/cyberos-obs-sdk/src/{tracecontext,logging,exemplar}.rs with red.rs counters (record_tracecontext_extracted, exemplar emission), the ai-gateway trace_ctx axum middleware in services/ai-gateway/src/server/mod.rs, and the auth JWT traceparent claim in services/auth/src/jwt.rs.

Problem

The original engineering-spec claimed crates/cyberos-obs-sdk/, separate integration test crates (tracecontext_test.rs, end_to_end_correlation_test.rs), .github/workflows/obs-correlation-gate.yml, and trace middleware on chat/memory. The live SDK is services/shared/cyberos-obs-sdk/; ai-gateway ships trace_ctx middleware; auth carries traceparent in JWT claims. The process evidence failed FM-004 (task@1 frontmatter + ## §N body), depends_on incorrectly included TASK-OBS-004, and phantom paths blocked re-entry.

Proposed Solution

Adopt the as-built layout:

Alternatives Considered

Success Metrics

Scope

In scope (as-built):

Out of scope / Non-Goals

Dependencies

depends_on: [TASK-OBS-001, TASK-OBS-003]. Soft: TASK-AI-022 (OTel propagation helpers in ai-gateway); TASK-OBS-004 (LangSmith trace_id alignment — not a hard gate for this adopt).

1. Description (normative)

Acceptance criteria

Verification

cd services && cargo test -p cyberos-obs-sdk tracecontext
cd services && cargo test -p cyberos-obs-sdk logging
cd services && cargo test -p cyberos-obs-sdk red::
cd services && cargo test -p cyberos-ai-gateway trace_ctx
cd services && cargo test -p cyberos-ai-gateway --test otel_propagation_test
# jwt_roundtrip (ignored without Postgres):
cd services && cargo test -p cyberos-auth jwt_roundtrip -- --ignored
PathCovers
cyberos-obs-sdk/src/tracecontext.rs (inline #[cfg(test)])W3C parse, extract, inject, hash16
cyberos-obs-sdk/src/logging.rs (inline #[cfg(test)])Span-scope log enrichment
cyberos-obs-sdk/src/red.rs (inline #[cfg(test)])Exemplar + tracecontext counter no-op safety
ai-gateway/src/server/mod.rs (inline tests)trace_ctx generate + echo
ai-gateway/tests/otel_propagation_test.rsTASK-AI-022 inject/extract roundtrip
auth/tests/jwt_roundtrip_test.rsJWT traceparent claim

AI Authorship Disclosure


batch/9b-obs adopt — TASK-OBS-005 re-spec against as-built TraceContext correlation.