RUM-3516 Provide the correct sampling priority for our Span events based on APM new rules#1913
Conversation
64cb324 to
ef6b729
Compare
ef6b729 to
a9433a0
Compare
5992b52 to
8924351
Compare
| val priority = ddSpanContext.samplingPriority | ||
| assertThat(priority).isIn(-1, 2) |
There was a problem hiding this comment.
Warning
This test is not testing whether we are using the sample rate passed in. We just test that when we set a sample rate, the span will have priority manual drop or manual keep.
A better test would be to create 100 spans with the tracer, and then count the number of manual keep, and make sure it's relatively close to the input sample rate.
There was a problem hiding this comment.
I am not trying to test the sampling mechanism here, I am just trying to test that if you specify a sample rate you will either get -1 or 2 but the intention is not to test the sampling logic.
3669e9b to
8f02a06
Compare
| "Tracer for %s already exists. Returning existing instance." | ||
| internal const val DEFAULT_TRACER_NAME = "android" | ||
| internal const val DEFAULT_SAMPLE_RATE = 100.0 | ||
| internal const val KEEP_ALL_SAMPLE_RATE = 100.0 |
There was a problem hiding this comment.
| internal const val KEEP_ALL_SAMPLE_RATE = 100.0 | |
| internal const val KEEP_ALL_SAMPLE_RATE_PERCENT = 100.0 |
| try { | ||
| pendingTraceBufferWorker.join(10000) | ||
| } catch (e: InterruptedException) { | ||
| // ignore |
There was a problem hiding this comment.
should we not log that this has happened? Alternatively if we keep it, I have some memory there is a convention to change the variable name to ignored in the catch block
There was a problem hiding this comment.
yeah I am currently testing things here as I don't really know why my tests are failing in CI. This is currently WIP until I figure out what's the bottom of the issue.
ff10d25 to
9a14bf3
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## feature/otel-support #1913 +/- ##
=========================================================
- Coverage 82.37% 56.43% -25.95%
=========================================================
Files 490 796 +306
Lines 17411 29605 +12194
Branches 2610 4854 +2244
=========================================================
+ Hits 14342 16705 +2363
- Misses 2348 11786 +9438
- Partials 721 1114 +393
|
cfeaed3 to
166d20b
Compare
166d20b to
e546eed
Compare
0xnm
left a comment
There was a problem hiding this comment.
lgtm, I've added some questions for the better understanding
| import static java.util.concurrent.TimeUnit.MILLISECONDS; | ||
| import static java.util.concurrent.TimeUnit.NANOSECONDS; | ||
|
|
||
| import android.util.Log; |
|
|
||
| // Then | ||
| val priority = delegateSpan.samplingPriority | ||
| assertThat(priority).isEqualTo(2) |
There was a problem hiding this comment.
It seems we can use here PrioritySampling.USER_KEEP, same for the tests below
| assertThat(priority).isEqualTo(2) | |
| assertThat(priority).isEqualTo(PrioritySampling.USER_KEEP) |
| } | ||
|
|
||
| @Test | ||
| fun `M use keep priority W buildSpan { not provided sample rate }`() { |
There was a problem hiding this comment.
| fun `M use keep priority W buildSpan { not provided sample rate }`() { | |
| fun `M use auto-keep priority W buildSpan { not provided sample rate }`() { |
e546eed to
8e26066
Compare
|
|
||
| // Then | ||
| val priority = delegateSpan.samplingPriority | ||
| assertThat(priority).isEqualTo(PrioritySampling.USER_KEEP.toInt()) |
There was a problem hiding this comment.
I believe it should be PrioritySampling.USER_DROP here by looking on the name of the test
| } | ||
|
|
||
| @Test | ||
| fun `M use auto - keep priority W buildSpan { not provided sample rate }`() { |
There was a problem hiding this comment.
nit
| fun `M use auto - keep priority W buildSpan { not provided sample rate }`() { | |
| fun `M use auto-keep priority W buildSpan { not provided sample rate }`() { |
8e26066 to
858200e
Compare
| val priority = delegateSpan.samplingPriority | ||
| assertThat(priority).isIn(PrioritySampling.USER_DROP.toInt(), PrioritySampling.USER_KEEP.toInt()) |
There was a problem hiding this comment.
Caution
This part still doesn't test that the appropriate sample rate is being used… the fact that a specific field is set on the core tracer (as tested line 445) doesn't mean it's the one that will be applied. Since we're testing the actual priority set on the spans, we should really try creating 100 spans and measure the effective sampling rate and compare that to the expected one (with some margin of error)
…sed on the new APM rules
858200e to
dcd9317
Compare
| assertThat(droppedSpans.size + keptSpans.size).isEqualTo(numberOfSpans) | ||
| // The sampler does not guarantee the exact number of dropped/kept spans due to the random nature | ||
| // of the sampling so we use an offset to allow a small margin of error | ||
| val offset = 10 | ||
| assertThat(droppedSpans.size).isCloseTo(expectedDroppedSpans, Offset.offset(offset)) | ||
| assertThat(keptSpans.size).isCloseTo(expectedKeptSpans, Offset.offset(offset)) |
What does this PR do?
Following the new rules in APM Java project we will provide the right sampling priority based on the APM tracer configuration.
Motivation
What inspired you to submit this pull request?
Additional Notes
Anything else we should know when reviewing?
Review checklist (to be filled by reviewers)