Skip to content

feat(obs): spans leave the process — OTLP over the reqwest we already link (telemetry P6b) - #429

Merged
athvin merged 2 commits into
mainfrom
bm/telemetry-p6b-otlp
Nov 3, 2026
Merged

athvin merged 2 commits into
mainfrom
bm/telemetry-p6b-otlp

Conversation

@athvin

@athvin athvin commented Nov 3, 2026

Copy link
Copy Markdown
Owner

The exporter er-obs was shaped for. init still always installs the structured stderr layer; when an OTLP endpoint is configured it additionally installs a tracing-opentelemetry bridge, so the span tree that already exists in-process starts arriving somewhere it can be queried.

Opt-in by the presence of an endpoint rather than opt-out by a flag, because er-entity and dedupe are build tools and every test binary in the workspace calls init. Option<Layer> is itself a Layer, so with no endpoint the exporter is absent from the subscriber rather than installed-and-disabled.

The deferral reason was real, and did not survive re-measurement

init.rs argued at length that the exporter could not land: opentelemetry-otlp's reqwest-rustls feature resolves a second reqwest and selects aws-lc-rs as rustls' provider, pulling an aws-lc-sys that needs a cmake the build image does not carry.

That was right about the feature it tested and wrong as a verdict on the exporter. Supplying our own HTTP client avoids the client features entirely. Re-measured on this branch with default-features = false + http-proto:

before after
aws-lc-sys / aws-lc-rs 0 0
reqwest versions 1 (0.12.28) 1 (0.12.28)
rustls provider ring ring
new lock entries — 12, no second HTTP or TLS stack

tonic is among the twelve, which the plan hoped to avoid — opentelemetry-proto depends on it unconditionally. But without its transport feature, which is why no new hyper appears. It is a protobuf codec here, not a gRPC stack.

The trap, and why the test sends real bytes

The SDK's batch processor owns a plain std::thread and polls the exporter future on it with a non-tokio executor. An async reqwest::Client needs a reactor, so sending directly from that thread panics:

thread 'OpenTelemetry.Traces.BatchProcessor' panicked:
there is no reactor running, must be called from the context of a Tokio 1.x runtime

That panic does not fail the process. It is on the processor's own thread, so main runs on, force_flush returns an error nobody is obliged to read, and every span is dropped. The failure mode is a telemetry pipeline that looks installed and exports nothing — and it is invisible to a build-only check.

So ReqwestClient hands each request to a single-worker runtime this module owns, which works whether or not the caller has one: the API and dispatcher arms are #[tokio::main], while the er pipeline CLI and the exec-task pod verb deliberately are not.

tests/otlp_export.rs therefore asserts on bytes received by a listener, in both runtime shapes, checking the request line and content-type: application/x-protobuf — a mis-joined endpoint is a silent 404 per batch and a wrong content-type a silent 415.

Gate observed failing before being trusted. Reintroducing the bug gives 1 passed; 2 failed with that exact panic surfaced through the flush assertion.

One guess recorded as wrong rather than quietly dropped: block_on in place of spawn was expected to pass the no-runtime case and panic the in-runtime one. It passes both — the SDK always polls on its own thread, so there is no ambient runtime to conflict with. spawn is kept for having one fewer assumption, and the tests state that they do not discriminate between the two rather than implying a guarantee they do not provide.

Flush

Guard::force_flush gains a body and Drop gains flush-then-shutdown, covering every normally-returning path. exec-task is not one of those — std::process::exit does not run destructors — so main.rs flushes explicitly before exiting. A pod exits immediately after its last span, so the tail of every run, including every failure, depends on it. SIGKILL and OOM remain uncoverable; the terminal message and stdout→Fluent Bit are that path.

Failures degrade to "no telemetry" throughout and are never propagated. Observation must not change a run, and this runs from the first statement of main, where an error is a pod that will not boot for a reason unrelated to its job.

Also

  • provider_for takes the endpoint as a parameter, which is what makes the export testable: the workspace denies unsafe_code and std::env::set_var is unsafe as of edition 2024. The endpoint/duration resolvers are pure functions for the same reason, which also stops them depending on what ran beside them in a shared test binary.
  • er-obs gains tests/main.rs with autotests = false, per the one-test-binary convention.
  • Corrects two now-stale comments: init.rs's deferral rationale and telemetry.rs's "there is no exporter in the build".

make check passes.

🤖 Generated with Claude Code

bmoore813 and others added 2 commits November 2, 2026 22:06
… link

The exporter er-obs was shaped for. `init` still always installs the structured
stderr layer; when an OTLP endpoint is configured it additionally installs a
`tracing-opentelemetry` bridge, so the span tree that already exists in-process
starts arriving somewhere it can be queried.

Opt-in by the presence of an endpoint rather than opt-out by a flag, because
`er-entity` and `dedupe` are build tools and every test binary in the workspace
calls `init`. `Option<Layer>` is itself a `Layer`, so with no endpoint the
exporter is absent from the subscriber rather than installed-and-disabled.

## The deferral reason was real and did not survive re-measurement

init.rs argued the exporter could not land because `opentelemetry-otlp`'s
`reqwest-rustls` feature resolves a second `reqwest` and selects `aws-lc-rs`,
pulling an `aws-lc-sys` that needs a cmake the build image lacks. That was
right about the feature it tested and wrong as a verdict on the exporter:
supplying our own HTTP client avoids the client features entirely.

Re-measured on this branch — zero `aws-lc-sys`, one `reqwest` (0.12.28),
rustls still on `ring`, 12 new lock entries and no second HTTP or TLS stack.
`tonic` is among them because `opentelemetry-proto` depends on it
unconditionally, but without `transport`, which is why no new `hyper` appears.
It is a protobuf codec here, not a gRPC stack.

## The trap, and why the test sends real bytes

The SDK's batch processor owns a plain std::thread and polls the exporter future
on it with a non-tokio executor, so an async `reqwest::Client` panics there with
`there is no reactor running`. That panic does NOT fail the process — it is on
the processor's thread, so `main` runs on and every span is silently dropped.
Observed while building this.

So `ReqwestClient` hands each request to a single-worker runtime this module
owns, which works whether or not the caller has one: the API and dispatcher are
`#[tokio::main]`, the `er` CLI and `exec-task` deliberately are not.
tests/otlp_export.rs asserts on **bytes received by a listener** in both shapes,
because a provider that merely builds proves nothing — the first version built
fine and exported nothing. Verified by reintroducing the bug: the no-runtime
test fails with that exact panic.

One guess recorded as wrong rather than quietly dropped: `block_on` instead of
`spawn` was expected to fail the in-runtime case. It passes both, because the
SDK always polls on its own thread. `spawn` is kept for having one fewer
assumption, and the tests say they do not discriminate the two.

## Flush

`Guard::force_flush` gains a body and `Drop` gains a flush-then-shutdown, so
every normally-returning path is covered. `exec-task` is not one of those:
`std::process::exit` does not run destructors, so main.rs flushes explicitly
before exiting. A pod exits immediately after its last span, and the tail of
every run — including every failure — depends on it.

Failures degrade to "no telemetry" throughout and are never propagated.
Observation must not change a run, and this code runs from the first statement
of `main`, where an error is a pod that will not boot for an unrelated reason.

`make check` passes.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
#418 sets OTEL_SERVICE_NAMESPACE on both the deployments and the task
template. It is not an OTLP SDK variable — the spec carries service.namespace
inside OTEL_RESOURCE_ATTRIBUTES — so the value was shipped to no effect.

Reading it here is cheaper than changing the chart and leaves one spelling
rather than two, and service.namespace is worth having: it is what separates
this product from anything else that ever writes to the one shared store.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@athvin
athvin merged commit 7c4a3f3 into main Nov 3, 2026
34 checks passed
@athvin
athvin deleted the bm/telemetry-p6b-otlp branch November 3, 2026 03:23
athvin added a commit that referenced this pull request Nov 3, 2026
… (P14) (#454)

This is a deduplication engine, so names, emails, phones and addresses ARE the
payload, and §10.4's rule is that telemetry carries identifiers and counts and
never attribute values. #429 made that boundary matter more: spans now leave
the process over OTLP, so it is an exportable store rather than in-account
Postgres.

The real guarantee is structural and already shipped — `er_span::sql_span`
takes no parameter argument, so there is nowhere to put a bind value. These are
the shape gates around it, because that property only holds while the call
stays where it is:

1. only GENERATED code may call `sql_span` (244 sites, all in er-entities);
   product code calls `generator_span`, which has no `sql` parameter at all.
   `er-span` and `er-sql-check/src/emit.rs` are allowlisted with reasons — the
   latter WRITES those calls as string literals rather than making them.
2. every emitted `sql_span` argument is a string literal, `SQL`, or a `Store`
   discriminant, so none can carry a runtime value.
3. the names `er-span` declares `Pii::Never` appear nowhere in code.

Each test also asserts a floor on what it examined (>60 files, >20 generated
callers, >200 statements), so a moved crate tree fails here rather than passing
having looked at nothing — the false-green shape this repo keeps being bitten
by.

The forbidden list is READ OUT of er-span/src/attr.rs rather than restated. A
hardcoded copy is how a registry and its enforcement drift apart, which
er-entity-lint's own header records as how three documented codes ended up
never implemented.

## Two things the gate taught me while being written

Its first version failed on `er-server/src/telemetry.rs` — whose comment says
`url.query` is deliberately NOT recorded. A file explaining the rule was being
reported as breaking it. Writing down why an attribute is forbidden is exactly
the behaviour to encourage, so prose is now exempt and only code counts.

And the comment stripper's limitation runs the UNSAFE way, so it says so: it
does not understand string literals, so a `//` inside one strips the rest of
that line and a forbidden name after it would be MISSED. A false negative, not
a false positive. Accepted because the structural guarantee does not depend on
this scan; if it ever does, this wants to be a real lint.

Both gates observed failing on injected violations before being trusted.
`make check` passes.

Co-authored-by: bmoore813 <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
athvin pushed a commit that referenced this pull request Nov 5, 2026
…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 added a commit that referenced this pull request Nov 5, 2026
…it (P9) (#481)

`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: bmoore813 <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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