Skip to content

Commit 9106ea5

Browse files
RUM-3900: Remove RUM feature check in AndroidTracer builder
1 parent f37baf1 commit 9106ea5

File tree

3 files changed

+37
-32
lines changed

3 files changed

+37
-32
lines changed

features/dd-sdk-android-trace/src/main/kotlin/com/datadog/android/trace/AndroidTracer.kt

-13
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ class AndroidTracer internal constructor(
126126
fun build(): AndroidTracer {
127127
val tracingFeature = sdkCore.getFeature(Feature.TRACING_FEATURE_NAME)
128128
?.unwrap<TracingFeature>()
129-
val rumFeature = sdkCore.getFeature(Feature.RUM_FEATURE_NAME)
130129

131130
if (tracingFeature == null) {
132131
sdkCore.internalLogger.log(
@@ -136,14 +135,6 @@ class AndroidTracer internal constructor(
136135
)
137136
}
138137

139-
if (bundleWithRumEnabled && rumFeature == null) {
140-
sdkCore.internalLogger.log(
141-
InternalLogger.Level.WARN,
142-
InternalLogger.Target.USER,
143-
{ RUM_NOT_ENABLED_ERROR_MESSAGE }
144-
)
145-
bundleWithRumEnabled = false
146-
}
147138
return AndroidTracer(
148139
sdkCore,
149140
config(),
@@ -296,10 +287,6 @@ class AndroidTracer internal constructor(
296287
"You're trying to create an AndroidTracer instance, " +
297288
"but either the SDK was not initialized or the Tracing feature was " +
298289
"not registered/initialized. No tracing data will be sent."
299-
internal const val RUM_NOT_ENABLED_ERROR_MESSAGE =
300-
"You're trying to bundle the traces with a RUM context, " +
301-
"but the RUM feature was not registered/initialized. " +
302-
"No RUM context will be attached to your traces in this case."
303290
internal const val DEFAULT_SERVICE_NAME_IS_MISSING_ERROR_MESSAGE =
304291
"Default service name is missing during" +
305292
" AndroidTracer.Builder creation, did you initialize SDK?"

features/dd-sdk-android-trace/src/test/kotlin/com/datadog/android/trace/AndroidTracerTest.kt

+33-16
Original file line numberDiff line numberDiff line change
@@ -153,22 +153,6 @@ internal class AndroidTracerTest {
153153
)
154154
}
155155

156-
@Test
157-
fun `M log a developer error W buildTracer { RumFeature not enabled, bundleWithRum true }`() {
158-
// GIVEN
159-
whenever(mockSdkCore.getFeature(Feature.RUM_FEATURE_NAME)) doReturn null
160-
161-
// WHEN
162-
testedTracerBuilder.build()
163-
164-
// THEN
165-
mockInternalLogger.verifyLog(
166-
InternalLogger.Level.WARN,
167-
InternalLogger.Target.USER,
168-
AndroidTracer.RUM_NOT_ENABLED_ERROR_MESSAGE
169-
)
170-
}
171-
172156
@Test
173157
fun `M log a developer error W buildTracer { default service name not available }`() {
174158
// GIVEN
@@ -415,6 +399,8 @@ internal class AndroidTracerTest {
415399
) {
416400
// GIVEN
417401
whenever(mockSdkCore.getFeature(Feature.RUM_FEATURE_NAME)) doReturn null
402+
whenever(mockSdkCore.getFeatureContext(Feature.RUM_FEATURE_NAME)) doReturn emptyMap()
403+
418404
val tracer = AndroidTracer.Builder(mockSdkCore)
419405
.build()
420406

@@ -429,6 +415,37 @@ internal class AndroidTracerTest {
429415
.isNull()
430416
}
431417

418+
@Test
419+
fun `M inject RumContext W buildSpan { RumFeature is initialized after AndroidTracer is built }`(
420+
@StringForgery(type = StringForgeryType.ALPHA_NUMERICAL) operationName: String
421+
) {
422+
// GIVEN
423+
whenever(mockSdkCore.getFeature(Feature.RUM_FEATURE_NAME)) doReturn null
424+
whenever(mockSdkCore.getFeatureContext(Feature.RUM_FEATURE_NAME)) doReturn emptyMap()
425+
426+
val tracer = AndroidTracer.Builder(mockSdkCore)
427+
.build()
428+
429+
whenever(mockSdkCore.getFeatureContext(Feature.RUM_FEATURE_NAME)) doReturn mapOf(
430+
"application_id" to fakeRumApplicationId,
431+
"session_id" to fakeRumSessionId,
432+
"view_id" to fakeRumViewId,
433+
"action_id" to fakeRumActionId
434+
)
435+
436+
whenever(mockSdkCore.getFeature(Feature.RUM_FEATURE_NAME)) doReturn mock()
437+
438+
// WHEN
439+
val span = tracer.buildSpan(operationName).start() as DDSpan
440+
441+
// THEN
442+
val meta = span.meta
443+
assertThat(meta[LogAttributes.RUM_APPLICATION_ID])
444+
.isEqualTo(fakeRumApplicationId)
445+
assertThat(meta[LogAttributes.RUM_SESSION_ID])
446+
.isEqualTo(fakeRumSessionId)
447+
}
448+
432449
@Test
433450
fun `M not inject RumContext W buildSpan { bundleWithRum disabled }`(
434451
@StringForgery(type = StringForgeryType.ALPHA_NUMERICAL) operationName: String

sample/kotlin/src/main/kotlin/com/datadog/android/sample/SampleApplication.kt

+4-3
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,6 @@ class SampleApplication : Application() {
153153
preferences.getTrackingConsent()
154154
)
155155

156-
val rumConfig = createRumConfiguration()
157-
Rum.enable(rumConfig)
158-
159156
initializeSessionReplay()
160157
initializeLogs()
161158
initializeTraces()
@@ -169,6 +166,10 @@ class SampleApplication : Application() {
169166
.setService(BuildConfig.APPLICATION_ID)
170167
.build()
171168
)
169+
170+
val rumConfig = createRumConfiguration()
171+
Rum.enable(rumConfig)
172+
172173
GlobalOpenTelemetry.set(object : OpenTelemetry {
173174
private val tracerProvider = OtelTracerProvider.Builder()
174175
.setService(BuildConfig.APPLICATION_ID)

0 commit comments

Comments
 (0)