RUM-3470 chore: Add tests for head-based trace sampling#1772
Conversation
instead of core. This is to remove core reference and migrate towards short-term goals from #1744
… names and fix comments
Datadog ReportBranch report: ✅ 0 Failed, 3000 Passed, 0 Skipped, 11m 13.69s Wall Time 🔻 Code Coverage Decreases vs Default Branch (8)
|
| XCTAssertEqual(try spanMatcher.meta.custom(keyPath: "meta.globaltag2"), "overwrittenValue") | ||
| } | ||
|
|
||
| // MARK: - Tracer with sampling rate |
There was a problem hiding this comment.
💡 Moved to DatadogTracer+SamplingTests.swif - now part of DatadogTraceTests instead of DatadogCoreTests.
| func interceptionDidComplete(interception: URLSessionTaskInterception) | ||
| } | ||
|
|
||
| internal struct NOPDatadogURLSessionInterceptor: DatadogURLSessionHandler { |
| @available(*, deprecated, message: "Use `URLSessionInstrumentation.enable(with:)` instead.") | ||
| open class DatadogURLSessionDelegate: NSObject, URLSessionDataDelegate { | ||
| var interceptor: URLSessionInterceptor? { | ||
| var feature: NetworkInstrumentationFeature? { |
There was a problem hiding this comment.
💡 🧹 to further drop dependency on URLSessionInterceptor - now it is only required for DatadogAlamofireExtension (soon dropped in RUM-3060).
| internal weak var core: DatadogCoreProtocol? | ||
| /// Trace feature scope. | ||
| private let featureScope: FeatureScope |
There was a problem hiding this comment.
💡 to achieve mid-term goals ("no core dependency") from #1744. With this change we facilitate testing DatadogTracer in DatadogTraceTests (vs testing with core mock in DatadogCoreTests).
| internal let origin: String? | ||
| /// The sampling rate for the span (between 0 and 100) | ||
| /// The sampling rate for the span (between 0 and 1) | ||
| internal let samplingRate: Float |
There was a problem hiding this comment.
💡 🧹 this wasn't correct - when encoded, we normalize sample rate to 0...1 range
| <SkippedTests> | ||
| <Test | ||
| Identifier = "HeadBasedSamplingTests/testSamplingLocalTrace()"> | ||
| </Test> |
There was a problem hiding this comment.
💡 These tests are disabled on purpose. I propose we go red → green through RUM-3470 (next PR) and later RUM-3535 ("trace context injection control").
ganeshnj
left a comment
There was a problem hiding this comment.
Very neatly written test cases. a couple of question, everything looks great.
| let allKept = spans.filter({ $0.isKept }).count == 3 | ||
| let allDropped = spans.filter({ !$0.isKept }).count == 3 |
There was a problem hiding this comment.
❓
do we have inconsistent isKept flag for local spans in a trace?
There was a problem hiding this comment.
Yes 😞, this test is red if enabled. Although the original issue touches only on head-based sampling for distributed traces I'll be fixing it for local traces as well. It might be one fix that works for both.
| // MARK: - Distributed Tracing | ||
|
|
||
| // TODO: RUM-3470 Enable this test when head-based sampling is supported | ||
| func testSendingSampledDistributedTraceWithNoParent() throws { |
| } | ||
|
|
||
| // TODO: RUM-3470 Enable this test when head-based sampling is supported | ||
| func testSendingSampledDistributedTraceWithParent() throws { |
What and why?
📦 🧰 This PR prepares
DatadogTracefor the implementation of head-based sampling. It only brings refactoring and fills gaps in tests coverage. There are no changes to existing behaviours.Notably, it adds
HeadBasedSamplingTestssuite that covers main scenarios we want to achieve with head-based sampling. That includes:Head-based sampling of local trace, where all spans must be either "kept" or "dropped":
Head-based sampling of distributed trace, where all spans must be either "kept" or "dropped":
Head-based sampling of distributed trace with local parent, where all spans must be either "kept" or "dropped":
The work has to be split between
RUM-3470(next PR) andRUM-3535("trace context injection"). To embrace common understanding of what we want to do, I propose to go red → green refactoring, hence I'm adding multiple tests that are yet disabled.How?
HeadBasedSamplingTeststo add missing coverage and set common goals forRUM-3470andRUM-3535;DatadogTracefor more clarity:sampler→localTraceSamplerinDatadogTracer;tracingSampler→distributedTraceSamplerinTracingURLSessionHandler;DatadogCoreTests(integration testing) toDatadogTraceTests(unit testing).Review checklist
Custom CI job configuration (optional)
tools/