Skip to content

feat(tracing): span the serve, pull, DHT and settlement paths - #2058

Merged
thiras merged 3 commits into
mainfrom
feat/trace-spans
Sep 19, 2026
Merged

thiras merged 3 commits into
mainfrom
feat/trace-spans

Conversation

@thiras

@thiras thiras commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Second of three observability PRs; #2057 is merged.

Why

The node exported exactly one span, so no request path produced a trace. The OpenTelemetry layer exports events only inside a span, so every event on the serve, pull and payment paths was also dropped. And because the reloadable log filter sat on the whole registry, log_level = "warn" silently stopped all span export.

What changes

  • Trace export no longer follows the log level. The EnvFilter is a per-layer filter on the fmt layer; the OTel layer has its own fixed allow-list (deCDN crates at INFO), which also keeps OTLP-transport and iroh per-packet spans out. Tested: an info span exports while the fmt filter is at warn, and the reload handle still swaps the level as a per-layer filter.
  • Spans (one per stream / pull / lookup / tx, never per frame):
    • serve_stream for each inbound stream. serve_stream and its helpers now return a typed ServeEnd (Completed{bytes} / Refused(reason) / Stopped{stop, bytes} / Reset), so the compiler forces every exit to name its outcome; the dispatch loop records outcome/reason/bytes once (tracing-opentelemetry keeps duplicate attributes if a field is recorded twice). Stream errors are logged inside the span so they reach the collector.
    • miss path: pull_through → origin_pull → node_pull → upstream_stream → open_progressive_pull; the pull thread carries its caller's span across spawn_blocking + its own runtime.
    • dht_lookup (RPC tasks in_current_span), redeem_cycle, onchain_tx (tx hash + outcome; halved retries nest).
  • Cross-node correlation without wire changes. Both ends record hash, pool_id, byte_offset, peer, local_node_id in identical renderings, so one TraceQL query finds both sides. A traceparent field was considered and kept out: the request already carries the join keys, and a remote parent would let a peer set this node's sampling decision.
  • Resource: adds service.version. service.instance.id is left alone — live Tempo shows the host Alloy already sets it (bcl / fra1 / lon1) and rewrites service.name to decdn-node.
  • Docs/monitoring: appendix-observability gains Trace Spans + log field conventions; node dashboard gains a deCDN operation latency panel (TraceQL quantile_over_time by span name); Tempo panel descriptions no longer claim deCDN has no spans.

Not included: a per-tick span for the chain watchers (a debug span never exports; an info span per watcher per tick would flood the collector).

Test plan

  • cargo nextest run -p decdn-node -p decdn-client-pull -p decdn-cache -p decdn-cli — 2579 passed (includes the monitoring/ADR metric-name gates)
  • New tests: serve_stream span exports join keys + outcome in the exact renderings the requester side uses; stopped/refused reasons; export filter (deCDN info in, deps and debug out); log level does not filter export; resource attributes; per-layer reload swap
  • clippy -D warnings --all-targets, doc, fmt via pre-commit
  • Manual, after deploy: {resource.service.name="decdn-node" && name="serve_stream"} in Tempo shows both sides of a miss pull, joinable on hash + peer/local_node_id

🤖 Generated with Claude Code

Copilot AI lite review requested due to automatic review settings September 19, 2026 02:13
@thiras thiras self-assigned this Sep 19, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Fix the dashboard query to include all documented spans and distinguish operation names in the legend.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds end-to-end OpenTelemetry tracing for serving, pull-through, DHT, and settlement paths, with updated filtering, resource metadata, documentation, and dashboards.

Changes:

  • Adds structured spans and typed serve outcomes.
  • Separates OTLP export filtering from log-level filtering.
  • Adds correlation fields, tests, documentation, and latency visualization.
File Reviewed change
monitoring/​grafana-dashboard.json Updates span-rate descriptions.
monitoring/​dashboard-node.json Adds latency visualization; query and legend need correction.
crates/​node/​src/​payment_settlement.rs Instruments settlement cycles and transactions.
crates/​node/​src/​node_origin/​mod.rs Instruments node pulls and upstream streams.
crates/​node/​src/​handlers/​client/​wire.rs Adds typed refusal outcomes.
crates/​node/​src/​handlers/​client/​window.rs Propagates typed serve outcomes.
crates/​node/​src/​handlers/​client/​serve_leg.rs Records serve outcomes.
crates/​node/​src/​handlers/​client/​outcome.rs Defines serve outcomes and tests.
crates/​node/​src/​handlers/​client/​mod.rs Adds fill outcome rendering.
crates/​node/​src/​handlers/​client/​fill.rs Instruments pull-through fills.
crates/​node/​src/​handlers/​client/​dispatch.rs Adds inbound stream spans.
crates/​node/​src/​handlers/​client/​delivery.rs Propagates delivery outcomes.
crates/​node/​src/​dht/​lookup.rs Instruments DHT lookups and RPC tasks.
crates/​node/​src/​commands/​otlp.rs Adds OTLP filtering and resource metadata.
crates/​node/​src/​commands/​mod.rs Makes log filtering per-layer and reloadable.
crates/​client-pull/​src/​lib.rs Instruments progressive pull handshakes.
crates/​cache/​src/​engine.rs Instruments origin and ranged pulls.
CHANGELOG.md Documents tracing additions.
adr/​appendix-observability.md Documents span and field conventions.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread monitoring/dashboard-node.json Resolved
@thiras
thiras force-pushed the feat/trace-spans branch 2 times, most recently from f3b4791 to a981dd0 Compare September 19, 2026 03:02
Base automatically changed from feat/logging-hygiene to main September 19, 2026 03:10
The node exported one span in total, so no request path produced a
trace, and the OpenTelemetry layer — which exports events only inside a
span — dropped every event on those paths. The log filter also sat on
the whole registry, so `log_level = "warn"` silently stopped all export.

- Trace export is independent of the log level. The reloadable
  `EnvFilter` filters the fmt layer only; the OpenTelemetry layer gets a
  fixed allow-list of deCDN crates at `INFO`, which also keeps the OTLP
  transport's own spans and iroh's per-packet spans out. The OTLP
  resource carries `service.version`; the sampler is an explicit
  `ParentBased(AlwaysOn)`.
- `serve_stream` wraps each inbound client stream. Every exit of
  `serve_stream` returns a typed `ServeEnd` (completed / refused /
  stopped / reset), so the compiler proves each path names its outcome;
  the dispatch loop records it once, with `reason` and `bytes`. Stream
  errors are logged inside the span so they reach the collector.
- A miss nests `pull_through` → `origin_pull` → `node_pull` →
  `upstream_stream` → `open_progressive_pull`. The pull thread carries
  its caller's span across `spawn_blocking` and its own runtime.
- `dht_lookup` (its RPC tasks run in its span), `redeem_cycle` and
  `onchain_tx` (tx hash + outcome; a halved retry nests).
- Both ends of a transfer record `hash`, `pool_id`, `byte_offset`,
  `peer` and `local_node_id` in identical renderings, so one TraceQL
  query finds both sides. No trace context crosses the wire: a remote
  parent would let a peer set this node's sampling decision.
- appendix-observability gains a Trace Spans section and the log field
  conventions; the node dashboard gains a deCDN operation latency
  panel, and the Tempo panel descriptions stop saying deCDN has no
  spans.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…them

The operation latency panel left out origin_range_pull and redeem_cycle,
and its legend (copied from the probe panel) printed only the quantile,
so the per-span series were indistinguishable. Review on #2058.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 83.02% (was 82.97%, ▲ +0.05%) — 80719/97230 lines

File Coverage Lines Δ
crates/cache/src/engine.rs 93.04% 4929/5298 ▲ +0.02%
crates/client-pull/src/lib.rs 89.49% 1737/1941 ▲ +0.05%
crates/node/src/commands/mod.rs 40.85% 58/142 ▲ +24.18%
crates/node/src/commands/otlp.rs 87.37% 256/293 ▲ +1.72%
crates/node/src/dht/lookup.rs 96.33% 420/436 ▲ +0.22%
crates/node/src/handlers/client/delivery.rs 92.13% 328/356 ▼ 0.60%
crates/node/src/handlers/client/dispatch.rs 80.98% 511/631 ▲ +0.21%
crates/node/src/handlers/client/fill.rs 73.38% 113/154 ▲ +4.67%
crates/node/src/handlers/client/mod.rs 94.84% 2002/2111 ▼ 0.13%
crates/node/src/handlers/client/outcome.rs 94.57% 122/129 new
crates/node/src/handlers/client/serve_leg.rs 72.31% 141/195 ▼ 2.69%
crates/node/src/handlers/client/window.rs 70.24% 295/420 ▲ +0.29%
crates/node/src/handlers/client/wire.rs 91.71% 387/422 ● 0.00%
crates/node/src/node_origin/mod.rs 92.28% 1124/1218 ▲ +0.28%
crates/node/src/payment_settlement.rs 64.26% 998/1553 ▲ +1.02%
History
Commit Total Δ vs base
19dbf69 83.00% ▲ +0.03%
871160d (HEAD) 83.02% ▲ +0.05%

Multi-agent review of #2058:

- Bare names in `#[instrument(fields(...))]` expand to `Empty`, not to
  the argument, so `open_progressive_pull`'s `byte_offset`/`byte_len` —
  the cross-node join key — `origin_range_pull`'s range, `origin_pull`'s
  `local_only` and `onchain_tx`'s `depth` were never exported. Each now
  names its value.
- The streaming serve-miss pull runs on its own thread and runtime with
  no span, so its `open_progressive_pull` started orphan traces. A
  `serve_miss_pull` child span is entered on that thread.
- Failed origin walks, ranged pulls and upstream opens exported as
  successes: their `err(level = "debug")` event was dropped by the
  export filter, so nothing set the status. Each records `outcome`,
  `error` and an error status once; a clean origin miss stays
  `not_found` with no error status.
- The export filter admits WARN/ERROR events from every crate (the
  OTLP transport stays off), so a dependency failure lands on the
  deCDN span it happened in.
- `serve_stream` records `error` text on a failed stream, `panicked`
  (then resumes the unwind so the JoinSet still meters it), and
  `cancelled` when the task is dropped before the stream ends.
- `ServeEnd::Reset` names its cause (`stream_cap_full` / `bad_binding`),
  and refusal reasons record in snake case like every other value.
- Tests: the stack `init_tracing` installs is one `subscriber` fn the
  tests use; a span-capture layer asserts the real serve path records
  `completed` / `refused cache_miss` with the miss chain under it, and
  that a node-to-node pull nests `node_pull ⊃ upstream_stream ⊃
  open_progressive_pull` across its thread with the range fields set.
- Docs: nesting for both miss paths, outcome values, the iroh probe
  panel removed (the export filter drops iroh spans), dashboard and ADR
  wording.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@thiras
thiras merged commit 7da144d into main Sep 19, 2026
25 checks passed
@thiras
thiras deleted the feat/trace-spans branch September 19, 2026 03:50
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