Skip to content
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-1556: Update default propagation style from Datadog to Datadog+TraceContext #1696

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ internal constructor(
NETWORK_REQUESTS_TRACKING_FEATURE_NAME
)
coreConfig = coreConfig.copy(
firstPartyHostsWithHeaderTypes = sanitizedHosts.associateWith { setOf(TracingHeaderType.DATADOG) }
firstPartyHostsWithHeaderTypes = sanitizedHosts.associateWith {
setOf(
TracingHeaderType.DATADOG,
TracingHeaderType.TRACECONTEXT
)
}
)
return this
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ class DefaultFirstPartyHostHeaderTypeResolver(

internal fun addKnownHosts(hosts: List<String>) {
knownHosts = knownHosts + hosts.associate {
it.lowercase(Locale.US) to setOf(TracingHeaderType.DATADOG)
it.lowercase(Locale.US) to setOf(
TracingHeaderType.DATADOG,
TracingHeaderType.TRACECONTEXT
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,12 @@ internal class ConfigurationBuilderTest {
assertThat(config.coreConfig).isEqualTo(
Configuration.DEFAULT_CORE_CONFIG.copy(
firstPartyHostsWithHeaderTypes =
hosts.associateWith { setOf(TracingHeaderType.DATADOG) }
hosts.associateWith {
setOf(
TracingHeaderType.DATADOG,
TracingHeaderType.TRACECONTEXT
)
}
)
)
assertThat(config.additionalConfig).isEmpty()
Expand All @@ -154,7 +159,8 @@ internal class ConfigurationBuilderTest {
Configuration.DEFAULT_CORE_CONFIG.copy(
firstPartyHostsWithHeaderTypes = hosts.associateWith {
setOf(
TracingHeaderType.DATADOG
TracingHeaderType.DATADOG,
TracingHeaderType.TRACECONTEXT
)
}
)
Expand All @@ -178,7 +184,12 @@ internal class ConfigurationBuilderTest {
assertThat(config.coreConfig).isEqualTo(
Configuration.DEFAULT_CORE_CONFIG.copy(
firstPartyHostsWithHeaderTypes =
hosts.associate { URL(it).host to setOf(TracingHeaderType.DATADOG) }
hosts.associate {
URL(it).host to setOf(
TracingHeaderType.DATADOG,
TracingHeaderType.TRACECONTEXT
)
}
)
)
assertThat(config.crashReportsEnabled).isTrue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,27 @@ internal class DefaultFirstPartyHostHeaderTypeResolverTest {
assertThat(testedDetector.getAllHeaderTypes()).isEqualTo(allUsedHeaderTraces)
}

@Test
fun `𝕄 use datadog and tracecontext header types 𝕎 addKnownHosts(String)`(
@StringForgery(regex = "http(s?)") scheme: String,
forge: Forge
) {
// Given
val fakeHosts = forge.aList { forge.aStringMatching(HOST_REGEX) }
val fakeUrls = fakeHosts.map { "$scheme://$it" }
testedDetector.addKnownHosts(fakeHosts)

// When + Then
val expectedHeaderTypes = setOf(
TracingHeaderType.DATADOG,
TracingHeaderType.TRACECONTEXT
)
fakeUrls.forEach {
val headerTypes = testedDetector.headerTypesForUrl(it)
assertThat(headerTypes).isEqualTo(expectedHeaderTypes)
}
}

companion object {
private const val HOST_REGEX = "([a-z][a-z0-9_~-]{3,9}\\.){1,4}[a-z][a-z0-9]{2,3}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ class AndroidTracer internal constructor(
private val logsHandler: LogHandler
) {

private var tracingHeaderTypes: Set<TracingHeaderType> = setOf(TracingHeaderType.DATADOG)
private var tracingHeaderTypes: Set<TracingHeaderType> =
setOf(TracingHeaderType.DATADOG, TracingHeaderType.TRACECONTEXT)
private var bundleWithRumEnabled: Boolean = true
private var sampleRate: Double = DEFAULT_SAMPLE_RATE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,31 @@ internal class AndroidTracerTest {
.isCloseTo(sampleRate, offset(0.005))
}

@Test
fun `it will build a valid Tracer with DATADOG and TRACECONTEXT propagation by default`() {
// Given

// When
val tracer = testedTracerBuilder
.build()
val properties = testedTracerBuilder.properties()

// Then
assertThat(tracer).isNotNull()

val injectionStyles =
properties.getProperty(Config.PROPAGATION_STYLE_INJECT).toString().split(",").toSet()
val extractionStyles =
properties.getProperty(Config.PROPAGATION_STYLE_EXTRACT).toString().split(",").toSet()

val expectedPropagationStyles =
listOf(TracingHeaderType.DATADOG, TracingHeaderType.TRACECONTEXT)
.map { it.headerType }
.toSet()
assertThat(injectionStyles).isEqualTo(expectedPropagationStyles)
assertThat(extractionStyles).isEqualTo(expectedPropagationStyles)
}

@Test
fun `it will build a valid Tracer with global tags { addGlobalTag }`(
@StringForgery operation: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,12 @@ internal constructor(
traceSampler: Sampler = RateBasedSampler(DEFAULT_TRACE_SAMPLE_RATE)
) : this(
sdkInstanceName = sdkInstanceName,
tracedHosts = firstPartyHosts.associateWith { setOf(TracingHeaderType.DATADOG) },
tracedHosts = firstPartyHosts.associateWith {
setOf(
TracingHeaderType.DATADOG,
TracingHeaderType.TRACECONTEXT
)
},
tracedRequestListener = tracedRequestListener,
rumResourceAttributesProvider = rumResourceAttributesProvider,
traceSampler = traceSampler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ internal constructor(
traceSampler: Sampler = RateBasedSampler(DEFAULT_TRACE_SAMPLE_RATE)
) : this(
sdkInstanceName,
tracedHosts.associateWith { setOf(TracingHeaderType.DATADOG) },
tracedHosts.associateWith {
setOf(
TracingHeaderType.DATADOG,
TracingHeaderType.TRACECONTEXT
)
},
tracedRequestListener,
null,
traceSampler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ internal class DatadogInterceptorTest : TracingInterceptorNotSendingSpanTest() {

// Then
assertThat(interceptor.tracedHosts.keys).containsAll(hosts)
val allHeaderTypes = interceptor.tracedHosts
.values
.fold(mutableSetOf<TracingHeaderType>()) { acc, tracingHeaderTypes ->
acc.apply { this += tracingHeaderTypes }
}
assertThat(allHeaderTypes).isEqualTo(
setOf(TracingHeaderType.DATADOG, TracingHeaderType.TRACECONTEXT)
)
assertThat(interceptor.rumResourceAttributesProvider)
.isInstanceOf(NoOpRumResourceAttributesProvider::class.java)
assertThat(interceptor.tracedRequestListener)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,14 @@ internal open class TracingInterceptorTest {

// Then
assertThat(interceptor.tracedHosts.keys).containsAll(hosts)
val allHeaderTypes = interceptor.tracedHosts
.values
.fold(mutableSetOf<TracingHeaderType>()) { acc, tracingHeaderTypes ->
acc.apply { this += tracingHeaderTypes }
}
assertThat(allHeaderTypes).isEqualTo(
setOf(TracingHeaderType.DATADOG, TracingHeaderType.TRACECONTEXT)
)
assertThat(interceptor.tracedRequestListener)
.isInstanceOf(NoOpTracedRequestListener::class.java)
assertThat(interceptor.traceSampler)
Expand Down