Skip to content

Commit

Permalink
Merge pull request #2077 from DataDog/mconstantin/merge-otel-into-dev…
Browse files Browse the repository at this point in the history
…elop

Merge Otel feature branch
  • Loading branch information
mariusc83 authored Jun 12, 2024
2 parents dc6dc20 + 3d1a62e commit f2af2ad
Show file tree
Hide file tree
Showing 469 changed files with 47,740 additions and 2,148 deletions.
32 changes: 32 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,22 @@ publish:release-okhttp:
- export OSSRH_PASSWORD=$(aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.signing.ossrh_password --with-decryption --query "Parameter.Value" --out text)
- ./gradlew :integrations:dd-sdk-android-okhttp:publishToSonatype --stacktrace --no-daemon

publish:release-okhttp-otel:
tags: [ "arch:amd64" ]
only:
- tags
- develop
image: $CI_IMAGE_DOCKER
stage: publish
timeout: 30m
script:
- aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.gradle-properties --with-decryption --query "Parameter.Value" --out text >> ./gradle.properties
- export GPG_PRIVATE_KEY=$(aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.signing.gpg_private_key --with-decryption --query "Parameter.Value" --out text)
- export GPG_PASSWORD=$(aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.signing.gpg_passphrase --with-decryption --query "Parameter.Value" --out text)
- export OSSRH_USERNAME=$(aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.signing.ossrh_username --with-decryption --query "Parameter.Value" --out text)
- export OSSRH_PASSWORD=$(aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.signing.ossrh_password --with-decryption --query "Parameter.Value" --out text)
- ./gradlew :integrations:dd-sdk-android-okhttp-otel:publishToSonatype --stacktrace --no-daemon

publish:release-trace:
tags: [ "arch:amd64" ]
only:
Expand All @@ -548,6 +564,22 @@ publish:release-trace:
- export OSSRH_PASSWORD=$(aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.signing.ossrh_password --with-decryption --query "Parameter.Value" --out text)
- ./gradlew :features:dd-sdk-android-trace:publishToSonatype --stacktrace --no-daemon

publish:release-trace-otel:
tags: [ "arch:amd64" ]
only:
- tags
- develop
image: $CI_IMAGE_DOCKER
stage: publish
timeout: 30m
script:
- aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.gradle-properties --with-decryption --query "Parameter.Value" --out text >> ./gradle.properties
- export GPG_PRIVATE_KEY=$(aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.signing.gpg_private_key --with-decryption --query "Parameter.Value" --out text)
- export GPG_PASSWORD=$(aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.signing.gpg_passphrase --with-decryption --query "Parameter.Value" --out text)
- export OSSRH_USERNAME=$(aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.signing.ossrh_username --with-decryption --query "Parameter.Value" --out text)
- export OSSRH_PASSWORD=$(aws ssm get-parameter --region us-east-1 --name ci.dd-sdk-android.signing.ossrh_password --with-decryption --query "Parameter.Value" --out text)
- ./gradlew :features:dd-sdk-android-trace-otel:publishToSonatype --stacktrace --no-daemon

publish:release-webview:
tags: [ "arch:amd64" ]
only:
Expand Down
6 changes: 6 additions & 0 deletions LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ import,androidx.vectordrawable,Apache-2.0,Copyright 2018 The Android Open Source
import,androidx.versionedparcelable,Apache-2.0,Copyright 2018 The Android Open Source Project
import,androidx.viewpager,Apache-2.0,Copyright 2018 The Android Open Source Project
import,androidx.work,Apache-2.0,Copyright 2018 The Android Open Source Project
import,com.android.tools,Apache-2.0,Copyright 2018 The Android Open Source Project
import,com.github.bumptech.glide,"Simplified BSD License/The Apache Software License, Version 2.0","Copyright 2014 Google, Inc. All rights reserved, Copyright (c) 2013. Bump Technologies Inc. All Rights Reserved."
import,com.facebook.fresco,MIT,"Copyright (c) Facebook, Inc. and its affiliates"
import,com.github.spotbugs,"GNU LESSER GENERAL PUBLIC LICENSE, Version 2.1","Copyright (C) 1991, 1999 Free Software Foundation, Inc."
import,com.google.android.material,Apache-2.0,Copyright 2018 The Android Open Source Project
import,com.google.code.gson,Apache-2.0,Copyright 2008 Google Inc
import,com.google.guava,Apache-2.0,Copyright 2009 The Guava Authors
Expand All @@ -56,6 +58,7 @@ import,com.squareup.sqldelight,Apache-2.0,"Copyright 2016 Square, Inc"
import,com.fasterxml.jackson,Apache-2.0,"Copyright 2020 Datadog, Inc."
import,com.datadoghq,Apache-2.0,"Copyright 2017 Datadog, Inc"
import,io.coil-kt,Apache-2.0,Copyright 2021 Coil Contributors
import,io.opentelemetry,Apache-2.0,Copyright 2019 The OpenTelemetry Authors
import,io.opentracing,Apache-2.0,Copyright 2016-2017 The OpenTracing Authors
import,io.opentracing.contrib,Apache-2.0,Copyright 2016-2017 The OpenTracing Authors
import,io.reactivex.rxjava3,Apache-2.0,"Copyright (c) 2016-present, RxJava Contributors"
Expand Down Expand Up @@ -90,6 +93,7 @@ import(test),com.github.xgouchet.Elmyr,MIT,Copyright 2017-2019 Xavier F. Gouchet
import(test),com.google.android.apps.common.testing.accessibility.framework,Apache-2.0,Copyright 2018 The Android Open Source Project
import(test),com.google.code.findbugs,Apache-2.0,"Copyright (C) 2006, University of Maryland"
import(test),com.parse.bolts,"BSD License","Copyright (c) Facebook, Inc. and its affiliates."
import(test),com.google.re2j,"Go License","Copyright (c) 2009 The Go Authors. All rights reserved."
import(test),greatest,ICT,"Copyright (c) 2011-2018 Scott Vokes <[email protected]>"
import(test),javax.inject,Apache-2.0,Copyright (C) 2009 The JSR-330 Expert Group
import(test),junit,EPL-1.0,Copyright © 2002-2019 JUnit
Expand All @@ -101,6 +105,7 @@ import(test),org.assertj,Apache-2.0,Copyright 2012-2019 the original author or a
import(test),org.ccil.cowan.tagsoup,Apache-2.0,Copyright 2002-2008 by John Cowan
import(test),org.hamcrest,BSD-3-Clause,Copyright (c) 2000-2015 www.hamcrest.org
import(test),org.jacoco,EPL-2.0,"Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors"
import(test),org.jctools,"Apache-2.0","Copyright 2023 Datadog, Inc."
import(test),org.junit,EPL-2.0,Copyright 2015-2019 the original author or authors
import(test),org.junit.jupiter,EPL-2.0,Copyright 2015-2019 the original author or authors
import(test),org.junit.platform,EPL-2.0,Copyright 2015-2019 the original author or authors
Expand All @@ -111,6 +116,7 @@ import(test),org.objenesis,Apache-2.0,"Copyright (c) 2003-2013, Objenesis Team a
import(test),org.opentest4j,Apache-2.0,Copyright 2015-2018 the original author or authors
import(test),org.robolectric,Apache-2.0,Copyright 2015-2018 the original author or authors
import(test),org.sonatype.oss,Apache-2.0,"Copyright (c) 2008-present Sonatype, Inc."
import(test),uk.org.webcompere,MIT,Copyright (c) 2020 Ashley Frieze (c) 2017 Stefan Birkner
build,androidx.compose.compiler,Apache-2.0,Copyright 2019 The Android Open Source Project
build,ch.qos.logback,EPL-1.0,"Copyright (C) 1999-2015, QOS.ch"
build,com.android.tools.build,Apache-2.0,Copyright (C) 2013 The Android Open Source Project
Expand Down
14 changes: 11 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,19 @@ registerSubModuleAggregationTask("assembleLibrariesDebug", "assembleDebug")
registerSubModuleAggregationTask("assembleLibrariesRelease", "assembleRelease")

registerSubModuleAggregationTask("unitTestRelease", "testReleaseUnitTest")
registerSubModuleAggregationTask("unitTestReleaseFeatures", "testReleaseUnitTest", ":features:")
registerSubModuleAggregationTask(
"unitTestReleaseFeatures",
"testReleaseUnitTest",
":features:"
)
registerSubModuleAggregationTask("unitTestReleaseIntegrations", "testReleaseUnitTest", ":integrations:")

registerSubModuleAggregationTask("unitTestDebug", "testDebugUnitTest")
registerSubModuleAggregationTask("unitTestDebugFeatures", "testDebugUnitTest", ":features:")
registerSubModuleAggregationTask(
"unitTestDebugFeatures",
"testDebugUnitTest",
":features:"
)
registerSubModuleAggregationTask("unitTestDebugIntegrations", "testDebugUnitTest", ":integrations:")

tasks.register("assembleSampleRelease") {
Expand Down Expand Up @@ -141,7 +149,7 @@ tasks.register("buildNdkIntegrationTestsArtifacts") {
dependsOn(":instrumented:integration:assembleDebug")
}

nightlyTestsCoverageConfig(threshold = 0.85f)
nightlyTestsCoverageConfig(threshold = 0.81f)

tasks.register("printSdkDebugRuntimeClasspath") {
val fileTreeClassPathCollector = UnionFileTree(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ fun Project.registerSubModuleAggregationTask(
subModuleTaskName: String,
subModulePathPrefix: String = ":",
subModuleNamePrefix: String = "dd-sdk-android-",
exceptions: Set<String> = emptySet(),
additionalConfiguration: Task.() -> Unit = {}
) {
tasks.register(taskName) {
project.subprojects.forEach { subProject ->
println("SubProject ${subProject.name} / ${subProject.path}")
if (subProject.name.startsWith(subModuleNamePrefix) &&
if (!exceptions.contains(subProject.name) &&
subProject.name.startsWith(subModuleNamePrefix) &&
subProject.path.startsWith(subModulePathPrefix)
) {
dependsOn("${subProject.path}:$subModuleTaskName")
Expand Down
20 changes: 19 additions & 1 deletion detekt_custom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ datadog:
- "java.lang.System.arraycopy(kotlin.Any, kotlin.Int, kotlin.Any, kotlin.Int, kotlin.Int):java.lang.IndexOutOfBoundsException,java.lang.ArrayStoreException,java.lang.NullPointerException"
- "java.lang.System.loadLibrary(kotlin.String?):java.lang.SecurityException,java.lang.UnsatisfiedLinkError,java.lang.NullPointerException"
- "java.lang.reflect.Field.get(kotlin.Any):java.lang.IllegalAccessException,java.lang.IllegalArgumentException,java.lang.NullPointerException,java.lang.ExceptionInInitializerError"
- "java.math.BigInteger.constructor(kotlin.String?, kotlin.Int):java.lang.NumberFormatException,java.lang.ArithmeticException"
- "java.net.URL.constructor(kotlin.String?):java.net.MalformedURLException"
- "java.security.MessageDigest.getInstance(kotlin.String?):java.security.NoSuchAlgorithmException"
- "java.text.SimpleDateFormat.constructor(kotlin.String, java.util.Locale):java.lang.NullPointerException"
Expand All @@ -258,7 +259,6 @@ datadog:
- "kotlin.String.takeLast(kotlin.Int):kotlin.IllegalArgumentException"
- "kotlin.String.toLong():java.lang.NumberFormatException"
- "kotlin.String.format(kotlin.Array):java.util.IllegalFormatException"
- "kotlin.String.takeLast(kotlin.Int):java.lang.IllegalArgumentException"
- "kotlin.ByteArray.copyOf(kotlin.Int):java.lang.NegativeArraySizeException"
- "kotlin.ByteArray.copyOfRange(kotlin.Int, kotlin.Int):java.lang.IndexOutOfBoundsException,java.lang.IllegalArgumentException"
- "kotlin.ByteArray.get(kotlin.Int):java.lang.IndexOutOfBoundsException"
Expand Down Expand Up @@ -296,6 +296,7 @@ datadog:
- "okhttp3.Request.Builder.post(okhttp3.RequestBody):java.lang.NullPointerException,java.lang.IllegalArgumentException"
- "okhttp3.Request.Builder.method(kotlin.String, okhttp3.RequestBody?):java.lang.NullPointerException,java.lang.IllegalArgumentException"
- "okhttp3.Request.Builder.tag(java.lang.Class, io.opentracing.Span?):java.lang.NullPointerException"
- "okhttp3.Request.Builder.tag(java.lang.Class, com.datadog.android.okhttp.TraceContext?):java.lang.ClassCastException"
- "okhttp3.Request.Builder.url(kotlin.String):java.lang.NullPointerException,java.lang.IllegalArgumentException"
- "okhttp3.Interceptor.Chain.proceed(okhttp3.Request):java.io.IOException"
- "okhttp3.RequestBody.writeTo(okio.BufferedSink):java.io.IOException"
Expand Down Expand Up @@ -894,6 +895,7 @@ datadog:
- "kotlin.collections.MutableList.isNullOrEmpty()"
- "kotlin.collections.MutableList.iterator()"
- "kotlin.collections.MutableList.joinToString(kotlin.CharSequence, kotlin.CharSequence, kotlin.CharSequence, kotlin.Int, kotlin.CharSequence, kotlin.Function1?)"
- "kotlin.collections.MutableList.map(kotlin.Function1)"
- "kotlin.collections.MutableList.remove(java.io.File)"
- "kotlin.collections.MutableList.remove(java.lang.ref.WeakReference)"
- "kotlin.collections.MutableList.removeAll(kotlin.Function1)"
Expand Down Expand Up @@ -1043,6 +1045,7 @@ datadog:
- "kotlin.math.max(kotlin.Long, kotlin.Long)"
- "kotlin.math.min(kotlin.Double, kotlin.Double)"
- "kotlin.math.sqrt(kotlin.Double)"
- "kotlin.String.trim(kotlin.Function1)"
# endregion
# region Kotlin Tuples
- "kotlin.Pair.constructor(com.datadog.android.sessionreplay.internal.utils.SessionReplayRumContext, com.google.gson.JsonArray)"
Expand Down Expand Up @@ -1093,6 +1096,7 @@ datadog:
- "kotlin.String.substringAfter(kotlin.Char, kotlin.String)"
- "kotlin.String.substringAfterLast(kotlin.Char, kotlin.String)"
- "kotlin.String.substringBefore(kotlin.Char, kotlin.String)"
- "kotlin.String.takeLeastSignificant64Bits()"
- "kotlin.String.toByteArray(java.nio.charset.Charset) "
- "kotlin.String.toByteArray(java.nio.charset.Charset)"
- "kotlin.String.toDoubleOrNull()"
Expand Down Expand Up @@ -1226,6 +1230,20 @@ datadog:
- "io.opentracing.util.GlobalTracer.get()"
- "io.opentracing.util.GlobalTracer.isRegistered()"
# endregion
# region Opentelemetry
- "io.opentelemetry.api.trace.Span.getInvalid()"
- "io.opentelemetry.api.trace.TracerBuilder.build()"
- "io.opentelemetry.api.trace.SpanBuilder.setAttribute(kotlin.String?, kotlin.String?)"
- "io.opentelemetry.api.trace.TracerBuilder.setInstrumentationVersion(kotlin.String?)"
- "io.opentelemetry.api.trace.TracerProvider.noop()"
- "io.opentelemetry.context.Context.get(io.opentelemetry.context.ContextKey?)"
- "io.opentelemetry.context.Context.makeCurrent()"
- "io.opentelemetry.context.Context.root()"
- "io.opentelemetry.context.ContextStorage.addWrapper(java.util.function.Function?)"
- "io.opentelemetry.context.ContextStorage.attach(io.opentelemetry.context.Context?)"
- "io.opentelemetry.context.ContextStorage.current()"
- "io.opentelemetry.context.Scope.close()"
# endregion
# region RxJava
- "io.reactivex.rxjava3.core.Completable.doOnError(io.reactivex.rxjava3.functions.Consumer?)"
- "io.reactivex.rxjava3.core.Flowable.doOnError(io.reactivex.rxjava3.functions.Consumer?)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,10 @@ internal class TelemetryEventHandler(
}

val rumContext = datadogContext.rumContext()

val traceContext = sdkCore.getFeatureContext(Feature.TRACING_FEATURE_NAME)
val tracerApi = resolveTracerApi(traceContext)
val openTelemetryApiVersion = resolveOpenTelemetryApiVersion(tracerApi, traceContext)
val useTracing = (traceFeature != null && tracerApi != null)
return TelemetryConfigurationEvent(
dd = TelemetryConfigurationEvent.Dd(),
date = timestamp,
Expand Down Expand Up @@ -300,7 +303,9 @@ internal class TelemetryEventHandler(
batchSize = coreConfiguration.batchSize,
batchUploadFrequency = coreConfiguration.batchUploadFrequency,
mobileVitalsUpdatePeriod = rumConfig?.vitalsMonitorUpdateFrequency?.periodInMs,
useTracing = traceFeature != null && isGlobalTracerRegistered(),
useTracing = useTracing,
tracerApi = tracerApi?.name,
tracerApiVersion = openTelemetryApiVersion,
trackNetworkRequests = trackNetworkRequests,
sessionReplaySampleRate = sessionReplaySampleRate,
defaultPrivacyLevel = sessionReplayPrivacy,
Expand Down Expand Up @@ -339,13 +344,38 @@ internal class TelemetryEventHandler(
}
}

private fun isOpenTelemetryRegistered(traceContext: Map<String, Any?>): Boolean {
return traceContext[IS_OPENTELEMETRY_ENABLED_CONTEXT_KEY] as? Boolean ?: false
}

private fun resolveTracerApi(traceContext: Map<String, Any?>): TracerApi? {
return when {
isOpenTelemetryRegistered(traceContext) -> TracerApi.OpenTelemetry
isGlobalTracerRegistered() -> TracerApi.OpenTracing
else -> null
}
}

private fun resolveOpenTelemetryApiVersion(tracerApi: TracerApi?, traceContext: Map<String, Any?>): String? {
return if (tracerApi == TracerApi.OpenTelemetry) {
traceContext[OPENTELEMETRY_API_VERSION_CONTEXT_KEY] as? String
} else {
null
}
}

private fun DatadogContext.rumContext(): RumContext {
val rumContext = featuresContext[Feature.RUM_FEATURE_NAME].orEmpty()
return RumContext.fromFeatureContext(rumContext)
}

// endregion

internal enum class TracerApi {
OpenTelemetry,
OpenTracing
}

companion object {
const val MAX_EVENTS_PER_SESSION = 100
const val DEFAULT_CONFIGURATION_SAMPLE_RATE = 20f
Expand All @@ -354,6 +384,8 @@ internal class TelemetryEventHandler(
const val MAX_EVENT_NUMBER_REACHED_MESSAGE =
"Max number of telemetry events per session reached, rejecting."
const val TELEMETRY_SERVICE_NAME = "dd-sdk-android"
internal const val IS_OPENTELEMETRY_ENABLED_CONTEXT_KEY = "is_opentelemetry_enabled"
internal const val OPENTELEMETRY_API_VERSION_CONTEXT_KEY = "opentelemetry_api_version"
internal const val SESSION_REPLAY_SAMPLE_RATE_KEY = "session_replay_sample_rate"
internal const val SESSION_REPLAY_PRIVACY_KEY = "session_replay_privacy"
internal const val SESSION_REPLAY_MANUAL_RECORDING_KEY =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,26 @@ internal class TelemetryConfigurationEventAssert(actual: TelemetryConfigurationE
return this
}

fun hasTracerApi(tracerApi: String?): TelemetryConfigurationEventAssert {
assertThat(actual.telemetry.configuration.tracerApi)
.overridingErrorMessage(
"Expected event data to have telemetry.configuration.tracerApi $tracerApi " +
"but was ${actual.telemetry.configuration.tracerApi}"
)
.isEqualTo(tracerApi)
return this
}

fun hasTracerApiVersion(tracerApiVersion: String?): TelemetryConfigurationEventAssert {
assertThat(actual.telemetry.configuration.tracerApiVersion)
.overridingErrorMessage(
"Expected event data to have telemetry.configuration.tracerApiVersion $tracerApiVersion " +
"but was ${actual.telemetry.configuration.tracerApiVersion}"
)
.isEqualTo(tracerApiVersion)
return this
}

fun hasBatchSize(expected: Long?): TelemetryConfigurationEventAssert {
assertThat(actual.telemetry.configuration.batchSize)
.overridingErrorMessage(
Expand Down
Loading

0 comments on commit f2af2ad

Please sign in to comment.