Skip to content

Commit

Permalink
RUMM-3450 feat: include session_sample_rate as part of _dd.configurat…
Browse files Browse the repository at this point in the history
…ion blob for all RUM events
  • Loading branch information
ganeshnj committed Aug 11, 2023
1 parent 11a6e49 commit 93ef89e
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 39 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- [BUGFIX] Do not propagate attributes from Errors and LongTasks to Views.
- [IMPROVEMENT] Upgrade to PLCrashReporter 1.11.1.
- [FEATURE] Report session sample rate to the backend with RUM events. See [#1410][]

# 2.0.0 / 31-07-2023

Expand Down Expand Up @@ -491,6 +492,7 @@ Release `2.0` introduces breaking changes. Follow the [Migration Guide](MIGRATIO
[#1331]: https://github.com/DataDog/dd-sdk-ios/pull/1331
[#1328]: https://github.com/DataDog/dd-sdk-ios/pull/1328
[#1355]: https://github.com/DataDog/dd-sdk-ios/pull/1355
[#1410]: https://github.com/DataDog/dd-sdk-ios/pull/1410
[@00fa9a]: https://github.com/00FA9A
[@britton-earnin]: https://github.com/Britton-Earnin
[@hengyu]: https://github.com/Hengyu
Expand Down
44 changes: 39 additions & 5 deletions DatadogCore/Tests/Datadog/Mocks/RUMDataModelMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ extension RUMOperatingSystem: RandomMockable {
}
}

extension RUMViewEvent.DD.Configuration: RandomMockable {
public static func mockRandom() -> RUMViewEvent.DD.Configuration {
return .init(sessionReplaySampleRate: .mockRandom(min: 0, max: 100), sessionSampleRate: .mockRandom(min: 0, max: 100))
}
}

extension RUMViewEvent: RandomMockable {
public static func mockRandom() -> RUMViewEvent {
return mockRandomWith()
Expand All @@ -108,7 +114,7 @@ extension RUMViewEvent: RandomMockable {
return RUMViewEvent(
dd: .init(
browserSdkVersion: nil,
configuration: nil,
configuration: .mockRandom(),
documentVersion: .mockRandom(),
pageStates: nil,
replayStats: nil,
Expand Down Expand Up @@ -162,6 +168,7 @@ extension RUMViewEvent: RandomMockable {
start: .mockRandom()
)
],
interactionToNextPaint: nil,
isActive: viewIsActive,
isSlowRendered: .mockRandom(),
jsRefreshRate: nil,
Expand All @@ -184,12 +191,18 @@ extension RUMViewEvent: RandomMockable {
}
}

extension RUMResourceEvent.DD.Configuration: RandomMockable {
public static func mockRandom() -> RUMResourceEvent.DD.Configuration {
.init(sessionReplaySampleRate: .mockRandom(min: 0, max: 100), sessionSampleRate: .mockRandom(min: 0, max: 100))
}
}

extension RUMResourceEvent: RandomMockable {
public static func mockRandom() -> RUMResourceEvent {
return RUMResourceEvent(
dd: .init(
browserSdkVersion: nil,
configuration: nil,
configuration: .mockRandom(),
discarded: nil,
rulePsr: nil,
session: .init(plan: .plan1),
Expand Down Expand Up @@ -244,6 +257,12 @@ extension RUMResourceEvent: RandomMockable {
}
}

extension RUMActionEvent.DD.Configuration: RandomMockable {
public static func mockRandom() -> RUMActionEvent.DD.Configuration {
.init(sessionReplaySampleRate: .mockRandom(min: 0, max: 100), sessionSampleRate: .mockRandom(min: 0, max: 100))
}
}

extension RUMActionEvent: RandomMockable {
public static func mockRandom() -> RUMActionEvent {
return RUMActionEvent(
Expand All @@ -257,7 +276,7 @@ extension RUMActionEvent: RandomMockable {
)
),
browserSdkVersion: nil,
configuration: nil,
configuration: .mockRandom(),
session: .init(plan: .plan1)
),
action: .init(
Expand Down Expand Up @@ -305,12 +324,18 @@ extension RUMErrorEvent.Error.SourceType: RandomMockable {
}
}

extension RUMErrorEvent.DD.Configuration: RandomMockable {
public static func mockRandom() -> RUMErrorEvent.DD.Configuration {
.init(sessionReplaySampleRate: .mockRandom(min: 0, max: 100), sessionSampleRate: .mockRandom(min: 0, max: 100))
}
}

extension RUMErrorEvent: RandomMockable {
public static func mockRandom() -> RUMErrorEvent {
return RUMErrorEvent(
dd: .init(
browserSdkVersion: nil,
configuration: nil,
configuration: .mockRandom(),
session: .init(plan: .plan1)
),
action: .init(id: .mockRandom()),
Expand Down Expand Up @@ -376,12 +401,18 @@ extension RUMCrashEvent: RandomMockable {
}
}

extension RUMLongTaskEvent.DD.Configuration: RandomMockable {
public static func mockRandom() -> RUMLongTaskEvent.DD.Configuration {
return .init(sessionReplaySampleRate: .mockRandom(min: 0, max: 100), sessionSampleRate: .mockRandom(min: 0, max: 100))
}
}

extension RUMLongTaskEvent: RandomMockable {
public static func mockRandom() -> RUMLongTaskEvent {
return RUMLongTaskEvent(
dd: .init(
browserSdkVersion: nil,
configuration: nil,
configuration: .mockRandom(),
discarded: nil,
session: .init(plan: .plan1)
),
Expand Down Expand Up @@ -424,6 +455,8 @@ extension TelemetryConfigurationEvent: RandomMockable {
telemetry: .init(
configuration: .init(
actionNameAttribute: nil,
allowFallbackToLocalStorage: nil,
allowUntrustedEvents: nil,
batchSize: .mockAny(),
batchUploadFrequency: .mockAny(),
defaultPrivacyLevel: .mockAny(),
Expand Down Expand Up @@ -467,6 +500,7 @@ extension TelemetryConfigurationEvent: RandomMockable {
useProxy: .mockRandom(),
useSecureSessionCookie: nil,
useTracing: .mockRandom(),
useWorkerUrl: nil,
viewTrackingStrategy: nil
)
),
Expand Down
56 changes: 55 additions & 1 deletion DatadogCore/Tests/Datadog/RUM/RUMMonitorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class RUMMonitorTests: XCTestCase {
override func setUp() {
super.setUp()
core = DatadogCoreProxy()
config = RUM.Configuration(applicationID: .mockAny())
config = RUM.Configuration(applicationID: .mockAny(), sessionSampleRate: .mockRandom(min: 0, max: 100))
}

override func tearDown() {
Expand Down Expand Up @@ -1250,6 +1250,60 @@ class RUMMonitorTests: XCTestCase {
XCTAssertEqual(try resourceEvents[0].attribute(forKeyPath: "context.def"), "789")
}

// MARK: - Configuration

func testRUMEvents_containSessionSampleRate() throws {
// Given
RUM.enable(with: config, in: core)

let monitor = RUMMonitor.shared(in: core)

// When
monitor.startView(viewController: mockView)
monitor.startAction(type: .scroll, name: .mockAny())
monitor.startResource(resourceKey: "/resource/1", request: .mockAny())
monitor.startResource(resourceKey: "/resource/2", request: .mockAny())
monitor.stopAction(type: .scroll)
monitor.stopResource(resourceKey: "/resource/1", response: .mockAny())
monitor.stopResourceWithError(resourceKey: "/resource/2", message: .mockAny())
monitor.addError(message: .mockAny(), source: .source)
monitor._internal?.addLongTask(at: Date(), duration: 1.0)
monitor.stopView(viewController: mockView)

let rumEventMatchers = try core.waitAndReturnRUMEventMatchers()

// Then
let viewEvents = rumEventMatchers.filterRUMEvents(ofType: RUMViewEvent.self)
XCTAssertNotEqual(viewEvents.count, 0)
for event in viewEvents {
XCTAssertEqual(try event.attribute(forKeyPath: "_dd.configuration.session_sample_rate"), config.sessionSampleRate)
}

let actionEvents = rumEventMatchers.filterRUMEvents(ofType: RUMActionEvent.self)
XCTAssertNotEqual(actionEvents.count, 0)
for event in actionEvents {
XCTAssertEqual(try event.attribute(forKeyPath: "_dd.configuration.session_sample_rate"), config.sessionSampleRate)
}

let resourceEvents = rumEventMatchers.filterRUMEvents(ofType: RUMResourceEvent.self)
XCTAssertNotEqual(resourceEvents.count, 0)
for event in resourceEvents {
XCTAssertEqual(try event.attribute(forKeyPath: "_dd.configuration.session_sample_rate"), config.sessionSampleRate)
}

let errorEvents = rumEventMatchers.filterRUMEvents(ofType: RUMErrorEvent.self)
XCTAssertNotEqual(errorEvents.count, 0)
for event in errorEvents {
XCTAssertEqual(try event.attribute(forKeyPath: "_dd.configuration.session_sample_rate"), config.sessionSampleRate)
}

let longTaskEvents = rumEventMatchers.filterRUMEvents(ofType: RUMLongTaskEvent.self)
XCTAssertNotEqual(longTaskEvents.count, 0)
for event in longTaskEvents {
XCTAssertEqual(try event.attribute(forKeyPath: "_dd.configuration.session_sample_rate"), config.sessionSampleRate)
}
}

// MARK: - Internal attributes

func testHandlingInternalTimestampAttribute() throws {
Expand Down
38 changes: 27 additions & 11 deletions DatadogObjc/Sources/RUM/RUMDataModels+objc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ public class DDRUMActionEventDDConfiguration: NSObject {
self.root = root
}

@objc public var sessionReplaySampleRate: NSNumber {
root.swiftModel.dd.configuration!.sessionReplaySampleRate as NSNumber
@objc public var sessionReplaySampleRate: NSNumber? {
root.swiftModel.dd.configuration!.sessionReplaySampleRate as NSNumber?
}

@objc public var sessionSampleRate: NSNumber {
Expand Down Expand Up @@ -958,8 +958,8 @@ public class DDRUMErrorEventDDConfiguration: NSObject {
self.root = root
}

@objc public var sessionReplaySampleRate: NSNumber {
root.swiftModel.dd.configuration!.sessionReplaySampleRate as NSNumber
@objc public var sessionReplaySampleRate: NSNumber? {
root.swiftModel.dd.configuration!.sessionReplaySampleRate as NSNumber?
}

@objc public var sessionSampleRate: NSNumber {
Expand Down Expand Up @@ -1953,8 +1953,8 @@ public class DDRUMLongTaskEventDDConfiguration: NSObject {
self.root = root
}

@objc public var sessionReplaySampleRate: NSNumber {
root.swiftModel.dd.configuration!.sessionReplaySampleRate as NSNumber
@objc public var sessionReplaySampleRate: NSNumber? {
root.swiftModel.dd.configuration!.sessionReplaySampleRate as NSNumber?
}

@objc public var sessionSampleRate: NSNumber {
Expand Down Expand Up @@ -2603,8 +2603,8 @@ public class DDRUMResourceEventDDConfiguration: NSObject {
self.root = root
}

@objc public var sessionReplaySampleRate: NSNumber {
root.swiftModel.dd.configuration!.sessionReplaySampleRate as NSNumber
@objc public var sessionReplaySampleRate: NSNumber? {
root.swiftModel.dd.configuration!.sessionReplaySampleRate as NSNumber?
}

@objc public var sessionSampleRate: NSNumber {
Expand Down Expand Up @@ -3558,8 +3558,8 @@ public class DDRUMViewEventDDConfiguration: NSObject {
self.root = root
}

@objc public var sessionReplaySampleRate: NSNumber {
root.swiftModel.dd.configuration!.sessionReplaySampleRate as NSNumber
@objc public var sessionReplaySampleRate: NSNumber? {
root.swiftModel.dd.configuration!.sessionReplaySampleRate as NSNumber?
}

@objc public var sessionSampleRate: NSNumber {
Expand Down Expand Up @@ -4266,6 +4266,10 @@ public class DDRUMViewEventView: NSObject {
root.swiftModel.view.inForegroundPeriods?.map { DDRUMViewEventViewInForegroundPeriods(swiftModel: $0) }
}

@objc public var interactionToNextPaint: NSNumber? {
root.swiftModel.view.interactionToNextPaint as NSNumber?
}

@objc public var isActive: NSNumber? {
root.swiftModel.view.isActive as NSNumber?
}
Expand Down Expand Up @@ -5102,6 +5106,14 @@ public class DDTelemetryConfigurationEventTelemetryConfiguration: NSObject {
root.swiftModel.telemetry.configuration.actionNameAttribute
}

@objc public var allowFallbackToLocalStorage: NSNumber? {
root.swiftModel.telemetry.configuration.allowFallbackToLocalStorage as NSNumber?
}

@objc public var allowUntrustedEvents: NSNumber? {
root.swiftModel.telemetry.configuration.allowUntrustedEvents as NSNumber?
}

@objc public var batchSize: NSNumber? {
root.swiftModel.telemetry.configuration.batchSize as NSNumber?
}
Expand Down Expand Up @@ -5310,6 +5322,10 @@ public class DDTelemetryConfigurationEventTelemetryConfiguration: NSObject {
root.swiftModel.telemetry.configuration.useTracing as NSNumber?
}

@objc public var useWorkerUrl: NSNumber? {
root.swiftModel.telemetry.configuration.useWorkerUrl as NSNumber?
}

@objc public var viewTrackingStrategy: DDTelemetryConfigurationEventTelemetryConfigurationViewTrackingStrategy {
.init(swift: root.swiftModel.telemetry.configuration.viewTrackingStrategy)
}
Expand Down Expand Up @@ -5434,4 +5450,4 @@ public class DDTelemetryConfigurationEventView: NSObject {

// swiftlint:enable force_unwrapping

// Generated from https://github.com/DataDog/rum-events-format/tree/2b1615693d269368ed91f061103ee98bfecafb00
// Generated from https://github.com/DataDog/rum-events-format/tree/f21e8badee23a4d3204440d55a5ac7b5d9fadc81
Loading

0 comments on commit 93ef89e

Please sign in to comment.