Skip to content

Commit

Permalink
RUM-6850: Updates the RUM models based on the current scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
simaoseica-dd committed Dec 10, 2024
1 parent 56ea2e1 commit d3b0a5d
Show file tree
Hide file tree
Showing 12 changed files with 238 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,18 +235,21 @@ class CoreTelemetryIntegrationTests: XCTestCase {
XCTAssertGreaterThan(usageEvents.count, 0)

let debug = try XCTUnwrap(debugEvents.first(where: { $0.telemetry.message == "Debug Telemetry" }))
XCTAssertEqual(debug.effectiveSampleRate, config.telemetrySampleRate)
XCTAssertEqual(debug.effectiveSampleRate, Int64(withNoOverflow: config.telemetrySampleRate))

let error = try XCTUnwrap(errorEvents.first(where: { $0.telemetry.message == "Error Telemetry" }))
XCTAssertEqual(error.effectiveSampleRate, config.telemetrySampleRate)
XCTAssertEqual(error.effectiveSampleRate, Int64(withNoOverflow: config.telemetrySampleRate))

let mobileMetric = try XCTUnwrap(debugEvents.first(where: { $0.telemetry.message == "[Mobile Metric] Metric Name" }))
XCTAssertEqual(mobileMetric.effectiveSampleRate, config.telemetrySampleRate.composed(with: metricsSampleRate))
XCTAssertEqual(mobileMetric.effectiveSampleRate,
Int64(withNoOverflow: config.telemetrySampleRate.composed(with: metricsSampleRate)))

let methodCalledMetric = try XCTUnwrap(debugEvents.first(where: { $0.telemetry.message == "[Mobile Metric] Method Called" }))
XCTAssertEqual(methodCalledMetric.effectiveSampleRate, config.telemetrySampleRate.composed(with: metricsSampleRate).composed(with: headSampleRate))
XCTAssertEqual(methodCalledMetric.effectiveSampleRate,
Int64(withNoOverflow: config.telemetrySampleRate.composed(with: metricsSampleRate).composed(with: headSampleRate)))

let usage = try XCTUnwrap(usageEvents.first)
XCTAssertEqual(usage.effectiveSampleRate, config.telemetrySampleRate.composed(with: metricsSampleRate))
XCTAssertEqual(usage.effectiveSampleRate,
Int64(withNoOverflow: config.telemetrySampleRate.composed(with: metricsSampleRate)))
}
}
7 changes: 6 additions & 1 deletion DatadogCore/Tests/Datadog/Mocks/RUMDataModelMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ extension RUMViewEvent: RandomMockable {
interactionToNextPaint: nil,
interactionToNextPaintTargetSelector: nil,
interactionToNextPaintTime: .mockRandom(),
interactionToNextViewTime: nil,
isActive: viewIsActive,
isSlowRendered: .mockRandom(),
jsRefreshRate: nil,
Expand All @@ -202,6 +203,7 @@ extension RUMViewEvent: RandomMockable {
memoryAverage: .mockRandom(),
memoryMax: .mockRandom(),
name: .mockRandom(),
networkSettledTime: nil,
referrer: .mockRandom(),
refreshRateAverage: .mockRandom(),
refreshRateMin: .mockRandom(),
Expand Down Expand Up @@ -249,6 +251,7 @@ extension RUMResourceEvent: RandomMockable {
resource: .init(
connect: .init(duration: .mockRandom(), start: .mockRandom()),
decodedBodySize: nil,
deliveryType: nil,
dns: .init(duration: .mockRandom(), start: .mockRandom()),
download: .init(duration: .mockRandom(), start: .mockRandom()),
duration: .mockRandom(),
Expand All @@ -269,7 +272,8 @@ extension RUMResourceEvent: RandomMockable {
statusCode: .mockRandom(),
transferSize: nil,
type: [.native, .image].randomElement()!,
url: .mockRandom()
url: .mockRandom(),
worker: nil
),
service: .mockRandom(),
session: .init(
Expand Down Expand Up @@ -526,6 +530,7 @@ extension TelemetryConfigurationEvent: RandomMockable {
forwardErrorsToLogs: nil,
forwardReports: nil,
initializationType: nil,
isMainProcess: nil,
mobileVitalsUpdatePeriod: .mockRandom(),
premiumSampleRate: nil,
reactNativeVersion: nil,
Expand Down
2 changes: 1 addition & 1 deletion DatadogInternal/Sources/SDKMetrics/SDKMetricFields.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public enum SDKMetricFields {
public static let typeKey = "metric_type"
/// The first sample rate applied to the metric.
public static let headSampleRate = "head_sample_rate"

/// Key referencing the session ID (`String`) that the metric should be sent with. It expects `String` value.
///
/// When attached to metric attributes, the value of this key (session ID) will be used to replace
Expand Down
117 changes: 116 additions & 1 deletion DatadogObjc/Sources/RUM/RUMDataModels+objc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ public class DDRUMActionEventDDAction: NSObject {
self.root = root
}

@objc public var nameSource: DDRUMActionEventDDActionNameSource {
set { root.swiftModel.dd.action!.nameSource = newValue.toSwift }
get { .init(swift: root.swiftModel.dd.action!.nameSource) }
}

@objc public var position: DDRUMActionEventDDActionPosition? {
root.swiftModel.dd.action!.position != nil ? DDRUMActionEventDDActionPosition(root: root) : nil
}
Expand All @@ -151,6 +156,41 @@ public class DDRUMActionEventDDAction: NSObject {
}
}

@objc
public enum DDRUMActionEventDDActionNameSource: Int {
internal init(swift: RUMActionEvent.DD.Action.NameSource?) {
switch swift {
case nil: self = .none
case .customAttribute?: self = .customAttribute
case .maskPlaceholder?: self = .maskPlaceholder
case .standardAttribute?: self = .standardAttribute
case .textContent?: self = .textContent
case .maskDisallowed?: self = .maskDisallowed
case .blank?: self = .blank
}
}

internal var toSwift: RUMActionEvent.DD.Action.NameSource? {
switch self {
case .none: return nil
case .customAttribute: return .customAttribute
case .maskPlaceholder: return .maskPlaceholder
case .standardAttribute: return .standardAttribute
case .textContent: return .textContent
case .maskDisallowed: return .maskDisallowed
case .blank: return .blank
}
}

case none
case customAttribute
case maskPlaceholder
case standardAttribute
case textContent
case maskDisallowed
case blank
}

@objc
public class DDRUMActionEventDDActionPosition: NSObject {
internal let root: DDRUMActionEvent
Expand Down Expand Up @@ -3986,6 +4026,10 @@ public class DDRUMResourceEventResource: NSObject {
root.swiftModel.resource.decodedBodySize as NSNumber?
}

@objc public var deliveryType: DDRUMResourceEventResourceDeliveryType {
.init(swift: root.swiftModel.resource.deliveryType)
}

@objc public var dns: DDRUMResourceEventResourceDNS? {
root.swiftModel.resource.dns != nil ? DDRUMResourceEventResourceDNS(root: root) : nil
}
Expand Down Expand Up @@ -4058,6 +4102,10 @@ public class DDRUMResourceEventResource: NSObject {
set { root.swiftModel.resource.url = newValue }
get { root.swiftModel.resource.url }
}

@objc public var worker: DDRUMResourceEventResourceWorker? {
root.swiftModel.resource.worker != nil ? DDRUMResourceEventResourceWorker(root: root) : nil
}
}

@objc
Expand All @@ -4077,6 +4125,32 @@ public class DDRUMResourceEventResourceConnect: NSObject {
}
}

@objc
public enum DDRUMResourceEventResourceDeliveryType: Int {
internal init(swift: RUMResourceEvent.Resource.DeliveryType?) {
switch swift {
case nil: self = .none
case .cache?: self = .cache
case .navigationalPrefetch?: self = .navigationalPrefetch
case .other?: self = .other
}
}

internal var toSwift: RUMResourceEvent.Resource.DeliveryType? {
switch self {
case .none: return nil
case .cache: return .cache
case .navigationalPrefetch: return .navigationalPrefetch
case .other: return .other
}
}

case none
case cache
case navigationalPrefetch
case other
}

@objc
public class DDRUMResourceEventResourceDNS: NSObject {
internal let root: DDRUMResourceEvent
Expand Down Expand Up @@ -4406,6 +4480,23 @@ public enum DDRUMResourceEventResourceResourceType: Int {
case native
}

@objc
public class DDRUMResourceEventResourceWorker: NSObject {
internal let root: DDRUMResourceEvent

internal init(root: DDRUMResourceEvent) {
self.root = root
}

@objc public var duration: NSNumber {
root.swiftModel.resource.worker!.duration as NSNumber
}

@objc public var start: NSNumber {
root.swiftModel.resource.worker!.start as NSNumber
}
}

@objc
public class DDRUMResourceEventSession: NSObject {
internal let root: DDRUMResourceEvent
Expand Down Expand Up @@ -5564,6 +5655,10 @@ public class DDRUMViewEventView: NSObject {
root.swiftModel.view.interactionToNextPaintTime as NSNumber?
}

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

@objc public var isActive: NSNumber? {
root.swiftModel.view.isActive as NSNumber?
}
Expand Down Expand Up @@ -5613,6 +5708,10 @@ public class DDRUMViewEventView: NSObject {
get { root.swiftModel.view.name }
}

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

@objc public var referrer: String? {
set { root.swiftModel.view.referrer = newValue }
get { root.swiftModel.view.referrer }
Expand Down Expand Up @@ -6696,6 +6795,10 @@ public class DDTelemetryErrorEvent: NSObject {
root.swiftModel.date as NSNumber
}

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

@objc public var experimentalFeatures: [String]? {
root.swiftModel.experimentalFeatures
}
Expand Down Expand Up @@ -6951,6 +7054,10 @@ public class DDTelemetryDebugEvent: NSObject {
root.swiftModel.date as NSNumber
}

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

@objc public var experimentalFeatures: [String]? {
root.swiftModel.experimentalFeatures
}
Expand Down Expand Up @@ -7185,6 +7292,10 @@ public class DDTelemetryConfigurationEvent: NSObject {
root.swiftModel.date as NSNumber
}

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

@objc public var experimentalFeatures: [String]? {
root.swiftModel.experimentalFeatures
}
Expand Down Expand Up @@ -7416,6 +7527,10 @@ public class DDTelemetryConfigurationEventTelemetryConfiguration: NSObject {
get { root.swiftModel.telemetry.configuration.initializationType }
}

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

@objc public var mobileVitalsUpdatePeriod: NSNumber? {
set { root.swiftModel.telemetry.configuration.mobileVitalsUpdatePeriod = newValue?.int64Value }
get { root.swiftModel.telemetry.configuration.mobileVitalsUpdatePeriod as NSNumber? }
Expand Down Expand Up @@ -7893,4 +8008,4 @@ public class DDTelemetryConfigurationEventView: NSObject {

// swiftlint:enable force_unwrapping

// Generated from https://github.com/DataDog/rum-events-format/tree/e1c6dde3793714453b5b49f17790a24e9ff9b77b
// Generated from https://github.com/DataDog/rum-events-format/tree/f0fb6383cc401f2f3db120d1f3e2d95d8e03b981
Loading

0 comments on commit d3b0a5d

Please sign in to comment.