|
| 1 | +# Migration from 1.x to 2.0 |
| 2 | + |
| 3 | +The main changes introduced in SDK 2.0 compared to 1.x are: |
| 4 | + |
| 5 | +1. All relevant products (RUM, Trace, Logs, etc.) are now extracted into different modules. That allows you to integrate only what is needed into your application. |
| 6 | + |
| 7 | +Whereas all products in version 1.x were contained in the single artifact `com.datadoghq:dd-sdk-android:x.x.x`, you now need to adopt the following artifacts: |
| 8 | + |
| 9 | +* RUM: `com.datadoghq:dd-sdk-android-rum:x.x.x` |
| 10 | +* Logs: `com.datadoghq:dd-sdk-android-logs:x.x.x` |
| 11 | +* Trace: `com.datadoghq:dd-sdk-android-trace:x.x.x` |
| 12 | +* WebView Tracking: `com.datadoghq:dd-sdk-android-webview:x.x.x` |
| 13 | +* OkHttp instrumentation: `com.datadoghq:dd-sdk-android-okhttp:x.x.x` |
| 14 | + |
| 15 | +**Note**: If you utilize NDK Crash Reporting and WebView Tracking, you also need to add RUM and/or Logs artifacts to be able to report events to RUM and/or Logs respectively. |
| 16 | + |
| 17 | +Reference to the `com.datadoghq:dd-sdk-android` artifact should be removed from your Gradle buildscript, this artifact doesn't exist anymore. |
| 18 | + |
| 19 | +**Note**: The Maven coordinates of all the other artifacts stay the same. |
| 20 | + |
| 21 | +2. Support for multiple SDK instances (see below). |
| 22 | +3. Unification of the API layout, as well as naming between iOS and Android SDKs with other Datadog products. Datadog SDK v2 is not binary compatible with Datadog SDK v1. |
| 23 | +4. Support of Android API 19 (KitKat) was dropped. The minimum SDK supported is now API 21 (Lollipop). |
| 24 | +5. Kotlin 1.7 is required in order to integrate the SDK. SDK itself is compiled with Kotlin 1.8, so compiler of Kotlin 1.6 and below cannot read SDK classes metadata. |
| 25 | + |
| 26 | +If you have an error like the following: |
| 27 | + |
| 28 | +``` |
| 29 | +A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable |
| 30 | +Duplicate class kotlin.collections.jdk8.CollectionsJDK8Kt found in modules kotlin-stdlib-1.8.10 (org.jetbrains.kotlin:kotlin-stdlib:1.8.10) and kotlin-stdlib-jdk8-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.20) |
| 31 | +``` |
| 32 | + |
| 33 | +you need to add the following rules to your buildscript (more details [here](https://stackoverflow.com/a/75298544)): |
| 34 | + |
| 35 | +```kotlin |
| 36 | +dependencies { |
| 37 | + constraints { |
| 38 | + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.10") { |
| 39 | + because("kotlin-stdlib-jdk7 is now a part of kotlin-stdlib") |
| 40 | + } |
| 41 | + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.10") { |
| 42 | + because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib") |
| 43 | + } |
| 44 | + } |
| 45 | +} |
| 46 | +``` |
| 47 | + |
| 48 | +You can always refer to this [sample application](https://github.com/DataDog/dd-sdk-android/blob/9c2d460b6b66161efb1252039a82784792958042/sample/kotlin/src/main/kotlin/com/datadog/android/sample/SampleApplication.kt) for an example on how to setup the SDK. |
| 49 | + |
| 50 | +## SDK configuration changes |
| 51 | + |
| 52 | +Better SDK granularity is achieved with the extraction of different products into independent modules. This changes the way SDK is configured. |
| 53 | + |
| 54 | +`com.datadog.android.core.configuration.Configuration.Builder` class has the following changes: |
| 55 | + |
| 56 | +* Client token, env name, variant name (default value is empty string), service name (default value is application ID taken from the manifest) should be provided in the constructor. |
| 57 | +* `com.datadog.android.core.configuration.Credentials` class which was containing parameters mentioned above is removed. |
| 58 | +* `logsEnabled`, `tracesEnabled`, `rumEnabled` are removed from the constructor in favour of the individual products configuration (see below). |
| 59 | +* `crashReportsEnabled` constructor argument is removed. You can enable/disable JVM crash reporting by using `Configuration.Builder.setCrashReportsEnabled` method, by default JVM crash reporting is enabled. |
| 60 | +* RUM, Logs, Trace products configuration methods are removed from `Configuration.Builder` in favour of the individual products configuration (see below). |
| 61 | + |
| 62 | +`Datadog.initialize` method has `Credentials` class removed from the list of the arguments. |
| 63 | + |
| 64 | +`com.datadog.android.plugin` package and all related classes/methods are removed. |
| 65 | + |
| 66 | +### Logs product changes |
| 67 | + |
| 68 | +All the classes related to the Logs product are now strictly contained in the `com.datadog.android.log` package. |
| 69 | + |
| 70 | +To use Logs product, import the following artifact: |
| 71 | + |
| 72 | +```kotlin |
| 73 | +implementation("com.datadoghq:dd-sdk-android-logs:x.x.x") |
| 74 | +``` |
| 75 | + |
| 76 | +You can enable the Logs product with the following snippet: |
| 77 | + |
| 78 | +```kotlin |
| 79 | +val logsConfig = LogsConfiguration.Builder() |
| 80 | + ... |
| 81 | + .build() |
| 82 | + |
| 83 | +Logs.enable(logsConfig) |
| 84 | + |
| 85 | +val logger = Logger.Builder() |
| 86 | + ... |
| 87 | + .build() |
| 88 | +``` |
| 89 | + |
| 90 | +API changes: |
| 91 | + |
| 92 | +|`1.x`|`2.0`| |
| 93 | +|---|---| |
| 94 | +|`com.datadog.android.core.configuration.Configuration.Builder.setLogEventMapper`|`com.datadog.android.log.LogsConfiguration.Builder.setEventMapper`| |
| 95 | +|`com.datadog.android.core.configuration.Configuration.Builder.useCustomLogsEndpoint`|`com.datadog.android.log.LogsConfiguration.Builder.useCustomEndpoint`| |
| 96 | +|`com.datadog.android.log.Logger.Builder.setLoggerName`|`com.datadog.android.log.Logger.Builder.setName`| |
| 97 | +|`com.datadog.android.log.Logger.Builder.setSampleRate`|`com.datadog.android.log.Logger.Builder.setRemoteSampleRate`| |
| 98 | +|`com.datadog.android.log.Logger.Builder.setDatadogLogsEnabled`|This method has been removed. Use `com.datadog.android.log.Logger.Builder.setRemoteSampleRate(0f)` instead to disable sending logs to Datadog.| |
| 99 | +|`com.datadog.android.log.Logger.Builder.setServiceName`|`com.datadog.android.log.Logger.Builder.setService`| |
| 100 | +|`com.datadog.android.log.Logger.Builder.setDatadogLogsMinPriority`|`com.datadog.android.log.Logger.Builder.setRemoteLogThreshold`| |
| 101 | + |
| 102 | +### Trace product changes |
| 103 | + |
| 104 | +All the classes related to the Trace product are now strictly contained in the `com.datadog.android.trace` package (this means that all classes residing in `com.datadog.android.tracing` before have moved). |
| 105 | + |
| 106 | +To use the Trace product, import the following artifact: |
| 107 | + |
| 108 | +```kotlin |
| 109 | +implementation("com.datadoghq:dd-sdk-android-trace:x.x.x") |
| 110 | +``` |
| 111 | + |
| 112 | +Enable the Trace product with the following snippet: |
| 113 | + |
| 114 | +```kotlin |
| 115 | +val traceConfig = TraceConfiguration.Builder() |
| 116 | + ... |
| 117 | + .build() |
| 118 | + |
| 119 | +Trace.enable(traceConfig) |
| 120 | + |
| 121 | +val tracer = AndroidTracer.Builder() |
| 122 | + ... |
| 123 | + .build() |
| 124 | + |
| 125 | +GlobalTracer.registerIfAbsent(tracer) |
| 126 | +``` |
| 127 | + |
| 128 | +API changes: |
| 129 | + |
| 130 | +|`1.x`|`2.0`| |
| 131 | +|---|---| |
| 132 | +|`com.datadog.android.core.configuration.Configuration.Builder.setSpanEventMapper`|`com.datadog.android.trace.TraceConfiguration.Builder.setEventMapper`| |
| 133 | +|`com.datadog.android.core.configuration.Configuration.Builder.useCustomTracesEndpoint`|`com.datadog.android.trace.TraceConfiguration.Builder.useCustomEndpoint`| |
| 134 | +|`com.datadog.android.tracing.AndroidTracer.Builder.setSamplingRate`|`com.datadog.android.trace.AndroidTracer.Builder.setSampleRate`| |
| 135 | +|`com.datadog.android.tracing.AndroidTracer.Builder.setServiceName`|`com.datadog.android.trace.AndroidTracer.Builder.setService`| |
| 136 | + |
| 137 | +### RUM product changes |
| 138 | + |
| 139 | +All classes related to the RUM product are now strictly contained in the `com.datadog.android.rum` package. |
| 140 | + |
| 141 | +To use the RUM product, import the following artifact: |
| 142 | + |
| 143 | +```kotlin |
| 144 | +implementation("com.datadoghq:dd-sdk-android-rum:x.x.x") |
| 145 | +``` |
| 146 | + |
| 147 | +The RUM product can be enabled with the following snippet: |
| 148 | + |
| 149 | +```kotlin |
| 150 | +val rumConfig = RumConfiguration.Builder(rumApplicationId) |
| 151 | + ... |
| 152 | + .build() |
| 153 | + |
| 154 | +Rum.enable(rumConfig) |
| 155 | +``` |
| 156 | + |
| 157 | +API changes: |
| 158 | + |
| 159 | +|`1.x`|`2.0`| |
| 160 | +|---|---| |
| 161 | +|`com.datadog.android.core.configuration.Configuration.Builder.setRumViewEventMapper`|`com.datadog.android.rum.RumConfiguration.Builder.setViewEventMapper`| |
| 162 | +|`com.datadog.android.core.configuration.Configuration.Builder.setRumResourceEventMapper`|`com.datadog.android.rum.RumConfiguration.Builder.setResourceEventMapper`| |
| 163 | +|`com.datadog.android.core.configuration.Configuration.Builder.setRumActionEventMapper`|`com.datadog.android.rum.RumConfiguration.Builder.setActionEventMapper`| |
| 164 | +|`com.datadog.android.core.configuration.Configuration.Builder.setRumErrorEventMapper`|`com.datadog.android.rum.RumConfiguration.Builder.setErrorEventMapper`| |
| 165 | +|`com.datadog.android.core.configuration.Configuration.Builder.setRumLongTaskEventMapper`|`com.datadog.android.rum.RumConfiguration.Builder.setLongTaskEventMapper`| |
| 166 | +|`com.datadog.android.core.configuration.Configuration.Builder.useCustomRumEndpoint`|`com.datadog.android.rum.RumConfiguration.Builder.useCustomEndpoint`| |
| 167 | +|`com.datadog.android.event.ViewEventMapper`|`com.datadog.android.rum.event.ViewEventMapper`| |
| 168 | +|`com.datadog.android.core.configuration.VitalsUpdateFrequency`|`com.datadog.android.rum.configuration.VitalsUpdateFrequency`| |
| 169 | +|`com.datadog.android.core.configuration.Configuration.Builder.trackInteractions`|`com.datadog.android.rum.RumConfiguration.Builder.trackUserInteractions`| |
| 170 | +|`com.datadog.android.core.configuration.Configuration.Builder.disableInteractionTracking`|`com.datadog.android.rum.RumConfiguration.Builder.disableUserInteractionTracking`| |
| 171 | +|`com.datadog.android.core.configuration.Configuration.Builder.sampleRumSessions`|`com.datadog.android.rum.RumConfiguration.Builder.setSessionSampleRate`| |
| 172 | +|`com.datadog.android.core.configuration.Configuration.Builder.sampleTelemetry`|`com.datadog.android.rum.RumConfiguration.Builder.setTelemetrySampleRate`| |
| 173 | +|`com.datadog.android.rum.RumMonitor.Builder`|This class has been removed. The RUM monitor is created and registered during the `Rum.enable` call.| |
| 174 | +|`com.datadog.android.rum.RumMonitor.Builder.sampleRumSessions`|`com.datadog.android.rum.RumConfiguration.Builder.setSessionSampleRate`| |
| 175 | +|`com.datadog.android.rum.RumMonitor.Builder.setSessionListener`|`com.datadog.android.rum.RumConfiguration.Builder.setSessionListener`| |
| 176 | +|`com.datadog.android.rum.RumMonitor.addUserAction`|`com.datadog.android.rum.RumMonitor.addAction`| |
| 177 | +|`com.datadog.android.rum.RumMonitor.startUserAction`|`com.datadog.android.rum.RumMonitor.startAction`| |
| 178 | +|`com.datadog.android.rum.RumMonitor.stopUserAction`|`com.datadog.android.rum.RumMonitor.stopAction`| |
| 179 | +|`com.datadog.android.rum.GlobalRum.registerIfAbsent`|This method has been removed. The RUM monitor is created and registered during the `Rum.enable` call.| |
| 180 | +|`com.datadog.android.rum.GlobalRum`|`com.datadog.android.rum.GlobalRumMonitor`| |
| 181 | +|`com.datadog.android.rum.GlobalRum.addAttribute`|`com.datadog.android.rum.RumMonitor.addAttribute`| |
| 182 | +|`com.datadog.android.rum.GlobalRum.removeAttribute`|`com.datadog.android.rum.RumMonitor.removeAttribute`| |
| 183 | + |
| 184 | +### NDK Crash Reporting changes |
| 185 | + |
| 186 | +The artifact name stays the same as before: `com.datadoghq:dd-sdk-android-ndk:x.x.x` |
| 187 | + |
| 188 | +NDK Crash Reporting can be enabled using the following snippet: |
| 189 | + |
| 190 | +```kotlin |
| 191 | +NdkCrashReports.enable() |
| 192 | +``` |
| 193 | + |
| 194 | +This configuration replaces the `com.datadog.android.core.configuration.Configuration.Builder.addPlugin` call used before. |
| 195 | + |
| 196 | +**Note**: You should have RUM and/or Logs products enabled in order to receive NDK crash reports in RUM and/or Logs. |
| 197 | + |
| 198 | +### WebView Tracking changes |
| 199 | + |
| 200 | +The artifact name stays the same as before: `com.datadoghq:dd-sdk-android-webview:x.x.x` |
| 201 | + |
| 202 | +You can enable WebView Tracking with the following snippet: |
| 203 | + |
| 204 | +```kotlin |
| 205 | +WebViewTracking.enable(webView, allowedHosts) |
| 206 | +``` |
| 207 | + |
| 208 | +**Note**: You should have RUM and/or Logs products enabled in order to receive events coming from WebView in RUM and/or Logs. |
| 209 | + |
| 210 | +API changes: |
| 211 | + |
| 212 | +|`1.x`|`2.0`| |
| 213 | +|---|---| |
| 214 | +|`com.datadog.android.webview.DatadogEventBridge`|This method became an `internal` class. Use `WebViewTracking` instead.| |
| 215 | +|`com.datadog.android.rum.webview.RumWebChromeClient`|This class was removed. Use `WebViewTracking` instead.| |
| 216 | +|`com.datadog.android.rum.webview.RumWebViewClient`|This class was removed. Use `WebViewTracking` instead.| |
| 217 | + |
| 218 | +### OkHttp Tracking changes |
| 219 | + |
| 220 | +In order to be able to use OkHttp Tracking you need to import the following artifact: |
| 221 | + |
| 222 | +```kotlin |
| 223 | +implementation("com.datadoghq:dd-sdk-android-okhttp:x.x.x") |
| 224 | +``` |
| 225 | + |
| 226 | +OkHttp instrumentation now supports the case when Datadog SDK is initialized after the OkHttp client, allowing you to create `com.datadog.android.okhttp.DatadogEventListener`, `com.datadog.android.okhttp.DatadogInterceptor`, and `com.datadog.android.okhttp.trace.TracingInterceptor` before Datadog SDK. OkHttp instrumentation starts reporting events to Datadog once Datadog SDK is initialized. |
| 227 | + |
| 228 | +Also, both `com.datadog.android.okhttp.DatadogInterceptor` and `com.datadog.android.okhttp.trace.TracingInterceptor` improve the integration with remote configuration, allowing you to control sampling dynamically. |
| 229 | +In order to do that, you need to provide your own implementation of the `com.datadog.android.core.sampling.Sampler` interface in the `com.datadog.android.okhttp.DatadogInterceptor`/`com.datadog.android.okhttp.trace.TracingInterceptor` constructor. It is queried for each request to make the sampling decision. |
| 230 | + |
| 231 | +## Using a Secondary Instance of the SDK |
| 232 | + |
| 233 | +Previously, the Datadog SDK implemented a singleton and only one SDK instance could exist in the application process. This created obstacles for use-cases like the usage of the SDK by 3rd party libraries. |
| 234 | + |
| 235 | +With version 2.0 we addressed this limitation: |
| 236 | + |
| 237 | +* It is now possible to initialize multiple instances of the SDK by associating them with a name. |
| 238 | +* Many methods of the SDK can optionally take an SDK instance as an argument. If not provided, the call is associated with the default (nameless) SDK instance. |
| 239 | + |
| 240 | +Here is an example illustrating how to initialize a secondary core instance and enable products: |
| 241 | + |
| 242 | +```kotlin |
| 243 | +val namedSdkInstance = Datadog.initialize("myInstance", context, configuration, trackingConsent) |
| 244 | +val userInfo = UserInfo(...) |
| 245 | +Datadog.setUserInfo(userInfo, sdkCore = namedSdkInstance) |
| 246 | + |
| 247 | +Logs.enable(logsConfig, namedSdkInstance) |
| 248 | +val logger = Logger.Builder(namedSdkInstance) |
| 249 | + ... |
| 250 | + .build() |
| 251 | + |
| 252 | +Trace.enable(traceConfig, namedSdkInstance) |
| 253 | +val tracer = AndroidTracer.Builder(namedSdkInstance) |
| 254 | + ... |
| 255 | + .build() |
| 256 | + |
| 257 | +Rum.enable(rumConfig, namedSdkInstance) |
| 258 | +GlobalRumMonitor.get(namedSdkInstance) |
| 259 | + |
| 260 | +NdkCrashReports.enable(namedSdkInstance) |
| 261 | + |
| 262 | +WebViewTracking.enable(webView, allowedHosts, namedSdkInstance) |
| 263 | +``` |
| 264 | + |
| 265 | +**Note**: The SDK instance name should have the same value between application runs. Storage paths for SDK events are associated with it. |
| 266 | + |
| 267 | +You can retrieve the named SDK instance by calling `Datadog.getInstance(<name>)` and use the `Datadog.isInitialized(<name>)` method to check if the particular SDK instance is initialized. |
0 commit comments