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>"
}
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 withDatadogInterceptor
).
val imageLoader = ImageLoader.Builder(context).okHttpClient(okHttpClient).build()
Coil.setImageLoader(imageLoader)
- Decorate the
ImageRequest.Builder
with theDatadogCoilRequestListener
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).
For details on contributing, read the Contributing Guide.