Skip to content

fix: Throw ArgumentException for empty traceId in DynamicSamplingContext - #5599

Merged
jamescrosswell merged 1 commit into
getsentry:mainfrom
chiliec:fix/dsc-empty-traceid-argument-exception
Sep 21, 2026
Merged

jamescrosswell merged 1 commit into
getsentry:mainfrom
chiliec:fix/dsc-empty-traceid-argument-exception

Conversation

@chiliec

@chiliec chiliec commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Closes #5169

DynamicSamplingContext throws ArgumentOutOfRangeException when traceId is SentryId.Empty. ArgumentOutOfRangeException is meant for values outside a numeric/ordinal range; an empty id is an invalid argument, so this changes it to ArgumentException (same message, same paramName), matching the publicKey check right below it. The sampleRate / sampleRand range checks are left as ArgumentOutOfRangeException since those really are range checks.

Adds CreateFromPropagationContext_TraceId_Empty_Throws to DynamicSamplingContextTests, which reaches the constructor via SentryPropagationContext(SentryId.Empty, ...).

Verified locally (Linux, .NET SDK 10.0.401, net10.0):

dotnet test test/Sentry.Tests/Sentry.Tests.csproj -f net10.0 --filter "FullyQualifiedName~DynamicSamplingContextTests"
Passed!  - Failed: 0, Passed: 35, Skipped: 0, Total: 35

With the source change reverted the new test fails as expected (Expected: ArgumentException, Actual: ArgumentOutOfRangeException).

Only net10.0 was run here (no Android/iOS workloads on this machine).

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Sep 18, 2026
@codecov

codecov Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.84%. Comparing base (54bb628) to head (0c07e6c).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5599      +/-   ##
==========================================
+ Coverage   74.81%   74.84%   +0.03%     
==========================================
  Files         515      515              
  Lines       18963    18963              
  Branches     3694     3694              
==========================================
+ Hits        14187    14193       +6     
+ Misses       3894     3892       -2     
+ Partials      882      878       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

@jamescrosswell jamescrosswell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Great - thanks @chiliec !

@jamescrosswell
jamescrosswell merged commit 2cf7c8b into getsentry:main Sep 21, 2026
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change ArgumentOutOfRangeException to ArgumentException in DSC

2 participants