Skip to content

View's duplicated when using version 2.x #1614

Description

@orafaaraujo

Describe what happened
Once we updated our app to use version 2.0 (and now 2.1.0), we noticed that the views inside the sessions were duplicated.

In the duplicated view, one is full of data, like tracers, and the other is empty.

Here's our setup

fun startLibrary() {
    if (Datadog.isInitialized()) return
    val configuration = getConfiguration()
    val trackingConsent = TrackingConsent.GRANTED
    Datadog.initialize(context, configuration, trackingConsent)

    // Enable RUM
    setupRumConfiguration()

    // Setup Tracers
    setupTracesConfiguration()

    if (showLogs) {
        Datadog.setVerbosity(Log.VERBOSE)
    }
}

fun setupUserInLibrary(user: User) {
    Datadog.setUserInfo(id = user.id)
}

fun unsetUserInLibrary() {
    // Setting nothing as user info will default to null attributes
    Datadog.setUserInfo()
}

private fun setupRumConfiguration() {
    val rumConfig = RumConfiguration
        .Builder(applicationId = ...)
        .setSessionSampleRate(SampleRateProvider.sampleRate())
        .setSessionListener(object : RumSessionListener {
            override fun onSessionStarted(sessionId: String, isDiscarded: Boolean) {
                log("Datadog - sessionId = [$sessionId], isDiscarded = [$isDiscarded]")
            }
        })
        .useViewTrackingStrategy(strategy = strategyProvider.get())
        .trackUserInteractions()
        .setErrorEventMapper(ErrorEventMapper())
        .trackLongTasks()
        .build()
    Rum.enable(rumConfig)
}

private fun setupTracesConfiguration() {
    val traceConfig = TraceConfiguration.Builder().build()
    Trace.enable(traceConfig)

    val tracer = AndroidTracer.Builder().build()
    GlobalTracer.registerIfAbsent(tracer)
}

private fun getConfiguration(): Configuration {

    return Configuration
        .Builder(
            clientToken = ...,
            env = ...,
            variant = ...,
            service = ...
        )
        .useSite(site = DatadogSite.EU1)
        .setCrashReportsEnabled(crashReportsEnabled = true)
        .setFirstPartyHosts(tracedHosts)
        .build()
}
class ViewTrackingStrategyProvider {

    private val activityPredicate = object : ComponentPredicate<Activity> {
        override fun accept(component: Activity): Boolean {
            return true
        }

        override fun getViewName(component: Activity): String? {
            return component.javaClass.simpleName
        }
    }

    private val fragmentPredicate = object : ComponentPredicate<Fragment> {
        override fun accept(component: Fragment): Boolean {
            // Skip Glide Fragments
            return (component is SupportRequestManagerFragment).not()
        }

        override fun getViewName(component: Fragment): String {
            return component.javaClass.simpleName.toString()
        }
    }

    @Suppress("deprecation")
    private val fragmentLegacyPredicate = object : ComponentPredicate<android.app.Fragment> {
        override fun accept(component: android.app.Fragment): Boolean {
            return true
        }

        override fun getViewName(component: android.app.Fragment): String {
            return component.javaClass.simpleName.toString()
        }
    }

    fun get() = MixedViewTrackingStrategy(
        trackExtras = true,
        componentPredicate = activityPredicate,
        supportFragmentComponentPredicate = fragmentPredicate,
        defaultFragmentComponentPredicate = fragmentLegacyPredicate,
    )
}

Steps to reproduce the issue:
Just use the app in version 2.x and open multiple screens.

Describe what you expected:
No views are duplicated, like version 1.x.

Additional context

  • Android OS version: 33
  • Datadog SDK version: 2.1.0
  • Gradle Plugins: 7.4.2

Let me know if I can help with any extra information.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions