-
Notifications
You must be signed in to change notification settings - Fork 44
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
Conversation
290f6cf
to
e36026f
Compare
@@ -204,7 +207,6 @@ ktlint { | |||
outputToConsole.set(true) | |||
ignoreFailures.set(false) | |||
enableExperimentalRules.set(false) | |||
additionalEditorconfigFile.set(file("${project.rootDir}/script/config/.editorconfig")) |
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
@@ -53,22 +76,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 comment
The reason will be displayed to describe this comment to others. Learn more.
I did not find an easy way to test this.
It can be a bit dangerous, as if the telemetry (or webview) proxy is initialized before the SDK, then telemetry (or webview) proxy will never work.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
proxy won't be recreated on every telemetry event, because lazy
does initialization only once and then memoized value is returned each time.
However, maybe we can optimize isInitialized
call? Datadog.isInitialized
is thread-safe call, but if this safety overhead is not needed and this wrapper is called only from the single thread always, maybe we can store initialization flag directly here?
private val tracerProvider: () -> Tracer = { AndroidTracer.Builder().build() } | ||
private val tracerProvider: () -> Tracer = { | ||
val tracer = AndroidTracer.Builder().build() | ||
GlobalTracer.registerIfAbsent(tracer) |
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.
Not sure if this is needed, need to be tested in real
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.
yes, it is still needed. We cannot move it behind .enable
call as it was done for RUM, because GlobalTracer
is not owned by us (it is coming from io.opentracing
) and may be already used by the user for something else.
type: com.datadog.android.rum.RumActionType, | ||
name: kotlin.String, | ||
attributes: kotlin.collections.Map<kotlin.String, kotlin.Any?> |
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.
we shouldn't use FQCN directly in this file, we should use imports instead.
override fun addRumGlobalAttributes(attributes: Map<String, Any?>) { | ||
attributes.forEach { | ||
GlobalRum.addAttribute(it.key, it.value) | ||
this.getRumMonitor().addAttribute(it.key, it.value) |
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.
minor: we can get rumMonitor
just once, outside of forEach
val sdkConfiguration = buildSDKConfiguration(ddSdkConfiguration) | ||
val rumConfiguration = buildRUMConfiguration(ddSdkConfiguration) |
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.
just for the naming consistency:
val sdkConfiguration = buildSDKConfiguration(ddSdkConfiguration) | |
val rumConfiguration = buildRUMConfiguration(ddSdkConfiguration) | |
val sdkConfiguration = buildSdkConfiguration(ddSdkConfiguration) | |
val rumConfiguration = buildRumConfiguration(ddSdkConfiguration) |
additionalConfig?.filterValues { it != null }?.mapValues { | ||
it.value!! | ||
} | ||
?: emptyMap() |
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.
minor: a bit strange formatting here
private val tracerProvider: () -> Tracer = { AndroidTracer.Builder().build() } | ||
private val tracerProvider: () -> Tracer = { | ||
val tracer = AndroidTracer.Builder().build() | ||
GlobalTracer.registerIfAbsent(tracer) |
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.
yes, it is still needed. We cannot move it behind .enable
call as it was done for RUM, because GlobalTracer
is not owned by us (it is coming from io.opentracing
) and may be already used by the user for something else.
@@ -53,22 +76,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 comment
The reason will be displayed to describe this comment to others. Learn more.
proxy won't be recreated on every telemetry event, because lazy
does initialization only once and then memoized value is returned each time.
However, maybe we can optimize isInitialized
call? Datadog.isInitialized
is thread-safe call, but if this safety overhead is not needed and this wrapper is called only from the single thread always, maybe we can store initialization flag directly here?
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.
lgtm, I left some non-blocking suggestions
additionalConfig?.filterValues { it != null }?.mapValues { | ||
it.value!! | ||
} | ||
?: emptyMap() |
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.
additionalConfig?.filterValues { it != null }?.mapValues { | |
it.value!! | |
} | |
?: emptyMap() | |
additionalConfig?.filterValues { it != null }?.mapValues { | |
it.value!! | |
} ?: emptyMap() |
(configuration.additionalConfig?.get(DD_FIRST_PARTY_HOSTS) as? ReadableArray) | ||
?.toArrayList() as? | ||
List<ReadableMap> |
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.
(configuration.additionalConfig?.get(DD_FIRST_PARTY_HOSTS) as? ReadableArray) | |
?.toArrayList() as? | |
List<ReadableMap> | |
(configuration.additionalConfig?.get(DD_FIRST_PARTY_HOSTS) as? ReadableArray) | |
?.toArrayList() as? List<ReadableMap> |
override fun addRumGlobalAttributes(attributes: Map<String, Any?>) { | ||
val rumMonitor = this.getRumMonitor() |
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.
val rumMonitor = this.getRumMonitor() | |
val rumMonitor = getRumMonitor() |
Closing this PR to merge directly all v2 changes in #523 |
What does this PR do?
Migrate Android SDK to v2.
We always use the default instance of the SDK, later we'll see if we can allow multiple instances.
Additional Notes
iOS will follow in another PR.
Review checklist (to be filled by reviewers)