Skip to content

Commit bccdd67

Browse files
committed
RUM-8042 Support generic metric telemetry aggregation
1 parent e85dd3a commit bccdd67

File tree

16 files changed

+462
-104
lines changed

16 files changed

+462
-104
lines changed

Datadog/Datadog.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,10 @@
13431343
D29A9FE029DDC75A005C54A4 /* UIKitMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = D29A9FDF29DDC75A005C54A4 /* UIKitMocks.swift */; };
13441344
D29CDD3228211A2200F7DAA5 /* TLVBlock.swift in Sources */ = {isa = PBXBuildFile; fileRef = D29CDD3128211A2200F7DAA5 /* TLVBlock.swift */; };
13451345
D29CDD3328211A2200F7DAA5 /* TLVBlock.swift in Sources */ = {isa = PBXBuildFile; fileRef = D29CDD3128211A2200F7DAA5 /* TLVBlock.swift */; };
1346+
D2A133912DAFA8B200D84D3C /* MetricTelemetryAggregator.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2A133902DAFA8B200D84D3C /* MetricTelemetryAggregator.swift */; };
1347+
D2A133922DAFA8B200D84D3C /* MetricTelemetryAggregator.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2A133902DAFA8B200D84D3C /* MetricTelemetryAggregator.swift */; };
1348+
D2A133942DB1074000D84D3C /* MetricTelemetryAggregatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2A133932DB1074000D84D3C /* MetricTelemetryAggregatorTests.swift */; };
1349+
D2A133952DB1074000D84D3C /* MetricTelemetryAggregatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2A133932DB1074000D84D3C /* MetricTelemetryAggregatorTests.swift */; };
13461350
D2A1EE23287740B500D28DFB /* ApplicationStatePublisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2A1EE22287740B500D28DFB /* ApplicationStatePublisher.swift */; };
13471351
D2A1EE24287740B500D28DFB /* ApplicationStatePublisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2A1EE22287740B500D28DFB /* ApplicationStatePublisher.swift */; };
13481352
D2A1EE32287DA51900D28DFB /* UserInfoPublisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2A1EE31287DA51900D28DFB /* UserInfoPublisher.swift */; };
@@ -3049,6 +3053,8 @@
30493053
D29A9FDF29DDC75A005C54A4 /* UIKitMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIKitMocks.swift; sourceTree = "<group>"; };
30503054
D29CDD3128211A2200F7DAA5 /* TLVBlock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TLVBlock.swift; sourceTree = "<group>"; };
30513055
D29D5A4C273BF8B400A687C1 /* SwiftUIActionModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUIActionModifier.swift; sourceTree = "<group>"; };
3056+
D2A133902DAFA8B200D84D3C /* MetricTelemetryAggregator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MetricTelemetryAggregator.swift; sourceTree = "<group>"; };
3057+
D2A133932DB1074000D84D3C /* MetricTelemetryAggregatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MetricTelemetryAggregatorTests.swift; sourceTree = "<group>"; };
30523058
D2A1EE22287740B500D28DFB /* ApplicationStatePublisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationStatePublisher.swift; sourceTree = "<group>"; };
30533059
D2A1EE31287DA51900D28DFB /* UserInfoPublisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserInfoPublisher.swift; sourceTree = "<group>"; };
30543060
D2A1EE34287EB8DB00D28DFB /* ServerOffsetPublisherTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerOffsetPublisherTests.swift; sourceTree = "<group>"; };
@@ -5068,6 +5074,7 @@
50685074
6174D61F2C009C6300EC7469 /* SessionEndedMetricController.swift */,
50695075
615E2B942D425F5600D85243 /* ViewEndedMetric.swift */,
50705076
615E2B8D2D39444300D85243 /* ViewEndedMetricController.swift */,
5077+
D2A133902DAFA8B200D84D3C /* MetricTelemetryAggregator.swift */,
50715078
);
50725079
path = SDKMetrics;
50735080
sourceTree = "<group>";
@@ -5077,6 +5084,7 @@
50775084
children = (
50785085
6174D6192BFE449300EC7469 /* SessionEndedMetricTests.swift */,
50795086
61DCC8462C05CD0000CB59E5 /* SessionEndedMetricControllerTests.swift */,
5087+
D2A133932DB1074000D84D3C /* MetricTelemetryAggregatorTests.swift */,
50805088
);
50815089
path = SDKMetrics;
50825090
sourceTree = "<group>";
@@ -8704,6 +8712,7 @@
87048712
6194B9342BB451DB00179430 /* FatalAppHangsHandler.swift in Sources */,
87058713
D23F8E5929DDCD28001CFAE8 /* WebViewEventReceiver.swift in Sources */,
87068714
D253EE972B988CA90010B589 /* ViewCache.swift in Sources */,
8715+
D2A133922DAFA8B200D84D3C /* MetricTelemetryAggregator.swift in Sources */,
87078716
D23F8E5A29DDCD28001CFAE8 /* RUMResourceScope.swift in Sources */,
87088717
D23F8E5C29DDCD28001CFAE8 /* RUMApplicationScope.swift in Sources */,
87098718
3CFF4F982C09E64C006F191D /* WatchdogTerminationMonitor.swift in Sources */,
@@ -8838,6 +8847,7 @@
88388847
D23F8EB329DDCD38001CFAE8 /* ErrorMessageReceiverTests.swift in Sources */,
88398848
61C713C12A3C9DAD00FA735A /* RequestBuilderTests.swift in Sources */,
88408849
D23F8EB429DDCD38001CFAE8 /* RUMApplicationScopeTests.swift in Sources */,
8850+
D2A133942DB1074000D84D3C /* MetricTelemetryAggregatorTests.swift in Sources */,
88418851
6105C5152D0C584F00C4C5EE /* INVMetricTests.swift in Sources */,
88428852
D23F8EB629DDCD38001CFAE8 /* RUMViewsHandlerTests.swift in Sources */,
88438853
61C713CB2A3DC22700FA735A /* RUMTests.swift in Sources */,
@@ -9063,6 +9073,7 @@
90639073
6194B9332BB451DB00179430 /* FatalAppHangsHandler.swift in Sources */,
90649074
D29A9F6229DD85BB005C54A4 /* WebViewEventReceiver.swift in Sources */,
90659075
D253EE962B988CA90010B589 /* ViewCache.swift in Sources */,
9076+
D2A133912DAFA8B200D84D3C /* MetricTelemetryAggregator.swift in Sources */,
90669077
D29A9F8429DD85BB005C54A4 /* RUMResourceScope.swift in Sources */,
90679078
D29A9F7329DD85BB005C54A4 /* RUMApplicationScope.swift in Sources */,
90689079
3CFF4F972C09E64C006F191D /* WatchdogTerminationMonitor.swift in Sources */,
@@ -9197,6 +9208,7 @@
91979208
D29A9FBB29DDB483005C54A4 /* ErrorMessageReceiverTests.swift in Sources */,
91989209
61C713C02A3C9DAD00FA735A /* RequestBuilderTests.swift in Sources */,
91999210
D29A9F9F29DDB483005C54A4 /* RUMApplicationScopeTests.swift in Sources */,
9211+
D2A133952DB1074000D84D3C /* MetricTelemetryAggregatorTests.swift in Sources */,
92009212
6105C5142D0C584F00C4C5EE /* INVMetricTests.swift in Sources */,
92019213
D29A9FAA29DDB483005C54A4 /* RUMViewsHandlerTests.swift in Sources */,
92029214
61C713CA2A3DC22700FA735A /* RUMTests.swift in Sources */,

DatadogCore/Sources/Core/DatadogCore.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ internal final class DatadogCore {
252252
private func applicationDidEnterBackground() {
253253
// Report aggregated 'Batch Blocked' telemetry metric
254254
// when the application enters background.
255-
for metric in batchBlockedMetricAggregator.flush() {
256-
telemetry.send(telemetry: .metric(metric))
255+
for event in batchBlockedMetricAggregator.flush() {
256+
telemetry.metric(.report(event))
257257
}
258258
}
259259
}

DatadogCore/Sources/SDKMetrics/BatchBlockedMetricAggregator.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ internal final class BatchBlockedMetricAggregator {
3535
_aggregations.mutate { $0[key, default: 0] += count }
3636
}
3737

38-
func flush() -> [MetricTelemetry] {
38+
func flush() -> [MetricTelemetry.Event] {
3939
_aggregations.mutate { aggregations in
4040
defer { aggregations = [:] }
4141

4242
return aggregations.compactMap { key, value in
4343
if let failure = key.failure {
44-
return MetricTelemetry(
44+
return MetricTelemetry.Event(
4545
name: BatchBlockedMetric.name,
4646
attributes: [
4747
SDKMetricFields.typeKey: BatchBlockedMetric.typeValue,
@@ -54,7 +54,7 @@ internal final class BatchBlockedMetricAggregator {
5454
}
5555

5656
if let blockers = key.blockers {
57-
return MetricTelemetry(
57+
return MetricTelemetry.Event(
5858
name: BatchBlockedMetric.name,
5959
attributes: [
6060
SDKMetricFields.typeKey: BatchBlockedMetric.typeValue,

DatadogCore/Tests/Datadog/Core/Persistence/FilesOrchestrator+MetricsTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class FilesOrchestrator_MetricsTests: XCTestCase {
6363
orchestrator.delete(readableFile: file, deletionReason: .intakeCode(responseCode: 202))
6464

6565
// Then
66-
let metric = try XCTUnwrap(telemetry.messages.firstMetric(named: "Batch Deleted"))
66+
let metric = try XCTUnwrap(telemetry.messages.firstMetricReport(named: "Batch Deleted"))
6767
DDAssertJSONEqual(metric.attributes, [
6868
"metric_type": "batch deleted",
6969
"track": "track name",
@@ -95,7 +95,7 @@ class FilesOrchestrator_MetricsTests: XCTestCase {
9595
_ = orchestrator.getReadableFiles()
9696

9797
// Then
98-
let metric = try XCTUnwrap(telemetry.messages.firstMetric(named: "Batch Deleted"))
98+
let metric = try XCTUnwrap(telemetry.messages.firstMetricReport(named: "Batch Deleted"))
9999
DDAssertJSONEqual(metric.attributes, [
100100
"metric_type": "batch deleted",
101101
"track": "track name",
@@ -130,7 +130,7 @@ class FilesOrchestrator_MetricsTests: XCTestCase {
130130
_ = try orchestrator.getWritableFile(writeSize: 1)
131131

132132
// Then
133-
let metric = try XCTUnwrap(telemetry.messages.firstMetric(named: "Batch Deleted"))
133+
let metric = try XCTUnwrap(telemetry.messages.firstMetricReport(named: "Batch Deleted"))
134134
DDAssertJSONEqual(metric.attributes, [
135135
"metric_type": "batch deleted",
136136
"track": "track name",
@@ -175,7 +175,7 @@ class FilesOrchestrator_MetricsTests: XCTestCase {
175175
_ = try orchestrator.getWritableFile(writeSize: 1)
176176

177177
// Then
178-
let metric = try XCTUnwrap(telemetry.messages.firstMetric(named: "Batch Closed"))
178+
let metric = try XCTUnwrap(telemetry.messages.firstMetricReport(named: "Batch Closed"))
179179
DDAssertReflectionEqual(metric.attributes, [
180180
"metric_type": "batch closed",
181181
"track": "track name",

DatadogInternal/Sources/SDKMetrics/SDKMetricFields.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import Foundation
1010
public enum SDKMetricFields {
1111
/// Metric type key. It expects `String` value.
1212
public static let typeKey = "metric_type"
13+
/// Metric value key. It expects `Double` value.
14+
public static let valueKey = "value"
1315
/// The first sample rate applied to the metric.
1416
public static let headSampleRate = "head_sample_rate"
1517
/// Key referencing the session ID (`String`) that the metric should be sent with. It expects `String` value.

DatadogInternal/Sources/Storage.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ public protocol Storage {
1414
func mostRecentModifiedFileAt(before: Date) throws -> Date?
1515
}
1616

17+
extension DatadogCoreProtocol {
18+
/// Provides access to the `Storage` associated with the core.
19+
/// - Returns: The `Storage` instance.
20+
public var storage: Storage { CoreStorage(core: self) }
21+
}
22+
1723
internal struct CoreStorage: Storage {
1824
/// A weak core reference.
1925
private weak var core: DatadogCoreProtocol?

0 commit comments

Comments
 (0)