-
Notifications
You must be signed in to change notification settings - Fork 134
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
ncreated
merged 5 commits into
master
from
ncreated/RUMM-1377-add-E2E-tests-for-tracing-APIs
Oct 5, 2021
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cccfc40
RUMM-1377 Add E2E tests for `Tracer` APIs
ncreated 614ee5a
RUMM-1377 Remove E2E monitors linter rule for including test method n…
ncreated d045165
RUMM-1377 Allow customizing `$feature` in `logs` monitor template
ncreated 3c2dc46
RUMM-1377 Add E2E tests for `Span` APIs
ncreated d8a9aeb
RUMM-1377 Add E2E tests for Tracing feature configuration API
ncreated File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
/// ``` | ||
/// | ||
/// - 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() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
This can't be automated and this is the only way possible if we want to make monitor assertions on span tags.