Skip to content

RUM-15138: Preserve custom DeterministicTraceSampler subclasses from rebasing#3455

Merged
hamorillo merged 1 commit into
developfrom
hector.morilloprieto/RUM-15138-custom-samplers
May 19, 2026
Merged

RUM-15138: Preserve custom DeterministicTraceSampler subclasses from rebasing#3455
hamorillo merged 1 commit into
developfrom
hector.morilloprieto/RUM-15138-custom-samplers

Conversation

@hamorillo

Copy link
Copy Markdown
Contributor

What does this PR do?

Replaces the is DeterministicTraceSampler type check at two call sites (DatadogInterceptor.Builder.build() and ApmNetworkInstrumentationConfiguration.createInstrumentation) with an exact-class match, so subclasses of DeterministicTraceSampler passed via setTraceSampler() are preserved as custom samplers and bypass cross-product rebasing. KDoc on setTraceSampler in TracingInterceptor and ApmNetworkInstrumentationConfiguration updated to clarify this behavior.

Motivation

Codex flagged a P2 in PR #3454: when a customer passes a DeterministicTraceSampler subclass via setTraceSampler(), the previous is DeterministicTraceSampler check still wrapped it in SessionRebasedSampler. Inside SessionRebasedSampler.sample(), when the combined rate differs from the raw rate, a fresh DeterministicTraceSampler(effectiveRate) is constructed and used — silently bypassing the customer's subclass logic. This contradicts the documented setTraceSampler contract that custom samplers do not participate in cross-product rebasing.

With the exact-class match, only an exact DeterministicTraceSampler instance (which is what setTraceSampleRate produces internally) is wrapped. Subclasses and any other custom Sampler<DatadogSpan> are preserved as-is.

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)

…rebasing

Tighten the SessionRebasedSampler wrap condition in DatadogInterceptor.Builder and ApmNetworkInstrumentationConfiguration.createInstrumentation from `is DeterministicTraceSampler` to an exact-class check, so subclasses passed via setTraceSampler are preserved as-is and bypass cross-product rebasing. This matches the documented setTraceSampler contract that custom samplers should not be rebased. Updated KDoc on setTraceSampler in TracingInterceptor and ApmNetworkInstrumentationConfiguration to clarify that subclasses of DeterministicTraceSampler are also treated as custom samplers and that only an exact DeterministicTraceSampler instance (equivalent to setTraceSampleRate) participates in rebasing. Added test coverage in DatadogInterceptorBuilderTest and ApmInstrumentationConfigurationTest asserting subclass instances are not wrapped.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.17%. Comparing base (2229525) to head (18e2381).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3455      +/-   ##
===========================================
- Coverage    72.22%   72.17%   -0.05%     
===========================================
  Files          964      964              
  Lines        35497    35500       +3     
  Branches      5896     5897       +1     
===========================================
- Hits         25635    25620      -15     
- Misses        8258     8263       +5     
- Partials      1604     1617      +13     
Files with missing lines Coverage Δ
...id/trace/ApmNetworkInstrumentationConfiguration.kt 77.22% <100.00%> (+2.22%) ⬆️
...n/com/datadog/android/okhttp/DatadogInterceptor.kt 81.67% <100.00%> (ø)
...datadog/android/okhttp/trace/TracingInterceptor.kt 82.37% <ø> (ø)

... and 32 files with indirect coverage changes

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

@hamorillo

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

ℹ️ 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".

@hamorillo
hamorillo marked this pull request as ready for review May 19, 2026 09:01
@hamorillo
hamorillo requested review from a team as code owners May 19, 2026 09:01
@hamorillo
hamorillo merged commit 057365c into develop May 19, 2026
28 checks passed
@hamorillo
hamorillo deleted the hector.morilloprieto/RUM-15138-custom-samplers branch May 19, 2026 09:16
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