Skip to content

Commit 64fe5b6

Browse files
authored
Merge pull request #3106 from DataDog/marroz/RUM-17889-fix-crash-on-session-start-swift-6
Crash when using RUM `onSessionStart` in a Swift 6 project
2 parents 83c55fe + de49b1c commit 64fe5b6

7 files changed

Lines changed: 19 additions & 8 deletions

File tree

CHANGELOG.md

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

33
- [FEATURE] Add support for UK1 Datadog Site. See [#3087][]
44
- [FIX] onSessionStart is now called only after sampling information used by WebView Tracking is in place, avoiding missing traces in early requests. See [#3104][]
5+
- [FIX] Fix crash when defining `onSessionStart` in RUM configuration in Swift 6 projects. See [#3106][]
56

67
# 3.14.0 / 15-07-2026
78

@@ -1202,6 +1203,7 @@ Release `2.0` introduces breaking changes. Follow the [Migration Guide](MIGRATIO
12021203
[#3051]: https://github.com/DataDog/dd-sdk-ios/pull/3051
12031204
[#3087]: https://github.com/DataDog/dd-sdk-ios/pull/3087
12041205
[#3104]: https://github.com/DataDog/dd-sdk-ios/pull/3104
1206+
[#3106]: https://github.com/DataDog/dd-sdk-ios/pull/3106
12051207

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

DatadogRUM/RUM_FEATURE.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
last_updated: 2026-06-29
3-
sdk_version: 3.13.0
4-
verified_against_commit: 48f0891ec
2+
last_updated: 2026-08-04
3+
sdk_version: 3.14.0
4+
verified_against_commit: cc8c93bb3
55
tracked_files:
66
- DatadogRUM/Sources/RUM.swift
77
- DatadogRUM/Sources/RUMConfiguration.swift
@@ -148,6 +148,8 @@ RUM.enable(
148148
// Also available: errorEventMapper, actionEventMapper, longTaskEventMapper
149149

150150
// Session start callback
151+
// Note: this is a `@Sendable` closure (SessionListener) — it may be
152+
// invoked from a background queue, so only capture Sendable state.
151153
onSessionStart: { sessionId, isDiscarded in
152154
// `sessionId` matches the emitted RUM event `session.id`
153155
print("Session \(sessionId) started, sampled out: \(isDiscarded)")

DatadogRUM/Sources/RUM+objc.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ public class objc_RUMConfiguration: NSObject {
709709
}
710710
}
711711

712-
public var onSessionStart: ((String, Bool) -> Void)? {
712+
public var onSessionStart: (@Sendable (String, Bool) -> Void)? {
713713
set { swiftConfig.onSessionStart = newValue }
714714
get { swiftConfig.onSessionStart }
715715
}

DatadogRUM/Sources/RUMConfiguration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extension RUM {
4747

4848
/// RUM session listener.
4949
/// - See: `RUM.Configuration.onSessionStart`.
50-
public typealias SessionListener = (String, Bool) -> Void
50+
public typealias SessionListener = @Sendable (String, Bool) -> Void
5151

5252
/// RUM resource attributes provider.
5353
/// - See: `RUM.Configuration.URLSessionTracking.resourceAttributesProvider`.

SmokeTests/spm/App/ViewController.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ internal class ViewController: UIViewController {
1818
DatadogSetup.initialize()
1919

2020
// RUM APIs must be visible:
21-
RUM.enable(with: .init(applicationID: "app-id"))
21+
RUM.enable(
22+
with: .init(
23+
applicationID: "app-id",
24+
onSessionStart: { sessionID, _ in
25+
print("Session ID is \(sessionID)")
26+
}
27+
)
28+
)
2229
RUMMonitor.shared().startView(viewController: self)
2330

2431
// Trace APIs must be visible:

api-surface-objc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3534,7 +3534,7 @@ public class objc_RUMConfiguration: NSObject
35343534
public func setActionEventMapper(_ mapper: @escaping (objc_RUMActionEvent) -> objc_RUMActionEvent?)
35353535
public func setErrorEventMapper(_ mapper: @escaping (objc_RUMErrorEvent) -> objc_RUMErrorEvent?)
35363536
public func setLongTaskEventMapper(_ mapper: @escaping (objc_RUMLongTaskEvent) -> objc_RUMLongTaskEvent?)
3537-
public var onSessionStart: ((String, Bool) -> Void)?
3537+
public var onSessionStart: (@Sendable (String, Bool) -> Void)?
35383538
public var customEndpoint: URL?
35393539
public var trackAnonymousUser: Bool
35403540
public class objc_RUM: NSObject

api-surface-swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ public enum RUM
391391
public typealias ErrorEventMapper = (RUMErrorEvent) -> RUMErrorEvent?
392392
public typealias ActionEventMapper = (RUMActionEvent) -> RUMActionEvent?
393393
public typealias LongTaskEventMapper = (RUMLongTaskEvent) -> RUMLongTaskEvent?
394-
public typealias SessionListener = (String, Bool) -> Void
394+
public typealias SessionListener = @Sendable (String, Bool) -> Void
395395
public typealias ResourceAttributesProvider = (URLRequest, URLResponse?, Data?, Error?) -> [AttributeKey: AttributeValue]?
396396
public struct Configuration
397397
public let applicationID: String

0 commit comments

Comments
 (0)