Repository navigation
feat(server): the trace-context hop — jobs.trace_context carries the click (telemetry P3) - #384
Merged
Merged
Conversation
…click (telemetry P3) `jobs.trace_context` and `task_instances.trace_context` have existed since the orchestration work, are threaded through ~20 statements, and already propagate job -> task_instance (taskpg.rs:92). Every writer passed `None`, so the column infrastructure.md §10.2 calls "the highest-value single decision in this section" has been built and empty. This fills it. Shippable before any OTel SDK exists anywhere, which is why it goes first: the column is a string and the header is a string. Once a subscriber lands, the dispatcher starts the run's span as a child of this context and one trace spans the click, the API call, the queue wait, the dispatch and every stage. Without it you get two unrelated traces and a run_id to join by hand. - `forwarded_traceparent` / `acceptable_traceparent` mirror the `forwarded_actor` / `acceptable_actor` pair beside them, including the split so the rule is testable without a header. W3C level-1 only: an all-zero trace or span id is refused (the spec calls both invalid), version `ff` is refused (the spec forbids it), uppercase hex is refused so one context cannot arrive as two distinct strings, and a future version is refused rather than stored half-understood. A malformed value is ignored, not refused — a bad telemetry header should not fail an otherwise valid enqueue. - The context rides on `Principal`, which is already the one thing extracted from headers on every authenticated request, so all 11 enqueue sites get it in scope with no new plumbing. - `pg::Provenance` bundles `created_by` with `trace_context`. Not cosmetic: widening `pg::enqueue` to 8 arguments trips clippy's `too_many_arguments`, and an `allow` would have been the wrong answer — the two are the same fact from two angles (durable attribution a human reads, correlation handle a tool follows) and always travel off the same request. The call sites shrank. - The in-memory store matches the Postgres path, which is what makes the hop testable end to end without a database: POST with a `traceparent` and the job row carries it; no header and it stays null; malformed and it stays null with the request still accepted. - A user-initiated import links to the run it causes (`finish_delivery` carries the context), while the S3 poll tick, the cron tick, the dispatcher's own drain and the `migrate-tenants` sweep pass no context — none of them has a caller to inherit from, and claiming a parent they do not have would be worse than rooting their own trace. Trace ids are correlation only and never an authorization input, so the spoofability `x-acting-user` already documents is tolerable here for the same reason; the doc comments say so at both sites. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This was referenced Nov 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First PR of the telemetry program (plan: 24 PRs, three waves). This one is Wave 1 — measurement substrate, no new dependencies, nothing observable changes yet.
Why this goes first
jobs.trace_context/task_instances.trace_contexthave existed since the orchestration work, are threaded through ~20 statements, and already propagate job → task_instance (taskpg.rs:92). Every writer passedNone. So the columninfrastructure.md§10.2 calls "the highest-value single decision in this section" has been built and empty.It ships before any OTel SDK exists anywhere, which is the point: the column is a string and the header is a string. Once a subscriber lands, the dispatcher starts the run's span as a child of this context and one trace spans the click → API call → queue wait → dispatch → every stage. Without it you get two unrelated traces and a
run_idto join by hand.What's here
The extractor mirrors the
forwarded_actor/acceptable_actorpair beside it, including the split that makes the rule testable without a header. W3C level-1 only:ff01+A malformed value is ignored, not refused — a bad telemetry header should not fail an otherwise valid enqueue. Same reasoning
forwarded_actoralready documents.It rides on
Principal, already the one thing extracted from headers on every authenticated request, so all 11 enqueue sites get it in scope with no new plumbing.pg::Provenancebundlescreated_bywithtrace_context. Not cosmetic — wideningpg::enqueueto 8 arguments trips clippy'stoo_many_arguments, and anallowwould have been the wrong answer. The two are the same fact from two angles (durable attribution a human reads; correlation handle a tool follows) and always travel off the same request. The call sites got shorter.Deliberately no context: the S3 poll tick, the cron tick, the dispatcher's own drain, and the
migrate-tenantssweep. None has a caller to inherit from, and claiming a parent they don't have is worse than rooting their own trace. A user-initiated import does link to the run it causes.Testing
The in-memory store now matches the Postgres path, which is what makes the hop testable end to end without a database:
http::an_enqueued_job_carries_the_requests_trace_context— header → stored; no header → null; malformed → null, request still202.tests::a_well_formed_traceparent_is_stored_verbatim,tests::a_malformed_traceparent_is_ignored_rather_than_stored— the validator against 10 malformed shapes.make checkgreen, includingentities-check(119 generated files current, every statement plans, 16 rules over 42 entities). No DDL change — the columns already exist, so the reconciler has nothing to do.Note on trace ids and auth
A trace id is correlation only and never an authorization input, so the spoofability
x-acting-useralready documents is tolerable here for the same reason. What a forged value can do is attach a run to someone else's trace, so durable attribution stayscreated_by/audit_log. The doc comments say this at both sites.🤖 Generated with Claude Code