feat(tracing): add DD_TRACE_SECURE_RANDOM option for guaranteed ID uniqueness#5739
feat(tracing): add DD_TRACE_SECURE_RANDOM option for guaranteed ID uniqueness#5739litianningdatadog wants to merge 4 commits into
Conversation
…iqueness Utils.next_id uses a module-level Random.new (Mersenne Twister) seeded from OS entropy at construction. After that point the PRNG state is fully deterministic. In environments where process memory is cloned (e.g. VM snapshots, certain fork patterns), all clones share the same PRNG state and produce identical trace and span ID sequences. The existing after_fork! guard reseeds on fork(2) via PID comparison but cannot detect other forms of memory duplication. When DD_TRACE_SECURE_RANDOM=true, next_id delegates to SecureRandom.random_number instead. SecureRandom reads from the OS entropy pool on every call and holds no userspace state, ensuring IDs remain unique regardless of how the process image was created or duplicated. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
|
👋 Hey @DataDog/ruby-guild, please fill "Change log entry" section in the pull request description. If changes need to be present in CHANGELOG.md you can state it this way **Change log entry**
Yes. A brief summary to be placed into the CHANGELOG.md(possible answers Yes/Yep/Yeah) Or you can opt out like that **Change log entry**
None.(possible answers No/Nope/None) Visited at: 2026-05-12 00:09:01 UTC |
🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: 964e877 | Docs | Datadog PR Page | Give us feedback! |
BenchmarksBenchmark execution time: 2026-05-13 02:34:22 Comparing candidate commit 964e877 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 45 metrics, 1 unstable metrics.
|
…RANDOM - Use DATADOG_ENV instead of ENV for DD_TRACE_SECURE_RANDOM access - Register DD_TRACE_SECURE_RANDOM in supported-configurations.json - Add RBS type declarations for secure_random? and @secure_random - Fix memoization bug: ||= does not cache false values; use nil? guard - Add test coverage for explicit false and memoization correctness Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Typing analysisNote: Ignored files are excluded from the next sections. Untyped methodsThis PR introduces 7 untyped methods and 1 partially typed method, and clears 7 untyped methods and 1 partially typed method. It increases the percentage of typed methods from 62.24% to 62.26% (+0.02%). Untyped methods (+7-7)❌ Introduced:Partially typed methods (+1-1)❌ Introduced:Untyped other declarationsThis PR introduces 1 untyped other declaration, and clears 1 untyped other declaration. It increases the percentage of typed other declarations from 78.4% to 78.41% (+0.01%). Untyped other declarations (+1-1)❌ Introduced:If you believe a method or an attribute is rightfully untyped or partially typed, you can add |
Bare `DATADOG_ENV` reference caused NameError since the constant is defined as `Datadog::DATADOG_ENV` and is not resolvable in the RSpec top-level scope. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Use `!!` to coerce `bool?` ivar to `bool` so Steep accepts the early return as the declared `() -> bool` return type. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Tech Doc
Summary
Utils.next_iduses a module-levelRandom.new(Mersenne Twister) seeded from OS entropy at construction. After that the PRNG state is fully deterministic. In environments where process memory is cloned, all copies share the same PRNG state and produce identical trace/span ID sequences. The existingafter_fork!guard reseeds onfork(2)via PID comparison but cannot detect other forms of memory duplication.DD_TRACE_SECURE_RANDOM=true,next_iddelegates toSecureRandom.random_numberinstead.SecureRandomreads from the OS entropy pool on every call and holds no userspace state.SecureRandomis Ruby stdlib — no new gem dependency.Test plan
DD_TRACE_SECURE_RANDOM=true: IDs within valid range, >90 unique out of 100 calls,SecureRandom.random_numberinvokedRandom.newpath used,SecureRandomnot invokedUtilsspecs unaffected🤖 Generated with Claude Code