From df1cfd048be3a28c8dcee028a8f38fbb11a6c92f Mon Sep 17 00:00:00 2001 From: zzstoatzz Date: Wed, 22 Jul 2026 10:49:41 -0500 Subject: [PATCH] match upstream context propagation --- build.zig.zon | 4 ++-- docs/configuration-parity.md | 2 +- docs/opentelemetry.md | 11 +++++++---- src/internal/observability.zig | 6 ++++++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/build.zig.zon b/build.zig.zon index a2c92d7..d90efcc 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -25,8 +25,8 @@ .hash = "rocksdb-9.7.4-z_CUTu7bAADWOmsU-JQTz1V91P7c6I8BzMS2_fkGtyLu", }, .otel = .{ - .url = "git+https://github.com/zzstoatzz/otel-zig.git#5e4d5d3223c90783c0fd39ea0137184f343c1558", - .hash = "otel-0.0.1-9q9ZWqD2EwAJbVOVObRoT8103sMb4ns2UHzoibbJ_2Ep", + .url = "git+https://github.com/zzstoatzz/otel-zig.git#0d7d5ffb4e58a181f74b09fadc976936ba5e2333", + .hash = "otel-0.0.1-9q9ZWmwwFAAhSkmrEejzkOcc0gQGNC1pLxvv1TmhhCpj", }, }, .paths = .{ diff --git a/docs/configuration-parity.md b/docs/configuration-parity.md index c43a561..620a630 100644 --- a/docs/configuration-parity.md +++ b/docs/configuration-parity.md @@ -28,7 +28,7 @@ the same runtime mechanism and an offline receipt observes that behavior. | public/debug bind addresses | closed | `serve --addr` binds the protocol-only public listener, an empty `--debug-addr` binds nothing, and a configured debug listener exclusively serves health/readiness/metrics; `just listener-contract` proves route isolation, public WebSocket upgrade, rejected debug upgrade, disabled-debug refusal, listener readiness, and the historical combined-port compatibility mode through real offline processes | | shutdown/client drain timeouts | closed | canonical signed Go-duration flags, 5s/10s defaults, net/http's non-positive 30s sentinel, the client drain's already-expired non-positive sentinel (immediate teardown with a best-effort close frame), listener-admission gating, concurrent public/debug/pipeline shutdown, close code 1001 for positive budgets, cooperative early exit, and one shared silent-client deadline are covered by unit and real ReleaseSafe process receipts. Per-client close hooks now fan out concurrently with borrowed-handler lifetime protection; a real-socket transport regression saturates the first peer's send buffer, proves a later peer receives 1001 before the deadline, and proves the blocked writer is interrupted at the shared deadline. | | log level/format | closed | `--log-level` retains debug calls in ReleaseSafe and applies the upstream case-insensitive aliases plus info default to every `std.log` producer; `--log-format` defaults to newline-delimited JSON and selects canonical text fields. `just logging-contract` proves default JSON, warn filtering, text/debug output, persistent root-flag placement, and fail-closed invalid values through real offline processes. | -| OpenTelemetry | open | provider bootstrap is real and empirically covered: endpoint activation/precedence, HTTP/protobuf path rules, headers, gzip, insecure mode, exporter timeout, batch queue/delay/size, the six SDK samplers, process plus service resource attributes, global provider installation, and bounded shutdown export all run through pinned `otel-zig`. Every pinned production span now matches upstream names, scopes, parentage, attributes, and success/error finalization, including `xrpcapi/getBlock`; real offline OTLP collectors exercise the production sync/async archive and success/failure XRPC boundaries. Remaining blockers are TraceContext+Baggage propagation, exporter retry, BSP export timeout, and custom CA/mTLS credentials. See `opentelemetry.md`. | +| OpenTelemetry | open | provider bootstrap is real and empirically covered: endpoint activation/precedence, HTTP/protobuf path rules, headers, gzip, insecure mode, exporter timeout, batch queue/delay/size, the six SDK samplers, process plus service resource attributes, global provider installation, W3C TraceContext+Baggage propagation (including no-exporter mode), and bounded shutdown export all run through pinned `otel-zig`. Every pinned production span now matches upstream names, scopes, parentage, attributes, and success/error finalization, including `xrpcapi/getBlock`; real offline OTLP collectors exercise the production sync/async archive and success/failure XRPC boundaries. Remaining blockers are exporter retry, BSP export timeout, and custom CA/mTLS credentials. See `opentelemetry.md`. | | `JETSTREAM_*` environment sources and unknown-variable rejection | closed | the exact pinned flag-source map applies root, serve, and `inspect-all` values with CLI-over-environment precedence; overridden invalid values are never parsed. Unknown names are sorted/deduplicated and rejected before command execution while upstream's Kubernetes `JETSTREAM_APP_*` and its `JETSTREAM_ORACLE_*`/`JETSTREAM_SIM_*` test namespaces are exempt. `just environment-contract` proves real ReleaseSafe root/inspect/serve processes, representative string behavior, every typed source, timestamp-import authentication, and precedence offline; the multiseed oracle proves its inherited upstream seed reaches the crash campaign without leaking into Stream configuration. | | serve/version/inspect command surface | closed | `serve` is accepted explicitly while retaining Stream's historical flag-only invocation. `version` emits the upstream build-information shape. `inspect-segment` matches the pinned renderer byte-for-byte on an upstream-produced sealed fixture while also walking active files, surfacing partial tails, and labelling readable checksum corruption. `inspect-all` folds the real steady and bootstrap trees with upstream's missing-root, racing-tail, active-skip, aggregation, sorting, truncation, and text-rendering semantics; a copied upstream golden report is byte-exact. Listener and root logging controls remain tracked by their separate rows. | diff --git a/docs/opentelemetry.md b/docs/opentelemetry.md index 5c7e621..b59c278 100644 --- a/docs/opentelemetry.md +++ b/docs/opentelemetry.md @@ -9,6 +9,8 @@ Stream uses the sibling `otel-zig` SDK and OTLP exporter. No endpoint means a real no-op global provider. Setting either endpoint below installs a batched provider, merges detected process/resource attributes with `service.name` and `service.version`, and flushes it within the ordinary graceful-shutdown budget. +Both modes install the same process-wide W3C TraceContext plus Baggage composite +propagator as upstream, so an absent exporter does not discard incoming context. | Environment | Behavior | |---|---| @@ -58,7 +60,9 @@ performs bounded shutdown. The collector asserts the protobuf content type, endpoint path, configured header, instrumentation scope, span name, `service.name`, and `service.version` from the received request body. Separate tests cover no-op behavior and environment precedence/fallbacks. This receipt -requires no external network. +requires no external network. The no-endpoint receipt also inspects the global +propagator fields, while `otel-zig` exercises real traceparent, tracestate, and +W3C baggage injection/extraction with upstream's strict invalid-header behavior. `internal/tracing_integration_test.zig` then drives the production archive in both asynchronous and synchronous modes. A real OTLP collector requires the @@ -75,9 +79,8 @@ recorded failure event. The provider is not the entire tracing contract. A full-network experiment remains blocked until Stream also has: -1. global W3C TraceContext plus Baggage propagation; -2. the upstream export retry policy and `OTEL_BSP_EXPORT_TIMEOUT` behavior; and -3. custom CA and client certificate/key handling for the corresponding OTLP +1. the upstream export retry policy and `OTEL_BSP_EXPORT_TIMEOUT` behavior; and +2. custom CA and client certificate/key handling for the corresponding OTLP environment variables. These are implementation requirements, not placeholder routes or synthetic diff --git a/src/internal/observability.zig b/src/internal/observability.zig index 43ae53e..b30c8cf 100644 --- a/src/internal/observability.zig +++ b/src/internal/observability.zig @@ -147,6 +147,8 @@ pub const Runtime = struct { pub fn init(allocator: std.mem.Allocator, config: InitConfig) !Runtime { var parsed = try Parsed.init(allocator, config.environment); + try otel_api.setGlobalTextMapPropagator(otel_api.context.createW3cBaggagePropagator()); + errdefer otel_api.setGlobalTextMapPropagator(null) catch {}; if (parsed.endpoint == null) { // The registry's built-in provider is a real no-op tracer provider. @@ -206,6 +208,7 @@ pub const Runtime = struct { self.shutdown_called = true; const result = if (self.provider) |provider| provider.shutdown(timeout_ms) else otel_api.common.ProcessResult.success; otel_api.provider_registry.setGlobalTracerProvider(null) catch {}; + otel_api.setGlobalTextMapPropagator(null) catch {}; return result; } @@ -629,6 +632,9 @@ test "no endpoint installs a callable no-op tracer and shuts down promptly" { }); defer runtime.deinit(); try std.testing.expect(!runtime.enabled()); + const propagation_fields = try otel_api.getGlobalTextMapPropagator().fields(std.testing.allocator); + defer std.testing.allocator.free(propagation_fields); + try std.testing.expectEqualSlices([]const u8, &.{ "traceparent", "tracestate", "baggage" }, propagation_fields); var span_tracer = try tracer("test"); var span = try span_tracer.startSpan("noop-span", .{}, &.{}); span.end(null); -- knotmirror 0.0.1