Skip to content

Use SecureRandom for Trace/Span ID generation, remove usage of SecureRandom.getStrongInstance#3379

Merged
0xnm merged 1 commit into
developfrom
nogorodnikov/use-secure-random-for-trace-span-id
Apr 20, 2026
Merged

Use SecureRandom for Trace/Span ID generation, remove usage of SecureRandom.getStrongInstance#3379
0xnm merged 1 commit into
developfrom
nogorodnikov/use-secure-random-for-trace-span-id

Conversation

@0xnm
Copy link
Copy Markdown
Member

@0xnm 0xnm commented Apr 17, 2026

What does this PR do?

This PR does the two things:

Use SecureRandom for DatadogTracing

It fixes the regression when we pulled dd-trace-java. In RUMM-233 + #141 we switched to SecureRandom, but during the latest pull of dd-trace-java we enabled its usage only for Otel, see

and later down the call chain

setCustomIdGenerationStrategy(IdGenerationStrategy.fromName("SECURE_RANDOM", traceId128BitGenerationEnabled))

Small change in Config.java activates SecureRandom by default.

Remove SecureRandom#getInstanceStrong usage

SecureRandom#getInstanceStrong() returns the generator which calls /dev/random and if there is not enough entropy any call to generate a random number will block until there is enough entropy.

Default constructor though is using /dev/urandom which doesn't block if there is not enough entropy. This is okay for our needs to generate ID. We are not using plain Random because it is using a timestamp as a seed, so span generated on two different devices at the same instant may have same ID.

The change is aligned with iOS generator, which is using SystemRandomNumberGenerator

At least on Linux systems it also calls /dev/urandom and not /dev/random.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@0xnm 0xnm requested review from a team as code owners April 17, 2026 15:29
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1f01c0cda9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@0xnm 0xnm force-pushed the nogorodnikov/use-secure-random-for-trace-span-id branch from 1f01c0c to ecc8f56 Compare April 17, 2026 15:41
@0xnm 0xnm requested a review from kikoveiga April 17, 2026 15:43
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.01%. Comparing base (e293f09) to head (ecc8f56).
⚠️ Report is 2 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3379      +/-   ##
===========================================
- Coverage    72.01%   72.01%   -0.01%     
===========================================
  Files          956      956              
  Lines        35307    35307              
  Branches      5862     5861       -1     
===========================================
- Hits         25426    25424       -2     
- Misses        8271     8277       +6     
+ Partials      1610     1606       -4     
Files with missing lines Coverage Δ
...ain/java/com/datadog/trace/api/ConfigDefaults.java 100.00% <ø> (ø)
...va/com/datadog/trace/api/IdGenerationStrategy.java 93.33% <100.00%> (+3.33%) ⬆️

... and 34 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@0xnm 0xnm merged commit ec675d8 into develop Apr 20, 2026
27 checks passed
@0xnm 0xnm deleted the nogorodnikov/use-secure-random-for-trace-span-id branch April 20, 2026 07:02
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.

4 participants