Skip to content

feat(ingester): continue the caller's trace across the ingest spawn (RFC 0039 slice 2) - #628

Merged
jensholdgaard merged 2 commits into
mainfrom
rfc0039-slice2-ingest-propagation
Jul 25, 2026
Merged

feat(ingester): continue the caller's trace across the ingest spawn (RFC 0039 slice 2)#628
jensholdgaard merged 2 commits into
mainfrom
rfc0039-slice2-ingest-propagation

Conversation

@jensholdgaard

@jensholdgaard jensholdgaard commented Jul 25, 2026

Copy link
Copy Markdown
Owner

What

RFC 0039 slice 2 — RFC0039.3: the caller's trace context survives the ingest tokio::spawn, on both OTLP transports.

Slice 1 (#627) gave the query span a parent. Both OTLP receivers still rooted their own traces: the ingest logs span is created inside ingest_bound, past a tokio::spawn, and ambient context does not cross that boundary. Each handler now extracts the caller's context from its own carrier before the spawn and attaches it to the whole spawned block:

tokio::spawn(
    async move { pipeline.ingest_bound(export, binding.as_ref(), false).await }
        .with_context(parent),
)

Wrapping the block rather than ingest_bound's future is deliberate — it holds whether #[tracing::instrument] mints its span at call time or on first poll, so the span cannot be created outside parent.

The RFC amendment (§3.3 / §3.4)

§3.3 originally routed gRPC extraction through the tower auth layer into a request extension. Withdrawn during implementation, for two reasons:

  1. It contradicted §6. The RFC0039.3 test drives LogsReceiver::export directly, with no tower stack — so a layer-extracted context would have left the extraction itself uncovered, testing only the spawn hand-off.
  2. It put a propagation concern inside a layer named for authentication.

Consulted the OTel knowledge base before choosing: OTel prescribes that a service receiving upstream calls extracts in the receiving handler ("the one context on the wire becomes the parent of the new span the library creates"), and the OTel Demo's own C++ gRPC service does exactly this with a GrpcServerCarrier over client_metadata(). The Go otelgrpc-interceptor pattern looks like the alternative but doesn't transfer — it extracts and creates the span in one place, which we cannot do across the spawn.

Cost of the correction is the ~15-line MetadataExtractor that §3.4 had hoped to avoid. Both sections are amended in place, with the rationale recorded as an amendment note; §7's first open question is now resolved.

Invariants (CLAUDE.md §3)

No invariant is touched. No new signal, no schema change, no on-disk change — this only sets the parent of spans that already exist. Both extractors are infallible by construction: absent, malformed, or unparsable context yields a context with no remote span, so the span roots itself exactly as before (RFC0039.2 / RFC0039.5). No unwrap/expect in non-test code (§6.1).

Tests

  • rfc0039_3_ingest_propagation.rs (new binary) — both arms assert the batch span joins the caller's trace, is parented to the caller's span, and that commit wal still nests under it inside that trace.
    • Red verified: with the two handler changes stashed, both arms' spans land in freshly minted traces (d1c539…, 11aa7e…) and the assertion fails at 0 spans in the caller's trace.
    • Its own binary per RFC0028.2 (needs the process-global tracer) — rfc0038_3_spawn_boundary.rs owns the no-inbound-context case and is left untouched, so both cases stay covered.
  • Two new unit tests: the gRPC carrier reaches the same SpanContext as the HTTP one; binary (-bin) metadata keys are withheld from keys().

Verification

  • cargo fmt --all --check
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo nextest run --all-features ✅ 1248 passed, 38 skipped
  • mdbook build

Remaining in RFC 0039

Slice 3 (RFC0039.6, MCP tool spans) and slice 4 (RFC0039.4, the sampling assertion).

Summary by CodeRabbit

  • New Features

    • Inbound trace context is now preserved across both OTLP/HTTP and OTLP/gRPC ingestion.
    • Ingest and commit operations remain connected to the caller’s existing W3C trace, improving end-to-end observability.
    • gRPC metadata and HTTP headers are supported for trace-context extraction.
  • Documentation

    • Updated trace-propagation guidance to describe supported transports and behavior.
  • Tests

    • Added coverage validating trace continuity across both ingestion paths.

…RFC 0039 slice 2)

Both OTLP receivers create their `ingest logs` span inside `ingest_bound`,
past a `tokio::spawn` that ambient context does not cross, so the caller's
`traceparent` never reached it. Each handler now extracts the context from
its own carrier before the spawn and attaches it to the whole spawned
block, so the span is minted under it (RFC0039.3).

The gRPC arm extracts from tonic metadata in `export` rather than from the
tower auth layer as RFC 0039 §3.3 first proposed. That design contradicted
§6 -- whose test drives `export` directly, with no tower stack, and so
would never have exercised the extraction -- and put propagation inside a
layer named for authentication. OTel prescribes extracting in the handler
that receives the call, as the OTel Demo's own C++ gRPC service does with a
carrier over `client_metadata()`. Cost is the `MetadataExtractor` that §3.4
had hoped to avoid; both RFC sections are amended in place.

The new test is its own binary because it needs the process-global tracer
(RFC0028.2) and `rfc0038_3_spawn_boundary.rs` owns the no-inbound-context
case; leaving that file untouched keeps both cases covered. It fails with
each arm's span in a freshly minted trace when the two handler changes are
reverted.

Signed-off-by: Jens Holdgaard Pedersen <Jens@holdgaard.org>
@jensholdgaard
jensholdgaard requested a review from Copilot July 25, 2026 00:45
@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@jensholdgaard, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 52 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 89ca8b86-3b39-4af2-8bfc-75afd7b1ef9d

📥 Commits

Reviewing files that changed from the base of the PR and between b19c141 and 9858adc.

📒 Files selected for processing (2)
  • crates/ourios-ingester/src/receiver/propagation.rs
  • docs/rfcs/0039-inbound-trace-context-propagation.md
📝 Walkthrough

Walkthrough

Inbound trace context propagation now supports HTTP headers and gRPC metadata. Both receivers extract the caller context before tokio::spawn and reattach it to ingest work. Unit and integration tests verify span parentage across both transports, with corresponding RFC and harness documentation updates.

Changes

Inbound trace context propagation

Layer / File(s) Summary
Carrier adapters and exports
crates/ourios-ingester/src/receiver/propagation.rs, crates/ourios-ingester/src/receiver.rs
Adds MetadataExtractor and extract_context_from_metadata for tonic metadata, filters binary keys, tests metadata extraction, and re-exports the new APIs.
Receiver spawn context wiring
crates/ourios-ingester/src/receiver/grpc.rs, crates/ourios-ingester/src/receiver/http.rs
Extracts inbound context from gRPC metadata or HTTP headers and applies with_context to spawned ingest tasks.
Integration validation and design record
crates/ourios-ingester/tests/rfc0039_3_ingest_propagation.rs, crates/ourios-ingester/tests/README.md, docs/rfcs/0039-inbound-trace-context-propagation.md
Verifies span parentage across gRPC and HTTP ingestion and documents the carrier and spawn-boundary behavior.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant Receiver
  participant SpawnedIngest
  participant SpanExporter
  Caller->>Receiver: Sends traceparent via HTTP headers or gRPC metadata
  Receiver->>Receiver: Extracts caller context
  Receiver->>SpawnedIngest: Spawns ingest task with attached context
  SpawnedIngest->>SpanExporter: Records ingest logs and commit wal spans
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the main change: preserving caller trace context across the ingest spawn for RFC 0039 slice 2.
Description check ✅ Passed It includes the summary, RFC rationale, tests, and verification, so it is mostly complete despite using nonstandard headings.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch rfc0039-slice2-ingest-propagation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/rfcs/0039-inbound-trace-context-propagation.md`:
- Line 73: Update the stale source-location references in
docs/rfcs/0039-inbound-trace-context-propagation.md: line 73 should reference
the gRPC LogsReceiver::export entrypoint at grpc.rs:155 instead of grpc.rs:152,
and lines 106-114 should reference spawn locations grpc.rs:176 and http.rs:153
instead of grpc.rs:167 and http.rs:146.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fc189052-a328-4ddd-b540-9c411e828cb0

📥 Commits

Reviewing files that changed from the base of the PR and between 8b4edd7 and b19c141.

📒 Files selected for processing (7)
  • crates/ourios-ingester/src/receiver.rs
  • crates/ourios-ingester/src/receiver/grpc.rs
  • crates/ourios-ingester/src/receiver/http.rs
  • crates/ourios-ingester/src/receiver/propagation.rs
  • crates/ourios-ingester/tests/README.md
  • crates/ourios-ingester/tests/rfc0039_3_ingest_propagation.rs
  • docs/rfcs/0039-inbound-trace-context-propagation.md

Comment thread docs/rfcs/0039-inbound-trace-context-propagation.md Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Implements RFC 0039 slice 2 by preserving inbound W3C trace context across the OTLP ingest tokio::spawn boundary, so spans created inside ingest_bound join the caller’s trace for both OTLP transports (gRPC + HTTP). This extends the inbound trace propagation work from the query path to the ingest path in ourios-ingester.

Changes:

  • Extract inbound trace context before spawning the ingest task and re-attach it to the spawned future via FutureExt::with_context (OTLP/HTTP and OTLP/gRPC).
  • Add a tonic MetadataMap carrier (MetadataExtractor) alongside the existing HeaderExtractor.
  • Add an integration test binary asserting the ingest batch span (and commit wal) are parented to the caller across the spawn boundary; document the new harness-exempt test.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
docs/rfcs/0039-inbound-trace-context-propagation.md Updates RFC 0039 text to reflect gRPC extraction from tonic metadata and spawn-boundary parenting approach.
crates/ourios-ingester/src/receiver/propagation.rs Adds MetadataExtractor + extract_context_from_metadata and unit tests for tonic metadata carrier behavior.
crates/ourios-ingester/src/receiver/http.rs Extracts caller context from HTTP headers and attaches it to the spawned ingest task.
crates/ourios-ingester/src/receiver/grpc.rs Extracts caller context from gRPC metadata and attaches it to the spawned ingest task.
crates/ourios-ingester/src/receiver.rs Re-exports the new metadata propagation helpers alongside the existing header-based ones.
crates/ourios-ingester/tests/rfc0039_3_ingest_propagation.rs New harness-exempt integration test verifying cross-spawn trace parenting for both transports.
crates/ourios-ingester/tests/README.md Documents the new harness-exempt test binary and why it must be separate.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/rfcs/0039-inbound-trace-context-propagation.md Outdated
Comment thread crates/ourios-ingester/src/receiver/propagation.rs
Review follow-ups on #628:

- CodeRabbit flagged three stale file:line references. Rather than correct
  the numbers a second time, §3.2's site table and §3.3 now name file +
  function only -- line numbers rot on every touch of surrounding code.
- Copilot: §3.3's first bullet still described a tower PropagationLayer for
  the query and HTTP-ingest arms, which neither uses. Rewritten to the
  implemented per-handler extraction, pointing at §4 for why no layer.
- Copilot: assert the gRPC carrier treats a malformed traceparent as absent
  (RFC0039.5, gRPC arm). The two carriers reach the propagator through
  different Extractor impls, so this was genuinely uncovered.

Signed-off-by: Jens Holdgaard Pedersen <Jens@holdgaard.org>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

@jensholdgaard
jensholdgaard merged commit e5b9e6e into main Jul 25, 2026
27 checks passed
@jensholdgaard
jensholdgaard deleted the rfc0039-slice2-ingest-propagation branch July 25, 2026 01:00
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