Skip to content

Commit 66c66fd

Browse files
committed
RUM-17867: Fixes wrong order setting up session sampler and calling onSessionStart.
When a new RUM session is created, we are doing two things: 1. Copy the session sampler to the `_rumSessionSampler` variable, used by the WebViewTracking feature to obtain sampling information and properly feed it to the JS bridge, which the Browser SDK will use to decide if traces are sampled or not; 2. Call the user provided `onSessionStart` callback if not nil. Right now, we are calling `onSessionStart` before we copy the sampler to `_rumSessionSampler.` This created a problem: when a WebView is created and a request issued, all at application launch, it’s possible the first requests issued by the page displayed in the WebView are not traced properly since the sampling information is not yet available. Even if the customer used `onSessionStart` to delay the WebView initialization, the sampling information wouldn’t be in place yet when the callback runs, so the problem remained. This patch inverts the order, so `onSessionStart` will run only after `_rumSessionSampler` contains the session sampler.
1 parent c436a9a commit 66c66fd

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Unreleased
22

33
- [FEATURE] Add support for UK1 Datadog Site. See [#3087][]
4+
- [FIX] onSessionStart is now called only after sampling information used by WebView Tracking is in place, avoiding missing traces in early requests. See [#3104][]
45

56
# 3.14.0 / 15-07-2026
67

@@ -1200,6 +1201,7 @@ Release `2.0` introduces breaking changes. Follow the [Migration Guide](MIGRATIO
12001201
[#3019]: https://github.com/DataDog/dd-sdk-ios/pull/3019
12011202
[#3051]: https://github.com/DataDog/dd-sdk-ios/pull/3051
12021203
[#3087]: https://github.com/DataDog/dd-sdk-ios/pull/3087
1204+
[#3104]: https://github.com/DataDog/dd-sdk-ios/pull/3104
12031205

12041206
[@00fa9a]: https://github.com/00FA9A
12051207
[@britton-earnin]: https://github.com/Britton-Earnin

DatadogRUM/Sources/Feature/RUMFeature.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ internal final class RUMFeature: DatadogRemoteFeature, RUMSessionSamplerProvider
111111
}()
112112

113113
let onSessionUpdate: RUM.SessionUpdater = { [onSessionStart = configuration.onSessionStart, _rumSessionSampler] sessionScope in
114+
_rumSessionSampler.mutate { $0 = sessionScope?.sampler }
114115
if let sessionScope {
115116
let sessionID = sessionScope.sessionUUID.toRUMDataFormat
116117
let isDiscarded = !sessionScope.sampler.isSampled
117118
onSessionStart?(sessionID, isDiscarded)
118119
}
119-
_rumSessionSampler.mutate { $0 = sessionScope?.sampler }
120120
}
121121

122122
let dependencies = RUMScopeDependencies(

0 commit comments

Comments
 (0)