GithubHelp home page GithubHelp logo

Comments (10)

erawhctim avatar erawhctim commented on July 23, 2024 1

Alright so I've reworked the order of initialization on some of our dependencies and was able to get rid of the "not initialized" warning from my original post. Thank you!

I think I could still benefit from a callback/notification telling me when the SDK is fully initialized, due to a slightly related (but different) issue I'm seeing with the new v1.8.0 SDK. I'll log that as a separate bug ticket.

from dd-sdk-android.

mariusc83 avatar mariusc83 commented on July 23, 2024 1

@erawhctim I am not sure why do you need that. The Datadog.initialize method is synchronous meaning that it once it is executed in the stack the SDK will be initialized. Your callback is the next line in your execution stack.

from dd-sdk-android.

xgouchet avatar xgouchet commented on July 23, 2024 1

Hi @orafaaraujo, and thanks for contacting us.

Our SDK comes with an Androidx Worker which is used to upload any pending data from previous sessions. The lifecycle of this worker is not something that we control, but we know it usually is woken up by the OS shortly after the application starts. Because you're delaying the call to Datadog.initialize(), when the worker wakes up it sees that the SDK is not initialized yet and can't proceed and display this warning.

In itself it's not necessarily an issue as this worker is mostly there to upload data when the app is killed, so while you're using the app you should be able to still upload data to Datadog, but this might have some unwanted side effect, especially in case of crashes. One advice is to persist the feature flag controlling whether or no to use Datadog to initialize it earlier.

from dd-sdk-android.

xgouchet avatar xgouchet commented on July 23, 2024 1

The Worker uploads any pending data from previous sessions. Does this mean re-opening the app so the last data will be sent, even in the case of crashes?

Yes in case of a crash we ask the OS to wake up the UploadWorker to send the crash as soon as possible.

Related to app start time metrics, is this somehow affected?

It can be affected. The app start time is the duration between the beginning of the process and the moment a view is visible. If the SDK is initialized after the first view is resumed (visible to the end user) then the values detected will be off.

from dd-sdk-android.

erawhctim avatar erawhctim commented on July 23, 2024

I'm on the latest v1.8.0

from dd-sdk-android.

erawhctim avatar erawhctim commented on July 23, 2024

Upon further investigation, my setup looks very similar to what's in the sample app 🤔 So now I'm wondering if this is related to something else.

Is the error log an issue, or more of a warning? If this is just a warning, we may be able to ignore this.

from dd-sdk-android.

0xnm avatar 0xnm commented on July 23, 2024

Hello @erawhctim !

Thanks for taking the time to report the issue! Can you please check if you are using any Datadog SDK features (like DatadogInterceptor, for example, which may be active for HTTP call in Application#onCreate) before Datadog SDK initialization call? And if you have a possibility to show us a sample project where this issue is reproducible, this would be helpful. At the same time we are looking at the issue on our end.

from dd-sdk-android.

erawhctim avatar erawhctim commented on July 23, 2024

Your comment is actually quite helpful, I think that may be the exact issue I'm seeing (making an HTTP call before initializing the SDK). Let me do some digging and verify that.

I know we set up our OkHttpClient earlier in our dependency chain than when we call Datadog.initialize(), and we definitely set the DD interceptors on the client before SDK init as well.

from dd-sdk-android.

orafaaraujo avatar orafaaraujo commented on July 23, 2024

Hello,

We are using the Datadog.isInitialized() and GlobalRum.isRegistered() to not add the Interceptors until the client is ready. But I still have the error on my logcat.

We are about to add Datadog in our project and we are adding the library under a feature flag, in case we want to turn it off. So we skip the interceptors until the client is not ready. We only start the client once our feature flags are updated.

The implementation is also in a library module, not in the Application class but using Koin to provide the Context by androidContext() (I'm not sure if this is relevant, but sharing in any case).

Logs

// Skipping
I/DATADOG-LOCAL: GlobalRum.isRegistered() = [false], Datadog.isInitialized() = [false]
I/DATADOG-LOCAL: GlobalRum.isRegistered() = [false], Datadog.isInitialized() = [false]
I/DATADOG-LOCAL: GlobalRum.isRegistered() = [false], Datadog.isInitialized() = [false]
I/DATADOG-LOCAL: GlobalRum.isRegistered() = [false], Datadog.isInitialized() = [false]
I/DATADOG-LOCAL: GlobalRum.isRegistered() = [false], Datadog.isInitialized() = [false]

// Start the client
I/DATADOG-LOCAL: Datadog.initialize()
I/DATADOG-LOCAL: GlobalRum.registerIfAbsent()
W/Datadog: A RUM event was detected, but no view is active. To track views automatically, try calling the Configuration.Builder.useViewTrackingStrategy() method.
    You can also track views manually using the RumMonitor.startView() and RumMonitor.stopView() methods.

// Client ready, add the Interceptors 
I/DATADOG-LOCAL: GlobalRum.isRegistered() = [true], Datadog.isInitialized() = [true]
I/DATADOG-LOCAL: Adding: DatadogInterceptor(tracedHosts)
I/DATADOG-LOCAL: Adding: TracingInterceptor(tracedHosts)
I/DATADOG-LOCAL: Adding: DatadogEventListener.Factory()
I/DATADOG-LOCAL: GlobalRum.isRegistered() = [true], Datadog.isInitialized() = [true]
I/DATADOG-LOCAL: Adding: DatadogInterceptor(tracedHosts)
I/DATADOG-LOCAL: Adding: TracingInterceptor(tracedHosts)
I/DATADOG-LOCAL: Adding: DatadogEventListener.Factory()
W/Datadog: A RUM event was detected, but no view is active. To track views automatically, try calling the Configuration.Builder.useViewTrackingStrategy() method.
    You can also track views manually using the RumMonitor.startView() and RumMonitor.stopView() methods.

// Receiving the error
E/Datadog: Datadog has not been initialized.
    Please add the following code in your application's onCreate() method:
    val credentials = Credentials("<CLIENT_TOKEN>", "<ENVIRONMENT>", "<VARIANT>", "<APPLICATION_ID>")
    Datadog.initialize(context, credentials, configuration, trackingConsent);
W/Datadog: You added a TracingInterceptor to your OkHttpClient, but you didn't register any Tracer. We automatically created a local tracer for you.
E/Datadog: Datadog has not been initialized.
    Please add the following code in your application's onCreate() method:
    val credentials = Credentials("<CLIENT_TOKEN>", "<ENVIRONMENT>", "<VARIANT>", "<APPLICATION_ID>")
    Datadog.initialize(context, credentials, configuration, trackingConsent);
W/Datadog: You added a TracingInterceptor to your OkHttpClient, but you didn't register any Tracer. We automatically created a local tracer for you.

Besides the error, I can see the records on Datadog dashboard and everything looks fine.

Implemenation in a library module

override fun startProvider() {
    startLibrary()
    startMonitor()
}

private fun startLibrary() {
    if (Datadog.isInitialized()) return
    val credentials = getCredentials()
    val configuration = getConfiguration()
    val trackingConsent = TrackingConsent.GRANTED
    Datadog.initialize(context, credentials, configuration, trackingConsent)
    Datadog.setVerbosity(Log.VERBOSE)
}

private fun startMonitor() {
    if (GlobalRum.isRegistered()) return
    val rumMonitor = getRumMonitor()
    val userAgent = "omitted"
    GlobalRum.registerIfAbsent(rumMonitor)
    GlobalRum.addAttribute(ATTRIBUTE_USER_AGENT, userAgent)
}

private fun getCredentials(): Credentials {
    val clientToken = "omitted"
    val applicationId = "omitted"
    val environmentName = "omitted"
    val appVariantName = "omitted"
    return Credentials(clientToken, environmentName, appVariantName, applicationId)
}

private fun getConfiguration(): Configuration = Configuration
    .Builder(
        rumEnabled = true,
        crashReportsEnabled = true,
        logsEnabled = false,
        tracesEnabled = true,
    )
    .useSite(DatadogSite.EU1)
    .trackInteractions()
    .trackLongTasks()
    .useViewTrackingStrategy(ActivityViewTrackingStrategy(true))
    .trackBackgroundRumEvents(true)
    .build()

private fun getRumMonitor(): RumMonitor = RumMonitor
    .Builder()
    .sampleRumSessions(SAMPLING_RATE)
    .build()

Is there anything that I can do? Should we ignore this error?

(I'm also concerned about the A RUM event was detected, but no view is active. To track views automatically, try calling the Configuration.Builder.useViewTrackingStrategy() method. but this I can check in other issue).

Thank you in advance

from dd-sdk-android.

orafaaraujo avatar orafaaraujo commented on July 23, 2024

Hey, @xgouchet
Thank you for the clarification.

Related to the "unwanted side effect, especially in case of crashes" I have two questions

  • The Worker uploads any pending data from previous sessions. Does this mean re-opening the app so the last data will be sent, even in the case of crashes?

  • Related to app start time metrics, is this somehow affected?

Once again, thank you for the quick reply. 🙏

from dd-sdk-android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.