Skip to content

Thread RoutingMetadata trait through user tracing; move routing heade…#1

Draft
mar-cf wants to merge 8 commits into
user-tracing-7from
user-tracing-7-wip
Draft

Thread RoutingMetadata trait through user tracing; move routing heade…#1
mar-cf wants to merge 8 commits into
user-tracing-7from
user-tracing-7-wip

Conversation

@mar-cf

@mar-cf mar-cf commented Jul 7, 2026

Copy link
Copy Markdown
Owner

// RoutingMetadata is a trait — you define the concrete routing type. group_key batches
// spans that share it into one request; encode produces the routing header's value.
#[derive(Debug)]
struct MyRouting { zone_id: u64, account_id: u64 }

impl RoutingMetadata for MyRouting {
fn group_key(&self) -> String { format!("{}|{}", self.zone_id, self.account_id) }
fn encode(&self) -> String { format!("zone={};account={}", self.zone_id, self.account_id) }
}

// Per request: open the root. routing is required and fixed at construction (inherited by all
// descendants); inbound continues an upstream W3C trace, or None for a fresh one.
let _root = tracing::start_user_trace(
"example_span_name",
MyRouting { zone_id, account_id },
inbound, // Option
);

mar-cf added 8 commits June 24, 2026 15:56
Replace the blanket `impl From<Span> for SharedSpan` — which always registered the span in the harness's `active_roots` — with an explicit `shared_span()` constructor, and migrate the internal call sites. This makes tracked construction a deliberate choice and sets up a later untracked variant for user spans.
Adds the user-span pipeline core: an `Untracked` `user_shared_span` constructor, the `start_user_trace`/`user_span` entry points and `UserSpanScope` guard on a separate `USER_HARNESS` (with a `USER_NOOP_HARNESS` fallback), plus the `add_user_span_tags!`/`add_user_span_log_fields!`/`set_user_span_finish_callback!` macros. Includes the test harness (`user_traces()` second sink) so user spans are observed independently of the internal pipeline. `start_user_trace` is name-only here; routing and inbound W3C continuation are layered on in later changes.
Adds a `user_span` slot to `TelemetryContext` (captured by `current()`, re-established by `scope()`, cloned across forks) plus `UserSpanScope::into_context()` and a parallel carry on `SpanScope::into_context()`. This lets a user span survive `.await`/`tokio::spawn` and ride along even when propagation goes through an internal span's context — no explicit threading. Verified by `propagates_across_await` and `user_span_carried_by_internal_context`.
Adds `SpanScope::with_user_span()` to open a parallel user span off an internal span (named after it), and a `user = true` option on `#[span_fn]` that does the same for whole functions (sync and async). Both are no-ops when no user trace is active. Covered by macro snapshot tests plus parallel and no-op runtime tests.
Points `cf-rustracing` at the fork branch that adds `RoutingMetadata` as a span property, needed by the user-tracing exporter and `start_user_trace` routing. Placeholder to be replaced by a normal version bump once the rustracing change is released.
Adds the per-process user pipeline — `UserTracingSettings`, `init_user`/`USER_HARNESS`, and the OTLP-over-UDS exporter that encodes `RoutingMetadata` into the `cf-trace-config` header — wired into `telemetry::init`. `start_user_trace` now takes a required `RoutingMetadata` attached at span construction and inherited by descendants (the exporter drops routing-less spans). Verified end-to-end by producer tests that decode the exported OTLP body.
Adds the `TraceparentContext` W3C parser and wires it through: `start_user_trace` gains an optional `inbound` traceparent that stitches the user root onto the upstream trace (shared trace id, inbound parent), and `user_tracing::w3c_traceparent()` derives the header for the current user span for outbound propagation. Covered by parser unit tests plus continuation tests through the test harness and the OTLP/UDS producer path.
@mar-cf mar-cf force-pushed the user-tracing-7 branch 3 times, most recently from d517d59 to faae636 Compare July 16, 2026 03:09
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