Skip to content

Shadow: RUM-15702 Add trace sampling decision to DatadogEventBridge (v1)#105

Open
allspain wants to merge 3 commits into
shadow/4516/v1-basefrom
shadow/4516/v1
Open

Shadow: RUM-15702 Add trace sampling decision to DatadogEventBridge (v1)#105
allspain wants to merge 3 commits into
shadow/4516/v1-basefrom
shadow/4516/v1

Conversation

@allspain
Copy link
Copy Markdown
Owner

Shadow Review — PR #4516 v1

Source: DataDog/browser-sdk#4516
Commit: 551c3cdd9565af1bc15a8102fc7bda59e3b9ca86
Timestamp: 2026-04-21T14:24:33Z


Original PR Description

Motivation

With deterministic sampling, the decision of sampling requests on native clients became consistent, based on the sampling rate and session ID. However, when a native client loads an instrumented web site on a WebView, there is a disconnect between the sampling decision used by the browser SDK of the page being viewed in the WebView, and the native client's decision. This cannot be fixed by post-processing on the native client when the data is funneled through it, since the browser SDK needs to know if headers should be injected on requests, or not. More details here (internal).

To fix this problem, this patch introduces a way for native clients to bridge the sampling decision.

Changes

This patch introduces an additional function in DatadogEventBridge: getIsTraceSampled(). The native clients can inject 3 values: true (if requests should be sampled), false (if they should not), or null if no decision was made (for example, if first party host tracing is not enabled). For the two initial values, sampling rate is set, respectively, to 100 and 0. For null, we fallback to the previous behavior, where the browser SDK is responsible for the sampling rate (through configuration, etc).

Note: I'm not a frontend developer, these changes were mostly made using AI. Please review them taking this into account.

Test instructions

This can only be tested using a native client SDK with the new functionality. I'm going to submit an iOS PR after this one with such functionality enabled.

Checklist

  • Tested locally
  • Tested on staging
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.
  • Updated documentation and/or relevant AGENTS.md file

arroz added 3 commits April 17, 2026 14:40
This way, when running inside a WebView, the native client can decide if tracing happens or not. By doing that, the native SDK can guarantee deterministic sampling between requests done by itself, and the ones done from the web page displayed in the WebView.

The decision is passed through the bridge instead of the sampling rate because, since the session ID is not passed (a mock one is used, and later replaced in the native SDK after the events flow through the bridge), the Browser SDK does not have enough information to perform a deterministic sampling decision.
…ull from the native SDK side.

There's no point in returning strings. Also, we need to return null when there is no decision (session tracing is not configured, for example). Although we could just not have the function there, this way it's more elegant and less error prone (and both methods are supported).
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.

2 participants