Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUMM-1377 Add E2E tests for Tracing APIs #616

Merged
merged 5 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Datadog/Datadog.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
61441C982461A649003D8BB8 /* DebugTracingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61441C932461A649003D8BB8 /* DebugTracingViewController.swift */; };
61441C992461A649003D8BB8 /* DebugLoggingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61441C942461A649003D8BB8 /* DebugLoggingViewController.swift */; };
61441C9D2461A796003D8BB8 /* AppConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61441C9C2461A796003D8BB8 /* AppConfiguration.swift */; };
6147E3B3270486920092BC9F /* TracingConfigurationE2ETests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6147E3B2270486920092BC9F /* TracingConfigurationE2ETests.swift */; };
614872772485067300E3EBDB /* SpanTagsReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 614872762485067300E3EBDB /* SpanTagsReducer.swift */; };
61494CB124C839460082C633 /* RUMResourceScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61494CB024C839460082C633 /* RUMResourceScope.swift */; };
61494CB524C864680082C633 /* RUMResourceScopeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61494CB424C864680082C633 /* RUMResourceScopeTests.swift */; };
Expand Down Expand Up @@ -268,9 +269,11 @@
6182374325D3DFD5006A375B /* CrashReportingWithRUMIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6182374225D3DFD5006A375B /* CrashReportingWithRUMIntegrationTests.swift */; };
6184751526EFCF1300C7C9C5 /* DatadogTestsObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6184751426EFCF1300C7C9C5 /* DatadogTestsObserver.swift */; };
6184751826EFD03400C7C9C5 /* DatadogTestsObserverLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 6184751726EFD03400C7C9C5 /* DatadogTestsObserverLoader.m */; };
6185F4AE26FE1956001A7641 /* SpanE2ETests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6185F4AD26FE1956001A7641 /* SpanE2ETests.swift */; };
618715F724DC0CDE00FC0F69 /* RUMCommandTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 618715F624DC0CDE00FC0F69 /* RUMCommandTests.swift */; };
618715F924DC13A100FC0F69 /* RUMDataModelsMapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 618715F824DC13A100FC0F69 /* RUMDataModelsMapping.swift */; };
618715FC24DC5F0800FC0F69 /* RUMDataModelsMappingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 618715FB24DC5F0800FC0F69 /* RUMDataModelsMappingTests.swift */; };
6187A53926FCBE240015D94A /* TracerE2ETests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6187A53826FCBE240015D94A /* TracerE2ETests.swift */; };
618C365F248E85B400520CDE /* DateFormattingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 618C365E248E85B400520CDE /* DateFormattingTests.swift */; };
618D9DE7263AD78900A3FAD2 /* SpanEventMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 618D9DE6263AD78900A3FAD2 /* SpanEventMapper.swift */; };
618DCFD724C7265300589570 /* RUMUUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 618DCFD624C7265300589570 /* RUMUUID.swift */; };
Expand Down Expand Up @@ -824,6 +827,7 @@
61441C932461A649003D8BB8 /* DebugTracingViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DebugTracingViewController.swift; sourceTree = "<group>"; };
61441C942461A649003D8BB8 /* DebugLoggingViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DebugLoggingViewController.swift; sourceTree = "<group>"; };
61441C9C2461A796003D8BB8 /* AppConfiguration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppConfiguration.swift; sourceTree = "<group>"; };
6147E3B2270486920092BC9F /* TracingConfigurationE2ETests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TracingConfigurationE2ETests.swift; sourceTree = "<group>"; };
614872762485067300E3EBDB /* SpanTagsReducer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpanTagsReducer.swift; sourceTree = "<group>"; };
61494CB024C839460082C633 /* RUMResourceScope.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RUMResourceScope.swift; sourceTree = "<group>"; };
61494CB424C864680082C633 /* RUMResourceScopeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RUMResourceScopeTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -909,9 +913,11 @@
6184751426EFCF1300C7C9C5 /* DatadogTestsObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatadogTestsObserver.swift; sourceTree = "<group>"; };
6184751726EFD03400C7C9C5 /* DatadogTestsObserverLoader.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DatadogTestsObserverLoader.m; sourceTree = "<group>"; };
6185EB0F25FA94A700B43E2E /* Base.local.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Base.local.xcconfig; sourceTree = "<group>"; };
6185F4AD26FE1956001A7641 /* SpanE2ETests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpanE2ETests.swift; sourceTree = "<group>"; };
618715F624DC0CDE00FC0F69 /* RUMCommandTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RUMCommandTests.swift; sourceTree = "<group>"; };
618715F824DC13A100FC0F69 /* RUMDataModelsMapping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RUMDataModelsMapping.swift; sourceTree = "<group>"; };
618715FB24DC5F0800FC0F69 /* RUMDataModelsMappingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RUMDataModelsMappingTests.swift; sourceTree = "<group>"; };
6187A53826FCBE240015D94A /* TracerE2ETests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TracerE2ETests.swift; sourceTree = "<group>"; };
618C365E248E85B400520CDE /* DateFormattingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateFormattingTests.swift; sourceTree = "<group>"; };
618D9DE6263AD78900A3FAD2 /* SpanEventMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpanEventMapper.swift; sourceTree = "<group>"; };
618DCFD624C7265300589570 /* RUMUUID.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RUMUUID.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2466,6 +2472,16 @@
path = DataModels;
sourceTree = "<group>";
};
6187A53726FCBDD00015D94A /* Tracing */ = {
isa = PBXGroup;
children = (
6147E3B2270486920092BC9F /* TracingConfigurationE2ETests.swift */,
6187A53826FCBE240015D94A /* TracerE2ETests.swift */,
6185F4AD26FE1956001A7641 /* SpanE2ETests.swift */,
);
path = Tracing;
sourceTree = "<group>";
};
618C365D248E858200520CDE /* Utils */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2557,6 +2573,7 @@
isa = PBXGroup;
children = (
61B3BD502661224800A9BEF0 /* Logging */,
6187A53726FCBDD00015D94A /* Tracing */,
61993667265BBEDC009D7EA8 /* E2ETests.swift */,
6167C79226665D6900D4CF07 /* E2EUtils.swift */,
61216B812667CFC90089DCD1 /* Helpers */,
Expand Down Expand Up @@ -4264,13 +4281,16 @@
6167C791266636B300D4CF07 /* FoundationMocks.swift in Sources */,
618F984F265BC905009959F8 /* E2EConfig.swift in Sources */,
61216B7B2667A9AE0089DCD1 /* LoggingConfigurationE2ETests.swift in Sources */,
6187A53926FCBE240015D94A /* TracerE2ETests.swift in Sources */,
61993668265BBEDC009D7EA8 /* E2ETests.swift in Sources */,
61216B852667CFFE0089DCD1 /* RUME2EHelpers.swift in Sources */,
61216B762666DDA10089DCD1 /* LoggerBuilderE2ETests.swift in Sources */,
61B3BD52266128D300A9BEF0 /* LoggerE2ETests.swift in Sources */,
61216B842667CFF70089DCD1 /* DatadogE2EHelpers.swift in Sources */,
6167C79326665D6900D4CF07 /* E2EUtils.swift in Sources */,
610DE00E26613E990042763D /* PersistenceHelper.swift in Sources */,
6147E3B3270486920092BC9F /* TracingConfigurationE2ETests.swift in Sources */,
6185F4AE26FE1956001A7641 /* SpanE2ETests.swift in Sources */,
61216B802667C79B0089DCD1 /* LoggingTrackingConsentE2ETests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
181 changes: 181 additions & 0 deletions Datadog/E2ETests/Tracing/SpanE2ETests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2019-2020 Datadog, Inc.
*/

import Datadog

class SpanE2ETests: E2ETests {
/// - api-surface: OTSpan.setOperationName(_ operationName: String)
///
/// - data monitor:
/// ```apm
/// $feature = trace
/// $monitor_id = trace_span_set_operation_name_data
/// $monitor_name = "[RUM] [iOS] Nightly - trace_span_set_operation_name: number of hits is below expected value"
/// $monitor_query = "sum(last_1d):avg:trace.trace_span_set_operation_name.hits{service:com.datadog.ios.nightly,env:instrumentation}.as_count() < 1"
/// $monitor_threshold = 1
/// ```
///
/// - performance monitor:
/// ```apm
/// $feature = trace
/// $monitor_id = trace_span_set_operation_name_performance
/// $monitor_name = "[RUM] [iOS] Nightly Performance - trace_span_set_operation_name: has a high average execution time"
/// $monitor_query = "avg(last_1d):p50:trace.perf_measure{env:instrumentation,resource_name:trace_span_set_operation_name,service:com.datadog.ios.nightly} > 0.024"
/// ```
func test_trace_span_set_operation_name() {
let span = Global.sharedTracer.startSpan(operationName: .mockRandom())
let knownOperationName = "trace_span_set_operation_name_new_operation_name" // asserted in monitor

measure(resourceName: DD.PerfSpanName.fromCurrentMethodName()) {
span.setOperationName(knownOperationName)
}

span.finish()
}

/// - api-surface: OTSpan.setTag(key: String, value: Encodable)
///
/// - data monitor: (it uses `ios_trace_span_set_tag` metric defined in "APM > Generate Metrics > Custom Span Metrics")
/// ```apm
/// $feature = trace
/// $monitor_id = trace_span_set_tag_data
/// $monitor_name = "[RUM] [iOS] Nightly - trace_span_set_tag: number of hits is below expected value"
/// $monitor_query = "sum(last_1d):avg:ios_trace_span_set_tag.hits_with_proper_payload{*}.as_count() < 1"
/// $monitor_threshold = 1
/// ```
///
/// - performance monitor:
/// ```apm
/// $feature = trace
/// $monitor_id = trace_span_set_tag_performance
/// $monitor_name = "[RUM] [iOS] Nightly Performance - trace_span_set_tag: has a high average execution time"
/// $monitor_query = "avg(last_1d):p50:trace.perf_measure{env:instrumentation,resource_name:trace_span_set_tag,service:com.datadog.ios.nightly} > 0.024"
/// ```
func test_trace_span_set_tag() {
let span = Global.sharedTracer.startSpan(operationName: "ios_trace_span_set_tag")
let knownTag = DD.specialTag()

measure(resourceName: DD.PerfSpanName.fromCurrentMethodName()) {
span.setTag(key: knownTag.key, value: knownTag.value)
}

span.finish()
}

/// - api-surface: OTSpan.setBaggageItem(key: String, value: String)
///
/// - data monitor: (it uses `ios_trace_span_set_baggage_item` metric defined in "APM > Generate Metrics > Custom Span Metrics")
/// ```apm
/// $feature = trace
/// $monitor_id = trace_span_set_baggage_item_data
/// $monitor_name = "[RUM] [iOS] Nightly - trace_span_set_baggage_item: number of hits is below expected value"
/// $monitor_query = "sum(last_1d):avg:ios_trace_span_set_baggage_item.hits_with_proper_payload{*}.as_count() < 1"
/// $monitor_threshold = 1
/// ```
Comment on lines +70 to +77
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of monitors require manual management of custom span metric generated at ingestion
Screenshot 2021-09-29 at 13 51 53

This can't be automated and this is the only way possible if we want to make monitor assertions on span tags.

///
/// - performance monitor:
/// ```apm
/// $feature = trace
/// $monitor_id = trace_span_set_baggage_item_performance
/// $monitor_name = "[RUM] [iOS] Nightly Performance - trace_span_set_baggage_item: has a high average execution time"
/// $monitor_query = "avg(last_1d):p50:trace.perf_measure{env:instrumentation,resource_name:trace_span_set_baggage_item,service:com.datadog.ios.nightly} > 0.024"
/// ```
func test_trace_span_set_baggage_item() {
let span = Global.sharedTracer.startSpan(operationName: "ios_trace_span_set_baggage_item")
let knownTag = DD.specialTag()

measure(resourceName: DD.PerfSpanName.fromCurrentMethodName()) {
span.setBaggageItem(key: knownTag.key, value: knownTag.value)
}

span.finish()
}

/// - api-surface: OTTracer.activeSpan: OTSpan?
///
/// - data monitor:
/// ```apm
/// $feature = trace
/// $monitor_id = trace_span_set_active_data
/// $monitor_name = "[RUM] [iOS] Nightly - trace_span_set_active: number of hits is below expected value"
/// $monitor_query = "sum(last_1d):avg:trace.trace_span_set_active_measured_span.hits{service:com.datadog.ios.nightly,env:instrumentation}.as_count() < 1"
/// $monitor_threshold = 1
/// ```
///
/// - performance monitor:
/// ```apm
/// $feature = trace
/// $monitor_id = trace_span_set_active_performance
/// $monitor_name = "[RUM] [iOS] Nightly Performance - trace_span_set_active: has a high average execution time"
/// $monitor_query = "avg(last_1d):p50:trace.perf_measure{env:instrumentation,resource_name:trace_span_set_active,service:com.datadog.ios.nightly} > 0.024"
/// ```
func test_trace_span_set_active() {
let span = Global.sharedTracer.startSpan(operationName: "trace_span_set_active_measured_span")

measure(resourceName: DD.PerfSpanName.fromCurrentMethodName()) {
span.setActive()
}

span.finish()
}

/// - api-surface: OTTracer.log(fields: [String: Encodable], timestamp: Date)
///
/// - data monitor:
/// ```logs
/// $feature = trace
/// $monitor_id = trace_span_log_data
/// $monitor_name = "[RUM] [iOS] Nightly - trace_span_log: number of hits is below expected value"
/// $monitor_query = "logs(\"service:com.datadog.ios.nightly @test_method_name:trace_span_log @test_special_string_attribute:customAttribute*\").index(\"*\").rollup(\"count\").last(\"1d\") < 1"
/// ```
///
/// - performance monitor:
/// ```apm
/// $feature = trace
/// $monitor_id = trace_span_log_performance
/// $monitor_name = "[RUM] [iOS] Nightly Performance - trace_span_log: has a high average execution time"
/// $monitor_query = "avg(last_1d):p50:trace.perf_measure{env:instrumentation,resource_name:trace_span_log,service:com.datadog.ios.nightly} > 0.024"
/// ```
func test_trace_span_log() {
let span = Global.sharedTracer.startSpan(operationName: "trace_span_log_measured_span")
let log = DD.specialStringAttribute()

var fields = DD.logAttributes()
fields[log.key] = log.value

measure(resourceName: DD.PerfSpanName.fromCurrentMethodName()) {
span.log(fields: fields)
}

span.finish()
}

/// - api-surface: OTTracer.finish(at time: Date)
///
/// - data monitor:
/// ```apm
/// $feature = trace
/// $monitor_id = trace_span_finish_data
/// $monitor_name = "[RUM] [iOS] Nightly - trace_span_finish: number of hits is below expected value"
/// $monitor_query = "sum(last_1d):avg:trace.trace_span_finish_measured_span.hits{service:com.datadog.ios.nightly,env:instrumentation}.as_count() < 1"
/// $monitor_threshold = 1
/// ```
///
/// - performance monitor:
/// ```apm
/// $feature = trace
/// $monitor_id = trace_span_finish_performance
/// $monitor_name = "[RUM] [iOS] Nightly Performance - trace_span_finish: has a high average execution time"
/// $monitor_query = "avg(last_1d):p50:trace.perf_measure{env:instrumentation,resource_name:trace_span_finish,service:com.datadog.ios.nightly} > 0.024"
/// ```
func test_trace_span_finish() {
let span = Global.sharedTracer.startSpan(operationName: "trace_span_finish_measured_span")

measure(resourceName: DD.PerfSpanName.fromCurrentMethodName()) {
span.finish()
}
}
}
84 changes: 84 additions & 0 deletions Datadog/E2ETests/Tracing/TracerE2ETests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2019-2020 Datadog, Inc.
*/

import Datadog

class TracerE2ETests: E2ETests {
private var tracer: OTTracer! // swiftlint:disable:this implicitly_unwrapped_optional

override func setUp() {
super.setUp()
tracer = Tracer.initialize(configuration: .init())
}

override func tearDown() {
tracer = nil
super.tearDown()
}

/// - api-surface: OTTracer.startSpan(operationName: String,references: [OTReference]?,tags: [String: Encodable]?,startTime: Date?) -> OTSpan
///
/// - performance monitor:
/// ```apm
/// $feature = trace
/// $monitor_id = trace_tracer_start_span_performance
/// $monitor_name = "[RUM] [iOS] Nightly Performance - trace_tracer_start_span: has a high average execution time"
/// $monitor_query = "avg(last_1d):p50:trace.perf_measure{env:instrumentation,resource_name:trace_tracer_start_span,service:com.datadog.ios.nightly} > 0.024"
/// ```
func test_trace_tracer_start_span() {
measure(resourceName: DD.PerfSpanName.fromCurrentMethodName()) {
_ = tracer.startSpan(operationName: .mockRandom()) // this span is never sent
}
}

/// - api-surface: OTTracer.startRootSpan(operationName: String,tags: [String: Encodable]?,startTime: Date?) -> OTSpan
///
/// - performance monitor:
/// ```apm
/// $feature = trace
/// $monitor_id = trace_tracer_start_root_span_performance
/// $monitor_name = "[RUM] [iOS] Nightly Performance - trace_tracer_start_root_span: has a high average execution time"
/// $monitor_query = "avg(last_1d):p50:trace.perf_measure{env:instrumentation,resource_name:trace_tracer_start_root_span,service:com.datadog.ios.nightly} > 0.024"
/// ```
func test_trace_tracer_start_root_span() {
measure(resourceName: DD.PerfSpanName.fromCurrentMethodName()) {
_ = tracer.startRootSpan(operationName: .mockRandom()) // this span is never sent
}
}

/// - api-surface: OTTracer.inject(spanContext: OTSpanContext, writer: OTFormatWriter)
///
/// - performance monitor:
/// ```apm
/// $feature = trace
/// $monitor_id = trace_tracer_inject_span_context_performance
/// $monitor_name = "[RUM] [iOS] Nightly Performance - trace_tracer_inject_span_context: has a high average execution time"
/// $monitor_query = "avg(last_1d):p50:trace.perf_measure{env:instrumentation,resource_name:trace_tracer_inject_span_context,service:com.datadog.ios.nightly} > 0.024"
/// ```
func test_trace_tracer_inject_span_context() {
let anySpan = tracer.startSpan(operationName: .mockRandom()) // this span is never sent
let anyWriter = HTTPHeadersWriter()

measure(resourceName: DD.PerfSpanName.fromCurrentMethodName()) {
tracer.inject(spanContext: anySpan.context, writer: anyWriter)
}
}

/// - api-surface: OTTracer.activeSpan: OTSpan?
///
/// - performance monitor:
/// ```apm
/// $feature = trace
/// $monitor_id = trace_tracer_active_span_performance
/// $monitor_name = "[RUM] [iOS] Nightly Performance - trace_tracer_active_span: has a high average execution time"
/// $monitor_query = "avg(last_1d):p50:trace.perf_measure{env:instrumentation,resource_name:trace_tracer_active_span,service:com.datadog.ios.nightly} > 0.024"
/// ```
func test_trace_tracer_active_span() {
measure(resourceName: DD.PerfSpanName.fromCurrentMethodName()) {
_ = tracer.activeSpan
}
}
}
Loading