-
Notifications
You must be signed in to change notification settings - Fork 63
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
RUM-3516 Provide the correct sampling priority for our Span events based on APM new rules #1913
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -224,7 +237,7 @@ class OtelTracerProvider( | |||
internal const val TRACER_ALREADY_EXISTS_WARNING_MESSAGE = | |||
"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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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.
lgtm, I've added some questions for the better understanding
@@ -9,6 +9,8 @@ | |||
import static java.util.concurrent.TimeUnit.MILLISECONDS; | |||
import static java.util.concurrent.TimeUnit.NANOSECONDS; | |||
|
|||
import android.util.Log; |
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.
unused import?
...sdk-android-trace/src/test/kotlin/com/datadog/android/trace/OtelTracerBuilderProviderTest.kt
Show resolved
Hide resolved
...sdk-android-trace/src/test/kotlin/com/datadog/android/trace/OtelTracerBuilderProviderTest.kt
Show resolved
Hide resolved
|
||
// Then | ||
val priority = delegateSpan.samplingPriority | ||
assertThat(priority).isEqualTo(2) |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fun `M use keep priority W buildSpan { not provided sample rate }`() { | |
fun `M use auto-keep priority W buildSpan { not provided sample rate }`() { |
...dk-android-trace/src/test/kotlin/com/datadog/android/utils/forge/CoreDDSpanForgeryFactory.kt
Show resolved
Hide resolved
e546eed
to
8e26066
Compare
|
||
// Then | ||
val priority = delegateSpan.samplingPriority | ||
assertThat(priority).isEqualTo(PrioritySampling.USER_KEEP.toInt()) |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)) |
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.
Great :)
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)