Skip to content

Commit 8df5aec

Browse files
committed
RUM-8042 Support generic metric telemetry aggregation
1 parent ab4d3fe commit 8df5aec

File tree

17 files changed

+464
-106
lines changed

17 files changed

+464
-106
lines changed

Datadog/Datadog.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,10 @@
13511351
D29A9FE029DDC75A005C54A4 /* UIKitMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = D29A9FDF29DDC75A005C54A4 /* UIKitMocks.swift */; };
13521352
D29CDD3228211A2200F7DAA5 /* TLVBlock.swift in Sources */ = {isa = PBXBuildFile; fileRef = D29CDD3128211A2200F7DAA5 /* TLVBlock.swift */; };
13531353
D29CDD3328211A2200F7DAA5 /* TLVBlock.swift in Sources */ = {isa = PBXBuildFile; fileRef = D29CDD3128211A2200F7DAA5 /* TLVBlock.swift */; };
1354+
D2A133912DAFA8B200D84D3C /* MetricTelemetryAggregator.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2A133902DAFA8B200D84D3C /* MetricTelemetryAggregator.swift */; };
1355+
D2A133922DAFA8B200D84D3C /* MetricTelemetryAggregator.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2A133902DAFA8B200D84D3C /* MetricTelemetryAggregator.swift */; };
1356+
D2A133942DB1074000D84D3C /* MetricTelemetryAggregatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2A133932DB1074000D84D3C /* MetricTelemetryAggregatorTests.swift */; };
1357+
D2A133952DB1074000D84D3C /* MetricTelemetryAggregatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2A133932DB1074000D84D3C /* MetricTelemetryAggregatorTests.swift */; };
13541358
D2A1EE23287740B500D28DFB /* ApplicationStatePublisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2A1EE22287740B500D28DFB /* ApplicationStatePublisher.swift */; };
13551359
D2A1EE24287740B500D28DFB /* ApplicationStatePublisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2A1EE22287740B500D28DFB /* ApplicationStatePublisher.swift */; };
13561360
D2A1EE32287DA51900D28DFB /* UserInfoPublisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2A1EE31287DA51900D28DFB /* UserInfoPublisher.swift */; };
@@ -3061,6 +3065,8 @@
30613065
D29A9FDF29DDC75A005C54A4 /* UIKitMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIKitMocks.swift; sourceTree = "<group>"; };
30623066
D29CDD3128211A2200F7DAA5 /* TLVBlock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TLVBlock.swift; sourceTree = "<group>"; };
30633067
D29D5A4C273BF8B400A687C1 /* SwiftUIActionModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUIActionModifier.swift; sourceTree = "<group>"; };
3068+
D2A133902DAFA8B200D84D3C /* MetricTelemetryAggregator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MetricTelemetryAggregator.swift; sourceTree = "<group>"; };
3069+
D2A133932DB1074000D84D3C /* MetricTelemetryAggregatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MetricTelemetryAggregatorTests.swift; sourceTree = "<group>"; };
30643070
D2A1EE22287740B500D28DFB /* ApplicationStatePublisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationStatePublisher.swift; sourceTree = "<group>"; };
30653071
D2A1EE31287DA51900D28DFB /* UserInfoPublisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserInfoPublisher.swift; sourceTree = "<group>"; };
30663072
D2A1EE34287EB8DB00D28DFB /* ServerOffsetPublisherTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerOffsetPublisherTests.swift; sourceTree = "<group>"; };
@@ -5081,6 +5087,7 @@
50815087
615E2B8D2D39444300D85243 /* ViewEndedController.swift */,
50825088
615E2B942D425F5600D85243 /* ViewEndedMetric.swift */,
50835089
11030D752D96EC5300732D5F /* ViewHitchesMetric.swift */,
5090+
D2A133902DAFA8B200D84D3C /* MetricTelemetryAggregator.swift */,
50845091
);
50855092
path = SDKMetrics;
50865093
sourceTree = "<group>";
@@ -5090,6 +5097,7 @@
50905097
children = (
50915098
6174D6192BFE449300EC7469 /* SessionEndedMetricTests.swift */,
50925099
61DCC8462C05CD0000CB59E5 /* SessionEndedMetricControllerTests.swift */,
5100+
D2A133932DB1074000D84D3C /* MetricTelemetryAggregatorTests.swift */,
50935101
);
50945102
path = SDKMetrics;
50955103
sourceTree = "<group>";
@@ -8723,6 +8731,7 @@
87238731
6194B9342BB451DB00179430 /* FatalAppHangsHandler.swift in Sources */,
87248732
D23F8E5929DDCD28001CFAE8 /* WebViewEventReceiver.swift in Sources */,
87258733
D253EE972B988CA90010B589 /* ViewCache.swift in Sources */,
8734+
D2A133922DAFA8B200D84D3C /* MetricTelemetryAggregator.swift in Sources */,
87268735
D23F8E5A29DDCD28001CFAE8 /* RUMResourceScope.swift in Sources */,
87278736
D23F8E5C29DDCD28001CFAE8 /* RUMApplicationScope.swift in Sources */,
87288737
3CFF4F982C09E64C006F191D /* WatchdogTerminationMonitor.swift in Sources */,
@@ -8858,6 +8867,7 @@
88588867
D23F8EB329DDCD38001CFAE8 /* ErrorMessageReceiverTests.swift in Sources */,
88598868
61C713C12A3C9DAD00FA735A /* RequestBuilderTests.swift in Sources */,
88608869
D23F8EB429DDCD38001CFAE8 /* RUMApplicationScopeTests.swift in Sources */,
8870+
D2A133942DB1074000D84D3C /* MetricTelemetryAggregatorTests.swift in Sources */,
88618871
6105C5152D0C584F00C4C5EE /* INVMetricTests.swift in Sources */,
88628872
D23F8EB629DDCD38001CFAE8 /* RUMViewsHandlerTests.swift in Sources */,
88638873
61C713CB2A3DC22700FA735A /* RUMTests.swift in Sources */,
@@ -9083,6 +9093,7 @@
90839093
6194B9332BB451DB00179430 /* FatalAppHangsHandler.swift in Sources */,
90849094
D29A9F6229DD85BB005C54A4 /* WebViewEventReceiver.swift in Sources */,
90859095
D253EE962B988CA90010B589 /* ViewCache.swift in Sources */,
9096+
D2A133912DAFA8B200D84D3C /* MetricTelemetryAggregator.swift in Sources */,
90869097
D29A9F8429DD85BB005C54A4 /* RUMResourceScope.swift in Sources */,
90879098
D29A9F7329DD85BB005C54A4 /* RUMApplicationScope.swift in Sources */,
90889099
3CFF4F972C09E64C006F191D /* WatchdogTerminationMonitor.swift in Sources */,
@@ -9218,6 +9229,7 @@
92189229
D29A9FBB29DDB483005C54A4 /* ErrorMessageReceiverTests.swift in Sources */,
92199230
61C713C02A3C9DAD00FA735A /* RequestBuilderTests.swift in Sources */,
92209231
D29A9F9F29DDB483005C54A4 /* RUMApplicationScopeTests.swift in Sources */,
9232+
D2A133952DB1074000D84D3C /* MetricTelemetryAggregatorTests.swift in Sources */,
92219233
6105C5142D0C584F00C4C5EE /* INVMetricTests.swift in Sources */,
92229234
D29A9FAA29DDB483005C54A4 /* RUMViewsHandlerTests.swift in Sources */,
92239235
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)