-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate Android SDK to v2 #522
Changes from all commits
8a70f02
b5bce9b
dde1092
c104c15
ab6bc2c
a5298d6
d25d243
798ae72
e36026f
23a619f
6cca754
7136dd9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -9,24 +9,51 @@ package com.datadog.reactnative | |||||
import android.content.Context | ||||||
import com.datadog.android.Datadog | ||||||
import com.datadog.android.core.configuration.Configuration | ||||||
import com.datadog.android.core.configuration.Credentials | ||||||
import com.datadog.android.log.Logs | ||||||
import com.datadog.android.log.LogsConfiguration | ||||||
import com.datadog.android.privacy.TrackingConsent | ||||||
import com.datadog.android.rum.GlobalRum | ||||||
import com.datadog.android.rum.GlobalRumMonitor | ||||||
import com.datadog.android.rum.Rum | ||||||
import com.datadog.android.rum.RumConfiguration | ||||||
import com.datadog.android.rum.RumMonitor | ||||||
import com.datadog.android.trace.Trace | ||||||
import com.datadog.android.trace.TraceConfiguration | ||||||
import com.datadog.android.webview.WebViewTracking | ||||||
|
||||||
internal class DatadogSDKWrapper : DatadogWrapper { | ||||||
|
||||||
// lazy here is on purpose. The thing is that this class will be instantiated even before | ||||||
// Sdk.initialize is called, but telemetry proxy can be created only after SDK is initialized. | ||||||
private val telemetryProxy by lazy { Datadog._internalProxy() } | ||||||
|
||||||
// lazy here is on purpose. The thing is that this class will be instantiated even before | ||||||
// Sdk.initialize is called, but webview proxy can be created only after SDK is initialized. | ||||||
private val webViewProxy by lazy { | ||||||
WebViewTracking._InternalWebViewProxy(Datadog.getInstance()) | ||||||
} | ||||||
|
||||||
override fun setVerbosity(level: Int) { | ||||||
Datadog.setVerbosity(level) | ||||||
} | ||||||
|
||||||
override fun initialize( | ||||||
context: Context, | ||||||
credentials: Credentials, | ||||||
configuration: Configuration, | ||||||
consent: TrackingConsent | ||||||
) { | ||||||
Datadog.initialize(context, credentials, configuration, consent) | ||||||
Datadog.initialize(context, configuration, consent) | ||||||
} | ||||||
|
||||||
override fun enableRum(configuration: RumConfiguration) { | ||||||
Rum.enable(configuration) | ||||||
} | ||||||
|
||||||
override fun enableLogs(configuration: LogsConfiguration) { | ||||||
Logs.enable(configuration) | ||||||
} | ||||||
|
||||||
override fun enableTrace(configuration: TraceConfiguration) { | ||||||
Trace.enable(configuration) | ||||||
} | ||||||
|
||||||
override fun setUserInfo( | ||||||
|
@@ -38,13 +65,10 @@ internal class DatadogSDKWrapper : DatadogWrapper { | |||||
Datadog.setUserInfo(id, name, email, extraInfo) | ||||||
} | ||||||
|
||||||
override fun registerRumMonitor(rumMonitor: RumMonitor) { | ||||||
GlobalRum.registerIfAbsent(rumMonitor) | ||||||
} | ||||||
|
||||||
override fun addRumGlobalAttributes(attributes: Map<String, Any?>) { | ||||||
val rumMonitor = this.getRumMonitor() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
attributes.forEach { | ||||||
GlobalRum.addAttribute(it.key, it.value) | ||||||
rumMonitor.addAttribute(it.key, it.value) | ||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -53,22 +77,38 @@ internal class DatadogSDKWrapper : DatadogWrapper { | |||||
} | ||||||
|
||||||
override fun telemetryDebug(message: String) { | ||||||
Datadog._internal._telemetry.debug(message) | ||||||
// Do not initialize the telemetry proxy before SDK is initialized | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not find an easy way to test this. I don't know what's the impact of re-creating a proxy on every telemetry and webview event, let me know if you think this logic is worth it or not. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. proxy won't be recreated on every telemetry event, because However, maybe we can optimize |
||||||
if (isInitialized()) { | ||||||
telemetryProxy._telemetry.debug(message) | ||||||
} | ||||||
} | ||||||
|
||||||
override fun telemetryError(message: String, stack: String?, kind: String?) { | ||||||
Datadog._internal._telemetry.error(message, stack, kind) | ||||||
// Do not initialize the telemetry proxy before SDK is initialized | ||||||
if (isInitialized()) { | ||||||
telemetryProxy._telemetry.error(message, stack, kind) | ||||||
} | ||||||
} | ||||||
|
||||||
override fun telemetryError(message: String, throwable: Throwable?) { | ||||||
Datadog._internal._telemetry.error(message, throwable) | ||||||
// Do not initialize the telemetry proxy before SDK is initialized | ||||||
if (isInitialized()) { | ||||||
telemetryProxy._telemetry.error(message, throwable) | ||||||
} | ||||||
} | ||||||
|
||||||
override fun consumeWebviewEvent(message: String) { | ||||||
Datadog._internal.consumeWebviewEvent(message) | ||||||
// Do not initialize the webview proxy before SDK is initialized | ||||||
if (isInitialized()) { | ||||||
webViewProxy.consumeWebviewEvent(message) | ||||||
} | ||||||
} | ||||||
|
||||||
override fun isInitialized(): Boolean { | ||||||
return Datadog.isInitialized() | ||||||
} | ||||||
|
||||||
override fun getRumMonitor(): RumMonitor { | ||||||
return GlobalRumMonitor.get() | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this option does not exist anymore and the file did not exist