Shadow: RUM-15702 Add trace sampling decision to DatadogEventBridge (v1)#105
Open
allspain wants to merge 3 commits into
Open
Shadow: RUM-15702 Add trace sampling decision to DatadogEventBridge (v1)#105allspain wants to merge 3 commits into
allspain wants to merge 3 commits into
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Shadow Review — PR
#4516v1Source:
DataDog/browser-sdk#4516Commit:
551c3cdd9565af1bc15a8102fc7bda59e3b9ca86Timestamp: 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), ornullif 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. Fornull, 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