Skip to content

Latest commit

 

History

History
73 lines (54 loc) · 2.15 KB

README.md

File metadata and controls

73 lines (54 loc) · 2.15 KB

Datadog Integration for Coil

Getting Started

To include the Datadog integration for Coil in your project, add the following to your application's build.gradle file.

dependencies {
    implementation "com.datadoghq:dd-sdk-android:<latest-version>"
    implementation "com.datadoghq:dd-sdk-android-coil:<latest-version>"
}

Initial setup

Before using the SDK, set up the library with your application context, client token, and application ID. To generate a client token and an application ID, check UX Monitoring > RUM Applications > New Application in the Datadog dashboard.

class SampleApplication : Application() {
    override fun onCreate() {
        super.onCreate()

        val configuration = Configuration.Builder(
            rumEnabled = true,
            ...
        )
                        .trackInteractions()
                        .useViewTrackingStrategy(strategy)
                        ...
                        .build()
          val credentials = Credentials(<CLIENT_TOKEN>, <ENV_NAME>, <APP_VARIANT_NAME>, <APPLICATION_ID>)
          Datadog.initialize(this, credentials, configuration, trackingConsent)

          val monitor = RumMonitor.Builder().build()
          GlobalRum.registerIfAbsent(monitor)
   }
}

Follow Coil's API documentation to:

  • Create your own ImageLoader by providing your own OkHttpClient (configured with DatadogInterceptor).
    val imageLoader = ImageLoader.Builder(context).okHttpClient(okHttpClient).build()
    Coil.setImageLoader(imageLoader)
  • Decorate the ImageRequest.Builder with the DatadogCoilRequestListener whenever you perform an image loading request.
    imageView.load(uri){
       listener(DatadogCoilRequestListener())
    }

This automatically tracks Coil's network requests (creating both APM Traces and RUM Resource events), and listens for disk cache errors (creating RUM Error events).

Contributing

For details on contributing, read the Contributing Guide.

License

Apache License, v2.0