Commit 3db9b65
fix(tracing): install W3C TraceContext propagator in OTLP path (#532)
## Summary
The OTLP init path never installed a text-map propagator, so katana
silently dropped inbound `traceparent` headers under that backend —
every request became a fresh root trace even when the caller had a live
trace context. The `gcloud` path installs a
`GoogleTraceContextPropagator`; OTLP was missing the equivalent W3C one.
One-line fix: add
`opentelemetry::global::set_text_map_propagator(TraceContextPropagator::new())`
in `otlp::init_tracer`.
## Why this matters
`crates/rpc/rpc-server/src/middleware/...` wraps incoming HTTP in a
`tower_http::TraceLayer` configured with `GoogleStackDriverMakeSpan`,
which calls `opentelemetry::global::get_text_map_propagator(|p|
p.extract(&HeaderExtractor(req.headers())))`. With no propagator
installed, `get_text_map_propagator` returns a `NoopTextMapPropagator`
and the extract call silently produces an empty context. Result:
`span.set_parent(cx)` is effectively a no-op, and the exported span
starts a new trace instead of chaining to the caller's.
## Repro (before this PR)
```bash
# Start jaeger v2 as an OTLP collector:
jaeger --config file:/tmp/jaeger-config.yaml # OTLP gRPC on :4317, UI on :16686
# Start katana with OTLP:
katana --tracer.otlp --tracer.otlp-endpoint http://localhost:4317 --http.port 5055
# Send a request with a synthetic traceparent:
curl http://localhost:5055 \
-H 'traceparent: 00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01' \
-d '{"jsonrpc":"2.0","method":"starknet_chainId","id":1}'
# Check jaeger — the exported trace has a random trace_id, NOT 0af7651916cd43dd8448eb211c80319c
curl "http://localhost:16686/api/traces?service=katana&limit=1"
```
After this PR, the exported `http_request` span has
`trace_id=0af7651916cd43dd8448eb211c80319c` — the caller's context is
preserved, and any spans katana fans out downstream chain under the same
trace.
## Discovered during
Wiring distributed tracing into the cartridge sidecar services
([cartridge-gg/vrf#46](cartridge-gg/vrf#46),
[cartridge-gg/paymaster#15](cartridge-gg/paymaster#15)).
Those PRs correctly install the W3C propagator; this PR closes the gap
on the katana side so the three-service chain stitches under one
trace_id in the collector.
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 3e40686 commit 3db9b65
File tree
3 files changed
+83
-2
lines changed- crates/tracing/src
- docs
3 files changed
+83
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
34 | 44 | | |
35 | 45 | | |
36 | 46 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
428 | 428 | | |
429 | 429 | | |
430 | 430 | | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
431 | 502 | | |
432 | 503 | | |
433 | 504 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
0 commit comments