-
Notifications
You must be signed in to change notification settings - Fork 81
RUM-16886: Mark sampled-out network spans as droppable while preserving stats #3596
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
base: feature/client-side-stats
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ import com.datadog.android.trace.internal.ApmNetworkInstrumentation.Companion.ZE | |
| import com.datadog.android.trace.internal.ParentContextSource | ||
| import com.datadog.android.trace.internal._TraceInternalProxy | ||
| import com.datadog.android.trace.internal._TraceInternalProxy.propagationHelper | ||
| import com.datadog.android.trace.internal.domain.event.FORCE_DROP_SPAN | ||
| import java.util.Locale | ||
|
|
||
| internal val FeatureSdkCore?.isRumEnabled: Boolean | ||
|
|
@@ -71,8 +72,12 @@ internal fun DatadogSpan.sample( | |
| } | ||
| } | ||
|
|
||
| internal fun DatadogSpan.finishRumAware(isSampled: Boolean, canSendSpan: Boolean) { | ||
| if (canSendSpan && isSampled) { | ||
| internal fun DatadogSpan.finishRumAware(isSampled: Boolean, canSendSpan: Boolean, isSDKBacked: Boolean) { | ||
| if (canSendSpan && (isSDKBacked || isSampled)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's hard to understand that complex boolean combination. maybe could be simplified? when {
!canSendSpan -> drop()
isSDKBacked && !sSampled -> {
setTag(FORCE_DROP_SPAN, true)
finish()
}
else -> dtop()
}
Not sure if the code does the same, but flattening it a bit will make it more readable." |
||
| if (isSDKBacked && !isSampled) { | ||
| // SDK-backed tracer: tag the span so CoreTraceWriter suppresses it instead of calling drop() | ||
| setTag(FORCE_DROP_SPAN, true) | ||
| } | ||
| finish() | ||
| } else { | ||
| drop() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,13 +23,15 @@ import com.datadog.android.trace.api.span.DatadogSpan | |
| * @property isSampled whether the request trace was sampled. | ||
| * @property span the trace span created for this request, or null if not sampled or tracing is disabled. | ||
| * @property sampleRate the sample rate used for the sampling decision. | ||
| * @property isSDKBacked whether the tracer is the SDK's built-in implementation | ||
| */ | ||
| @InternalApi | ||
| data class RequestTracingState( | ||
| val requestInfoBuilder: HttpRequestInfoBuilder, | ||
| val isSampled: Boolean = false, | ||
| val span: DatadogSpan? = null, | ||
| val sampleRate: Float? = null | ||
| val sampleRate: Float? = null, | ||
| val isSDKBacked: Boolean | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, that is much better :D |
||
| ) { | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,6 +19,7 @@ import com.datadog.android.event.EventMapper | |||||||||||||||||||||||||||||||||||||
| import com.datadog.android.log.LogAttributes | ||||||||||||||||||||||||||||||||||||||
| import com.datadog.android.trace.internal.RumContextPropagator | ||||||||||||||||||||||||||||||||||||||
| import com.datadog.android.trace.internal.domain.event.ContextAwareMapper | ||||||||||||||||||||||||||||||||||||||
| import com.datadog.android.trace.internal.domain.event.FORCE_DROP_SPAN | ||||||||||||||||||||||||||||||||||||||
| import com.datadog.android.trace.internal.storage.ContextAwareSerializer | ||||||||||||||||||||||||||||||||||||||
| import com.datadog.android.trace.model.SpanEvent | ||||||||||||||||||||||||||||||||||||||
| import com.datadog.android.trace.utils.RumContextTestsUtils.RUM_CONTEXT_ACTION_ID | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -319,6 +320,24 @@ internal class CoreTraceWriterTest { | |||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||
| fun `M not write spans with force drop tag W write()`(forge: Forge) { | ||||||||||||||||||||||||||||||||||||||
| // GIVEN | ||||||||||||||||||||||||||||||||||||||
| val ddSpans = createNonEmptyDdSpans( | ||||||||||||||||||||||||||||||||||||||
| forge = forge, | ||||||||||||||||||||||||||||||||||||||
| includeDropSamplingPriority = false | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
| ddSpans.forEach { whenever(it.getTag(FORCE_DROP_SPAN)) doReturn true } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // WHEN | ||||||||||||||||||||||||||||||||||||||
| testedWriter.write(ddSpans) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // THEN | ||||||||||||||||||||||||||||||||||||||
| verifyNoInteractions(mockEventBatchWriter) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| ddSpans.forEach { it.finish() } | ||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is wired line: If this is an assertion and you've expected for example that there is no exception thrown - it's better to wrap into If this code tries to free up resources - this is the wrong way to do so as if test fails on the lines above - this line won't be executed
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A few of the tests in this file have that and I am not sure why, they don't look to serve a purpose to me given they are Forge generated spans Lines 304 to 321 in 5410db4
|
||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||
| fun `M not write non-mapped spans W write()`(forge: Forge) { | ||||||||||||||||||||||||||||||||||||||
| // GIVEN | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
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.
could be
constThere 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.
Not sure I follow, it is a const?