Skip to content

feat(obs): the job span becomes a child of the request that enqueued it (telemetry P9) - #481

Merged
athvin merged 1 commit into
mainfrom
bm/telemetry-p9-job-parent
Nov 5, 2026
Merged

athvin merged 1 commit into
mainfrom
bm/telemetry-p9-job-parent

Conversation

@athvin

@athvin athvin commented Nov 5, 2026

Copy link
Copy Markdown
Owner

dispatcher.rs has carried this as a TODO since P3, and it named its own precondition:

// The §10.2 hop, half-closed: the enqueue side writes this ... Making this
// span a true CHILD of that context needs the OTel context propagator, which
// arrives with the exporter — at which point this field becomes `set_parent`.
er.trace_context = job.trace_context.as_deref().unwrap_or(""),

The exporter arrived in #429, so it does.

jobs.trace_context has held the traceparent of the enqueueing request all along, and the dispatcher recorded it as a span field. A field joins two traces by log search; it does not make them one trace. Now the context is adopted as the job span's parent, so a click, the HTTP request it caused, the job, its run, its eleven stages and every statement they execute are one trace — which is the thing this whole programme is for.

The field stays: CloudWatch Logs has no span tree to walk, so it remains how the two sides join there.

Where it lives, and why

er-obs, not er-server. The propagator needs opentelemetry_sdk and tracing-opentelemetry, and the control plane has neither — so this keeps the OTel surface in the one crate that owns it and gives the dispatcher a one-line call instead of two dependencies.

Best effort, silently

A job the scheduler enqueued has no request behind it and stays a root, which is correct and not worth a log line on every claim. A context that will not parse also leaves it a root — exactly the behaviour before this existed — and acceptable_traceparent has already refused malformed values on the way in.

A job must never fail because its telemetry lineage could not be established.

The test is a pair, and the control is the point

adopts_parent_context.rs asserts the exported trace_id equals the incoming one, as its sixteen raw bytes, because that is how OTLP encodes it. Asserting on a hex string would pass while the field held something else entirely — a mistake this crate's tests already made once against otel.status_code.

The second test exports without adopting and asserts the trace id is absent. Without it the positive test could pass because those bytes appeared somewhere incidental, and a test that cannot fail for the right reason is not evidence.

Verified by breaking adopt_traceparent: the positive test fails with its own message, the control keeps passing.

What remains of P9

Two pieces, deliberately not here:

  • The traceparent reaching the pod in the work order (er-dag's WorkOrder → exec_task), so a runner Job's spans join the same trace rather than starting fresh. The row is the right carrier — it survives a relaunch, and an ${ER_…} env var would trip render_job's unsubstituted-placeholder refusal.
  • The backdated queue.wait span, which needs the OTel tracer directly (with_start_time/with_end_time) because tracing has no API for a span that already happened. That gap between enqueue and claim is where per-tenant serialization shows up, and it is invisible today.

make check passes.

🤖 Generated with Claude Code

…it (P9)

`dispatcher.rs` has carried this as a TODO since P3, and it named its own
precondition:

    // The §10.2 hop, half-closed: the enqueue side writes this ... Making this
    // span a true CHILD of that context needs the OTel context propagator,
    // which arrives with the exporter — at which point this field becomes
    // `set_parent`.

The exporter arrived in #429, so it does.

`jobs.trace_context` has held the traceparent of the enqueueing request all
along, and the dispatcher recorded it as a span FIELD. A field joins two traces
by log search; it does not make them one trace. Now the context is adopted as
the job span's parent, so a click, the HTTP request it caused, the job, its run,
its eleven stages and every statement they execute are ONE trace — which is the
thing this whole programme is for.

The field stays. CloudWatch Logs has no span tree to walk, so it remains how
the two sides join there.

## Where it lives

`er-obs`, not `er-server`. The propagator needs `opentelemetry_sdk` and
`tracing-opentelemetry` and the control plane has neither, so this keeps the
OTel surface in the one crate that owns it and gives the dispatcher a one-line
call instead of two dependencies.

## Best effort, silently

A job the scheduler enqueued has no request behind it and stays a root, which
is correct and not worth a log line on every claim. A context that will not
parse also leaves it a root — exactly the behaviour before this existed — and
`acceptable_traceparent` has already refused malformed values on the way in. A
job must never fail because its telemetry lineage could not be established.

## The test is a PAIR, and the control is the point

`adopts_parent_context.rs` asserts the exported `trace_id` equals the incoming
one, as its sixteen RAW BYTES, because that is how OTLP encodes it — asserting
on a hex string would pass while the field held something else, which is a
mistake this crate's tests already made once against `otel.status_code`.

The second test exports WITHOUT adopting and asserts the trace id is absent.
Without it the positive test could pass because the bytes appeared somewhere
incidental, and a test that cannot fail for the right reason is not evidence.

Verified by breaking `adopt_traceparent`: the positive test fails with its own
message, the control keeps passing.

`make check` passes.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@athvin
athvin force-pushed the bm/telemetry-p9-job-parent branch from 2d5a52d to f06189e Compare November 5, 2026 02:10
@athvin
athvin merged commit ac16741 into main Nov 5, 2026
36 checks passed
@athvin
athvin deleted the bm/telemetry-p9-job-parent branch November 5, 2026 10:53
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.

2 participants