Skip to content
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

RUMM-2380: Enable custom application version support #1020

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dd-sdk-android/apiSurface
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class com.datadog.android._InternalProxy
fun error(String, Throwable? = null)
fun error(String, String?, String?)
val _telemetry: _TelemetryProxy
fun setCustomAppVersion(String)
enum com.datadog.android.core.configuration.BatchSize
constructor(Long)
- SMALL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ object Datadog {
)
}

@Suppress("ComplexMethod")
private fun applyAdditionalConfiguration(
additionalConfiguration: Map<String, Any>
) {
Expand All @@ -368,6 +369,12 @@ object Datadog {
CoreFeature.sdkVersion = it
}
}

additionalConfiguration[DD_APP_VERSION_TAG]?.let {
if (it is String && it.isNotBlank()) {
CoreFeature.packageVersionProvider.version = it
}
}
}

@Suppress("ThrowingInternalException")
Expand Down Expand Up @@ -426,6 +433,7 @@ object Datadog {

internal const val DD_SOURCE_TAG = "_dd.source"
internal const val DD_SDK_VERSION_TAG = "_dd.sdk_version"
internal const val DD_APP_VERSION_TAG = "_dd.version"

// endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package com.datadog.android

import com.datadog.android.core.internal.CoreFeature
import com.datadog.android.telemetry.internal.Telemetry

/**
Expand All @@ -22,16 +23,12 @@ import com.datadog.android.telemetry.internal.Telemetry
"UndocumentedPublicClass",
"UndocumentedPublicFunction",
"UndocumentedPublicProperty",
"ClassName",
"ClassNaming",
"VariableNaming"
)
class _InternalProxy {
class _TelemetryProxy {
private val telemetry: Telemetry

internal constructor(telemetry: Telemetry) {
this.telemetry = telemetry
}
class _InternalProxy internal constructor(telemetry: Telemetry) {
class _TelemetryProxy internal constructor(private val telemetry: Telemetry) {

fun debug(message: String) {
telemetry.debug(message)
Expand All @@ -46,9 +43,9 @@ class _InternalProxy {
}
}

val _telemetry: _TelemetryProxy
val _telemetry: _TelemetryProxy = _TelemetryProxy(telemetry)

internal constructor(telemetry: Telemetry) {
_telemetry = _TelemetryProxy(telemetry)
fun setCustomAppVersion(version: String) {
CoreFeature.packageVersionProvider.version = version
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ import com.datadog.android.core.internal.privacy.ConsentProvider
import com.datadog.android.core.internal.privacy.NoOpConsentProvider
import com.datadog.android.core.internal.privacy.TrackingConsentProvider
import com.datadog.android.core.internal.system.AndroidInfoProvider
import com.datadog.android.core.internal.system.AppVersionProvider
import com.datadog.android.core.internal.system.BroadcastReceiverSystemInfoProvider
import com.datadog.android.core.internal.system.DefaultAndroidInfoProvider
import com.datadog.android.core.internal.system.DefaultAppVersionProvider
import com.datadog.android.core.internal.system.NoOpAndroidInfoProvider
import com.datadog.android.core.internal.system.NoOpAppVersionProvider
import com.datadog.android.core.internal.system.NoOpSystemInfoProvider
import com.datadog.android.core.internal.system.SystemInfoProvider
import com.datadog.android.core.internal.time.KronosTimeProvider
Expand Down Expand Up @@ -134,7 +137,7 @@ internal object CoreFeature {

internal var clientToken: String = ""
internal var packageName: String = ""
internal var packageVersion: String = ""
internal var packageVersionProvider: AppVersionProvider = NoOpAppVersionProvider()
internal var serviceName: String = ""
internal var sourceName: String = DEFAULT_SOURCE_NAME
internal var sdkVersion: String = DEFAULT_SDK_VERSION
Expand Down Expand Up @@ -259,7 +262,7 @@ internal object CoreFeature {
timeProvider,
sdkVersion,
envName,
packageVersion
packageVersionProvider
),
NdkCrashLogDeserializer(sdkLogger),
RumEventDeserializer(),
Expand Down Expand Up @@ -306,12 +309,14 @@ internal object CoreFeature {
devLogger.e("Unable to read your application's version name", e)
null
}
packageVersion = packageInfo?.let {
// we need to use the deprecated method because getLongVersionCode method is only
// available from API 28 and above
@Suppress("DEPRECATION")
it.versionName ?: it.versionCode.toString()
} ?: DEFAULT_APP_VERSION
packageVersionProvider = DefaultAppVersionProvider(
packageInfo?.let {
// we need to use the deprecated method because getLongVersionCode method is only
// available from API 28 and above
@Suppress("DEPRECATION")
it.versionName ?: it.versionCode.toString()
} ?: DEFAULT_APP_VERSION
)
clientToken = credentials.clientToken
serviceName = credentials.serviceName ?: appContext.packageName
rumApplicationId = credentials.rumApplicationId
Expand Down Expand Up @@ -468,7 +473,7 @@ internal object CoreFeature {
private fun cleanupApplicationInfo() {
clientToken = ""
packageName = ""
packageVersion = ""
packageVersionProvider = NoOpAppVersionProvider()
serviceName = ""
sourceName = DEFAULT_SOURCE_NAME
rumApplicationId = null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2016-Present Datadog, Inc.
*/

package com.datadog.android.core.internal.system

internal interface AppVersionProvider {
var version: String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2016-Present Datadog, Inc.
*/

package com.datadog.android.core.internal.system

import java.util.concurrent.atomic.AtomicReference

internal class DefaultAppVersionProvider(initialVersion: String) : AppVersionProvider {

private val value: AtomicReference<String>

override var version: String
get() = value.get()
set(value) {
this.value.set(value)
}

init {
this.value = AtomicReference(initialVersion)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2016-Present Datadog, Inc.
*/

package com.datadog.android.core.internal.system

internal class NoOpAppVersionProvider : AppVersionProvider {
@Suppress("UNUSED_PARAMETER")
override var version: String
get() = ""
set(value) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ internal object CrashReportsFeature : SdkFeature<LogEvent, Configuration.Feature
CoreFeature.timeProvider,
CoreFeature.sdkVersion,
CoreFeature.envName,
CoreFeature.packageVersion
CoreFeature.packageVersionProvider
),
writer = persistenceStrategy.getWriter(),
appContext = appContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ internal constructor(internal var handler: LogHandler) {
CoreFeature.timeProvider,
CoreFeature.sdkVersion,
CoreFeature.envName,
CoreFeature.packageVersion
CoreFeature.packageVersionProvider
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package com.datadog.android.log.internal.domain

import com.datadog.android.core.internal.net.info.NetworkInfoProvider
import com.datadog.android.core.internal.system.AppVersionProvider
import com.datadog.android.core.internal.time.TimeProvider
import com.datadog.android.core.model.NetworkInfo
import com.datadog.android.core.model.UserInfo
Expand All @@ -26,7 +27,7 @@ internal class LogGenerator(
internal val timeProvider: TimeProvider,
internal val sdkVersion: String,
envName: String,
appVersion: String
internal val appVersionProvider: AppVersionProvider
) {

private val simpleDateFormat = buildLogDateFormat()
Expand All @@ -37,11 +38,15 @@ internal class LogGenerator(
null
}

private val appVersionTag = if (appVersion.isNotEmpty()) {
"${LogAttributes.APPLICATION_VERSION}:$appVersion"
} else {
null
}
private val appVersionTag: String?
get() {
val appVersion = appVersionProvider.version
return if (appVersion.isNotEmpty()) {
"${LogAttributes.APPLICATION_VERSION}:$appVersion"
} else {
null
}
}

@Suppress("LongParameterList")
fun generateLog(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,11 @@ import com.datadog.android.rum.internal.monitor.AdvancedRumMonitor
"UndocumentedPublicClass",
"UndocumentedPublicFunction",
"UndocumentedPublicProperty",
"ClassName",
"ClassNaming",
"VariableNaming"
)
class _RumInternalProxy {
private val rumMonitor: AdvancedRumMonitor

internal constructor(rumMonitor: AdvancedRumMonitor) {
this.rumMonitor = rumMonitor
}
class _RumInternalProxy internal constructor(private val rumMonitor: AdvancedRumMonitor) {

fun addLongTask(durationNs: Long, target: String) {
rumMonitor.addLongTask(durationNs, target)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ internal object RumFeature : SdkFeature<Any, Configuration.Feature.RUM>() {
CoreFeature.sourceName,
CoreFeature.sdkVersion,
CoreFeature.okHttpClient,
CoreFeature.androidInfoProvider
CoreFeature.androidInfoProvider,
CoreFeature.packageVersionProvider
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package com.datadog.android.rum.internal.net
import com.datadog.android.core.internal.CoreFeature
import com.datadog.android.core.internal.net.DataOkHttpUploaderV2
import com.datadog.android.core.internal.system.AndroidInfoProvider
import com.datadog.android.core.internal.system.AppVersionProvider
import com.datadog.android.core.internal.utils.sdkLogger
import com.datadog.android.rum.RumAttributes
import okhttp3.Call
Expand All @@ -19,7 +20,8 @@ internal open class RumOkHttpUploaderV2(
source: String,
sdkVersion: String,
callFactory: Call.Factory,
androidInfoProvider: AndroidInfoProvider
androidInfoProvider: AndroidInfoProvider,
private val appVersionProvider: AppVersionProvider
) : DataOkHttpUploaderV2(
buildUrl(endpoint, TrackType.RUM),
clientToken,
Expand All @@ -31,20 +33,21 @@ internal open class RumOkHttpUploaderV2(
sdkLogger
) {

private val tags: String by lazy {
val elements = mutableListOf(
"${RumAttributes.SERVICE_NAME}:${CoreFeature.serviceName}",
"${RumAttributes.APPLICATION_VERSION}:${CoreFeature.packageVersion}",
"${RumAttributes.SDK_VERSION}:$sdkVersion",
"${RumAttributes.ENV}:${CoreFeature.envName}"
)
private val tags: String
get() {
val elements = mutableListOf(
"${RumAttributes.SERVICE_NAME}:${CoreFeature.serviceName}",
"${RumAttributes.APPLICATION_VERSION}:${appVersionProvider.version}",
"${RumAttributes.SDK_VERSION}:$sdkVersion",
"${RumAttributes.ENV}:${CoreFeature.envName}"
)

if (CoreFeature.variant.isNotEmpty()) {
elements.add("${RumAttributes.VARIANT}:${CoreFeature.variant}")
}
if (CoreFeature.variant.isNotEmpty()) {
elements.add("${RumAttributes.VARIANT}:${CoreFeature.variant}")
}

elements.joinToString(",")
}
return elements.joinToString(",")
}

// region DataOkHttpUploaderV2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ internal object TracingFeature : SdkFeature<DDSpan, Configuration.Feature.Tracin
CoreFeature.timeProvider,
CoreFeature.networkInfoProvider,
CoreFeature.userInfoProvider,
CoreFeature.packageVersionProvider,
CoreFeature.envName,
sdkLogger,
configuration.spanEventMapper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.datadog.android.core.internal.persistence.file.advanced.FeatureFileOr
import com.datadog.android.core.internal.persistence.file.batch.BatchFileHandler
import com.datadog.android.core.internal.persistence.file.batch.BatchFilePersistenceStrategy
import com.datadog.android.core.internal.privacy.ConsentProvider
import com.datadog.android.core.internal.system.AppVersionProvider
import com.datadog.android.core.internal.time.TimeProvider
import com.datadog.android.event.SpanEventMapper
import com.datadog.android.log.Logger
Expand All @@ -33,6 +34,7 @@ internal class TracesFilePersistenceStrategy(
timeProvider: TimeProvider,
networkInfoProvider: NetworkInfoProvider,
userInfoProvider: UserInfoProvider,
appVersionProvider: AppVersionProvider,
envName: String,
internalLogger: Logger,
spanEventMapper: SpanEventMapper,
Expand All @@ -50,7 +52,8 @@ internal class TracesFilePersistenceStrategy(
DdSpanToSpanEventMapper(
timeProvider,
networkInfoProvider,
userInfoProvider
userInfoProvider,
appVersionProvider
),
SpanEventMapperWrapper(spanEventMapper),
SpanEventSerializer(envName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package com.datadog.android.tracing.internal.domain.event
import com.datadog.android.core.internal.CoreFeature
import com.datadog.android.core.internal.Mapper
import com.datadog.android.core.internal.net.info.NetworkInfoProvider
import com.datadog.android.core.internal.system.AppVersionProvider
import com.datadog.android.core.internal.time.TimeProvider
import com.datadog.android.core.internal.utils.toHexString
import com.datadog.android.core.model.NetworkInfo
Expand All @@ -19,7 +20,8 @@ import com.datadog.opentracing.DDSpan
internal class DdSpanToSpanEventMapper(
private val timeProvider: TimeProvider,
private val networkInfoProvider: NetworkInfoProvider,
private val userInfoProvider: UserInfoProvider
private val userInfoProvider: UserInfoProvider,
private val appVersionProvider: AppVersionProvider
) : Mapper<DDSpan, SpanEvent> {

// region Mapper
Expand Down Expand Up @@ -71,7 +73,7 @@ internal class DdSpanToSpanEventMapper(
additionalProperties = userInfo.additionalProperties
)
return SpanEvent.Meta(
version = CoreFeature.packageVersion,
version = appVersionProvider.version,
dd = SpanEvent.Dd(source = CoreFeature.sourceName),
span = SpanEvent.Span(),
tracer = SpanEvent.Tracer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ internal constructor(
WebViewLogEventConsumer(
userLogsWriter = WebViewLogsFeature.persistenceStrategy.getWriter(),
rumContextProvider = contextProvider,
timeProvider = CoreFeature.timeProvider
timeProvider = CoreFeature.timeProvider,
appVersionProvider = CoreFeature.packageVersionProvider
)
)
}
Expand Down
Loading