Skip to content

Commit

Permalink
RUM-7745 use TraceContextInjection.Sampled by default
Browse files Browse the repository at this point in the history
  • Loading branch information
xgouchet committed Dec 17, 2024
1 parent 9f3d758 commit 388c229
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ open class DatadogInterceptor internal constructor(
tracedRequestListener = tracedRequestListener,
rumResourceAttributesProvider = rumResourceAttributesProvider,
traceSampler = traceSampler,
traceContextInjection = TraceContextInjection.All,
traceContextInjection = TraceContextInjection.Sampled,
localTracerFactory = { sdkCore, tracingHeaderTypes ->
AndroidTracer.Builder(sdkCore).setTracingHeaderTypes(tracingHeaderTypes).build()
}
Expand Down Expand Up @@ -188,7 +188,7 @@ open class DatadogInterceptor internal constructor(
tracedRequestListener = tracedRequestListener,
rumResourceAttributesProvider = rumResourceAttributesProvider,
traceSampler = traceSampler,
traceContextInjection = TraceContextInjection.All,
traceContextInjection = TraceContextInjection.Sampled,
localTracerFactory = { sdkCore, tracingHeaderTypes ->
AndroidTracer.Builder(sdkCore).setTracingHeaderTypes(tracingHeaderTypes).build()
}
Expand Down Expand Up @@ -228,7 +228,7 @@ open class DatadogInterceptor internal constructor(
tracedRequestListener = tracedRequestListener,
rumResourceAttributesProvider = rumResourceAttributesProvider,
traceSampler = traceSampler,
traceContextInjection = TraceContextInjection.All,
traceContextInjection = TraceContextInjection.Sampled,
localTracerFactory = { sdkCore, tracingHeaderTypes ->
AndroidTracer.Builder(sdkCore).setTracingHeaderTypes(tracingHeaderTypes).build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,20 @@ internal constructor(
tracedRequestListener: TracedRequestListener = NoOpTracedRequestListener(),
traceSampler: Sampler<Span> = DeterministicTraceSampler(DEFAULT_TRACE_SAMPLE_RATE)
) : this(
sdkInstanceName,
tracedHosts.associateWith {
sdkInstanceName = sdkInstanceName,
tracedHosts = tracedHosts.associateWith {
setOf(
TracingHeaderType.DATADOG,
TracingHeaderType.TRACECONTEXT
)
},
tracedRequestListener,
null,
traceSampler,
tracedRequestListener = tracedRequestListener,
traceOrigin = null,
traceSampler = traceSampler,
localTracerFactory = { sdkCore, tracingHeaderTypes ->
AndroidTracer.Builder(sdkCore).setTracingHeaderTypes(tracingHeaderTypes).build()
},
traceContextInjection = TraceContextInjection.All
traceContextInjection = TraceContextInjection.Sampled
)

/**
Expand Down Expand Up @@ -172,15 +172,15 @@ internal constructor(
tracedRequestListener: TracedRequestListener = NoOpTracedRequestListener(),
traceSampler: Sampler<Span> = DeterministicTraceSampler(DEFAULT_TRACE_SAMPLE_RATE)
) : this(
sdkInstanceName,
tracedHostsWithHeaderType,
tracedRequestListener,
null,
traceSampler,
sdkInstanceName = sdkInstanceName,
tracedHosts = tracedHostsWithHeaderType,
tracedRequestListener = tracedRequestListener,
traceOrigin = null,
traceSampler = traceSampler,
localTracerFactory = { sdkCore, tracingHeaderTypes ->
AndroidTracer.Builder(sdkCore).setTracingHeaderTypes(tracingHeaderTypes).build()
},
traceContextInjection = TraceContextInjection.All
traceContextInjection = TraceContextInjection.Sampled
)

/**
Expand Down Expand Up @@ -214,7 +214,7 @@ internal constructor(
localTracerFactory = { sdkCore, tracingHeaderTypes ->
AndroidTracer.Builder(sdkCore).setTracingHeaderTypes(tracingHeaderTypes).build()
},
traceContextInjection = TraceContextInjection.All
traceContextInjection = TraceContextInjection.Sampled
)

// region Interceptor
Expand Down Expand Up @@ -766,7 +766,7 @@ internal constructor(
{ sdkCore, tracingHeaderTypes ->
AndroidTracer.Builder(sdkCore).setTracingHeaderTypes(tracingHeaderTypes).build()
}
internal var traceContextInjection = TraceContextInjection.All
internal var traceContextInjection = TraceContextInjection.Sampled

/**
* Set the SDK instance name to bind to, the default value is null.
Expand Down Expand Up @@ -810,11 +810,10 @@ internal constructor(

/**
* Set the trace context injection behavior for this interceptor in the intercepted requests.
* By default this is set to [TraceContextInjection.All] meaning that all the trace context
* will be propagated in the intercepted requests no matter if the span created around the request
* is sampled or not. In case of [TraceContextInjection.Sampled] only the sampled request will propagate
* the trace context.
* @param traceContextInjection the trace context injection option.
* When set to [TraceContextInjection.All], the sampling decision is propagated in the request.
* When set to [TraceContextInjection.Sampled], only sampled in requests will keep the header, allowing the
* backend agent to apply a different sampling rate for the rest of the request.
* @param traceContextInjection the trace context injection option (default = [TraceContextInjection.Sampled]).
* @see TraceContextInjection.All
* @see TraceContextInjection.Sampled
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ internal class DatadogInterceptorBuilderTest {

// Then
assertThat(interceptor.tracedHosts).isEqualTo(fakeTracedHostsWithHeaderType)
assertThat(interceptor.traceContextInjection).isEqualTo(TraceContextInjection.All)
assertThat(interceptor.traceContextInjection).isEqualTo(TraceContextInjection.Sampled)
assertThat(interceptor.sdkInstanceName).isNull()
assertThat(
interceptor.rumResourceAttributesProvider
Expand All @@ -102,7 +102,7 @@ internal class DatadogInterceptorBuilderTest {
setOf(TracingHeaderType.DATADOG, TracingHeaderType.TRACECONTEXT)
}
)
assertThat(interceptor.traceContextInjection).isEqualTo(TraceContextInjection.All)
assertThat(interceptor.traceContextInjection).isEqualTo(TraceContextInjection.Sampled)
assertThat(interceptor.sdkInstanceName).isNull()
assertThat(
interceptor.rumResourceAttributesProvider
Expand All @@ -122,7 +122,7 @@ internal class DatadogInterceptorBuilderTest {

// Then
assertThat(interceptor.tracedHosts).isEqualTo(fakeTracedHostsWithHeaderType)
assertThat(interceptor.traceContextInjection).isEqualTo(TraceContextInjection.All)
assertThat(interceptor.traceContextInjection).isEqualTo(TraceContextInjection.Sampled)
assertThat(interceptor.sdkInstanceName).isEqualTo(fakeSdkInstaceName)
assertThat(
interceptor.rumResourceAttributesProvider
Expand Down Expand Up @@ -162,7 +162,7 @@ internal class DatadogInterceptorBuilderTest {

// Then
assertThat(interceptor.tracedHosts).isEqualTo(fakeTracedHostsWithHeaderType)
assertThat(interceptor.traceContextInjection).isEqualTo(TraceContextInjection.All)
assertThat(interceptor.traceContextInjection).isEqualTo(TraceContextInjection.Sampled)
assertThat(interceptor.sdkInstanceName).isNull()
assertThat(
interceptor.rumResourceAttributesProvider
Expand All @@ -182,7 +182,7 @@ internal class DatadogInterceptorBuilderTest {

// Then
assertThat(interceptor.tracedHosts).isEqualTo(fakeTracedHostsWithHeaderType)
assertThat(interceptor.traceContextInjection).isEqualTo(TraceContextInjection.All)
assertThat(interceptor.traceContextInjection).isEqualTo(TraceContextInjection.Sampled)
assertThat(interceptor.sdkInstanceName).isNull()
assertThat(interceptor.rumResourceAttributesProvider).isSameAs(mockRumResourceAttributesProvider)
assertThat(interceptor.tracedRequestListener).isInstanceOf(NoOpTracedRequestListener::class.java)
Expand All @@ -202,7 +202,7 @@ internal class DatadogInterceptorBuilderTest {

// Then
assertThat(interceptor.tracedHosts).isEqualTo(fakeTracedHostsWithHeaderType)
assertThat(interceptor.traceContextInjection).isEqualTo(TraceContextInjection.All)
assertThat(interceptor.traceContextInjection).isEqualTo(TraceContextInjection.Sampled)
assertThat(interceptor.sdkInstanceName).isNull()
assertThat(
interceptor.rumResourceAttributesProvider
Expand All @@ -223,7 +223,7 @@ internal class DatadogInterceptorBuilderTest {

// Then
assertThat(interceptor.tracedHosts).isEqualTo(fakeTracedHostsWithHeaderType)
assertThat(interceptor.traceContextInjection).isEqualTo(TraceContextInjection.All)
assertThat(interceptor.traceContextInjection).isEqualTo(TraceContextInjection.Sampled)
assertThat(interceptor.sdkInstanceName).isNull()
assertThat(
interceptor.rumResourceAttributesProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ internal class TracingInterceptorBuilderTest {

// Then
assertThat(interceptor.tracedHosts).isEqualTo(fakeTracedHostsWithHeaderType)
assertThat(interceptor.traceContextInjection).isEqualTo(TraceContextInjection.All)
assertThat(interceptor.traceContextInjection).isEqualTo(TraceContextInjection.Sampled)
assertThat(interceptor.sdkInstanceName).isNull()
assertThat(interceptor.tracedRequestListener).isInstanceOf(NoOpTracedRequestListener::class.java)
assertThat(interceptor.traceSampler).isInstanceOf(DeterministicTraceSampler::class.java)
Expand All @@ -97,7 +97,7 @@ internal class TracingInterceptorBuilderTest {
setOf(TracingHeaderType.DATADOG, TracingHeaderType.TRACECONTEXT)
}
)
assertThat(interceptor.traceContextInjection).isEqualTo(TraceContextInjection.All)
assertThat(interceptor.traceContextInjection).isEqualTo(TraceContextInjection.Sampled)
assertThat(interceptor.sdkInstanceName).isNull()
assertThat(interceptor.tracedRequestListener).isInstanceOf(NoOpTracedRequestListener::class.java)
assertThat(interceptor.traceSampler).isInstanceOf(DeterministicTraceSampler::class.java)
Expand All @@ -114,7 +114,7 @@ internal class TracingInterceptorBuilderTest {

// Then
assertThat(interceptor.tracedHosts).isEqualTo(fakeTracedHostsWithHeaderType)
assertThat(interceptor.traceContextInjection).isEqualTo(TraceContextInjection.All)
assertThat(interceptor.traceContextInjection).isEqualTo(TraceContextInjection.Sampled)
assertThat(interceptor.sdkInstanceName).isEqualTo(fakeSdkInstaceName)
assertThat(interceptor.tracedRequestListener).isInstanceOf(NoOpTracedRequestListener::class.java)
assertThat(interceptor.traceSampler).isInstanceOf(DeterministicTraceSampler::class.java)
Expand Down Expand Up @@ -148,7 +148,7 @@ internal class TracingInterceptorBuilderTest {

// Then
assertThat(interceptor.tracedHosts).isEqualTo(fakeTracedHostsWithHeaderType)
assertThat(interceptor.traceContextInjection).isEqualTo(TraceContextInjection.All)
assertThat(interceptor.traceContextInjection).isEqualTo(TraceContextInjection.Sampled)
assertThat(interceptor.sdkInstanceName).isNull()
assertThat(interceptor.tracedRequestListener).isInstanceOf(NoOpTracedRequestListener::class.java)
assertThat(interceptor.traceSampler).isInstanceOf(DeterministicTraceSampler::class.java)
Expand All @@ -165,7 +165,7 @@ internal class TracingInterceptorBuilderTest {

// Then
assertThat(interceptor.tracedHosts).isEqualTo(fakeTracedHostsWithHeaderType)
assertThat(interceptor.traceContextInjection).isEqualTo(TraceContextInjection.All)
assertThat(interceptor.traceContextInjection).isEqualTo(TraceContextInjection.Sampled)
assertThat(interceptor.sdkInstanceName).isNull()
assertThat(interceptor.tracedRequestListener).isSameAs(mockTracedRequestListener)
assertThat(interceptor.traceSampler).isInstanceOf(DeterministicTraceSampler::class.java)
Expand All @@ -182,7 +182,7 @@ internal class TracingInterceptorBuilderTest {

// Then
assertThat(interceptor.tracedHosts).isEqualTo(fakeTracedHostsWithHeaderType)
assertThat(interceptor.traceContextInjection).isEqualTo(TraceContextInjection.All)
assertThat(interceptor.traceContextInjection).isEqualTo(TraceContextInjection.Sampled)
assertThat(interceptor.sdkInstanceName).isNull()
assertThat(interceptor.tracedRequestListener).isInstanceOf(NoOpTracedRequestListener::class.java)
assertThat(interceptor.traceSampler).isSameAs(mockSampler)
Expand Down

0 comments on commit 388c229

Please sign in to comment.