Skip to content

[V2] [FIX] Update resourceTracingSamplingRate on deferred DatadogProvider initialization#1290

Merged
sbarrio merged 1 commit into
feature/v2from
sbarrio/v2/fix/deferred-initialization-ignoring-resource-tracing-sampling-rate
May 26, 2026
Merged

[V2] [FIX] Update resourceTracingSamplingRate on deferred DatadogProvider initialization#1290
sbarrio merged 1 commit into
feature/v2from
sbarrio/v2/fix/deferred-initialization-ignoring-resource-tracing-sampling-rate

Conversation

@sbarrio
Copy link
Copy Markdown
Contributor

@sbarrio sbarrio commented May 25, 2026

What does this PR do?

When using delayedinitialization via the DatadogProvider (giving a basic initialization to the provider and later calling DatadogProvider.Initialize with the full config), if the user was to set resourceTracingSamplingRate via DatadogProvider.initialize(...) this value would end up being ignored by the JS XHRProxy. This was pretty apparent on Android, as the tracing would be stuck at the default 20%. on iOS however this resourceTracingSampligRate would be actually used (nativeInitialization is still called in this path), so the bug was masked.

Motivation

Setting the resourceTracingSamplingRate when using deferred initialization should work.

Additional Notes

Before fix (setting resourceTracingSampligRate on`DatadogProvider.initialize(...)

(Note the sampligPriority being 0)

Screenshot 2026-05-25 at 21 12 03

After fix

Screenshot 2026-05-25 at 21 10 22

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests
  • 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)
  • If this PR is auto-generated, please make sure also to manually update the code related to the change

@sbarrio sbarrio force-pushed the sbarrio/v2/fix/deferred-initialization-ignoring-resource-tracing-sampling-rate branch from 659f211 to edef4c6 Compare May 25, 2026 19:45
@sbarrio sbarrio marked this pull request as ready for review May 25, 2026 19:52
@sbarrio sbarrio requested a review from a team as a code owner May 25, 2026 19:52
Copilot AI review requested due to automatic review settings May 25, 2026 19:52
@sbarrio sbarrio self-assigned this May 25, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes deferred initialization (via DatadogProvider + later DatadogProvider.initialize) so that resourceTracingSamplingRate/first-party-host tracing settings are applied to the already-installed JS XHR instrumentation, preventing Android from being stuck at the default sampling rate.

Changes:

  • Added a tracking-context update mechanism (onTrackingUpdate) to the request proxy abstraction and implemented it in XHRProxy by reading sampling/hosts from a mutable context at open() time.
  • Introduced DdRumResourceTracking.updateTrackingContext() and invoked it during deferred initialization to re-apply resolved tracing values.
  • Extended partial initialization config to accept resourceTracingSamplingRate and added regression tests for XHR sampling rate updates.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/core/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts Makes XHR tracing attributes read from a mutable context and adds onTrackingUpdate.
packages/core/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/tests/XHRProxy.test.ts Adds regression tests validating that updated sampling rate affects subsequent XHRs.
packages/core/src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.ts Extends the request proxy contract with onTrackingUpdate.
packages/core/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.tsx Adds updateTrackingContext wrapper to update an installed proxy.
packages/core/src/DdSdkReactNativeConfiguration.tsx Allows resourceTracingSamplingRate in PartialInitializationConfiguration.
packages/core/src/DdSdkReactNative.tsx Calls updateTrackingContext during deferred initialization before native init.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/core/src/DdSdkReactNativeConfiguration.tsx
@sbarrio sbarrio force-pushed the sbarrio/v2/fix/deferred-initialization-ignoring-resource-tracing-sampling-rate branch from edef4c6 to 2506136 Compare May 25, 2026 20:19
Copy link
Copy Markdown
Member

@marco-saia-datadog marco-saia-datadog left a comment

Choose a reason for hiding this comment

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

Nice 💯

@sbarrio sbarrio merged commit 3a21a80 into feature/v2 May 26, 2026
9 checks passed
@sbarrio sbarrio deleted the sbarrio/v2/fix/deferred-initialization-ignoring-resource-tracing-sampling-rate branch May 26, 2026 10:45
@sbarrio sbarrio mentioned this pull request May 28, 2026
4 tasks
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.

3 participants