Skip to content

test(relay): deflake trace_context_lookup test via rebuild_interest_cache - #4100

Open
iroiro147 wants to merge 1 commit into
block:mainfrom
iroiro147:claude/issue3929-flaky-trace-test-20260801
Open

test(relay): deflake trace_context_lookup test via rebuild_interest_cache#4100
iroiro147 wants to merge 1 commit into
block:mainfrom
iroiro147:claude/issue3929-flaky-trace-test-20260801

Conversation

@iroiro147

Copy link
Copy Markdown

Fixes #3929.

What

telemetry::tests::trace_context_lookup_does_not_enable_callsites was intermittently failing in the parallel buzz-relay lib suite — 1/6 of full-suite runs on clean main. Standalone the test passes 100% of the time, but under parallel scheduling the tracing::enabled! assertion could race with other tests that install a global default dispatcher.

Root cause

tracing maintains a per-callsite interest cache that is global and process-wide, not per-subscriber. with_default only installs a thread-local dispatcher. If another test (or any prior thread) has primed a static callsite's interest to always, a later assertion on the same static callsite can consult stale cache and bypass our newly-installed LevelFilter::OFF layer.

Change

Call tracing::callsite::rebuild_interest_cache():

  1. Inside with_default — forces all callsites to be re-evaluated against our subscriber, making the LevelFilter::OFF filter authoritative for this assertion.
  2. After the block — restores the global default interest so downstream tests see fresh values.

This is the tracing-idiomatic escape hatch (tracing-rs/tracing#1527) and is more direct than the alternates:

  • ENV_LOCK only serializes against other tests that take it — it can't catch a non-participating racer (the flake materialised precisely because the interferer isn't ENV_LOCK-adjacent).
  • Per-run unique callsite targets would need dynamically-generated &'static str, which tracing::event!/enabled! cannot take.

Why this is safe

  • Test-only change; no production code touched.
  • rebuild_interest_cache() is documented in tracing-core and is the standard escape hatch for stale-callsite flakes.
  • The second rebuild_interest_cache() call restores the default interest — it doesn't lock in our OFF filter. Verified by running the full suite 6x post-fix.

Verification

before (clean main, full suite): 6 runs -> 5 pass, 1 fail
after  (this branch, full suite): 6 runs -> 6 pass, 0 fail

cargo clippy -p buzz-relay --all-targets -- -D warnings — clean.

…ache

trace_context_lookup_does_not_enable_callsites flakes ~1/6 in the full
buzz-relay lib suite (clean main), because tracing's per-callsite
`interest` cache is global and outlives the thread-local `with_default`
dispatcher — a stale cache can bypass our `LevelFilter::OFF` layer and
make the `enabled!` assertion race.

Call `tracing::callsite::rebuild_interest_cache()` once inside the
`with_default` block so the per-test filter is authoritative, and once
afterward to restore default interest for downstream tests. This is the
tracing-idiomatic escape hatch and avoids both ENV_LOCK (which cannot
catch every global-state race) and any per-run naming hack.

Verified: 6/6 green in the full lib suite; was 1/6 failing previously.

Fixes block#3929

Signed-off-by: Sarthak Singh <sarthak.singh@juspay.in>
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.

test(relay): telemetry trace_context_lookup test flaky under parallel suite — reproduces on clean main

1 participant