-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RUM-3438 Add the OkHttp otel extensions module
- Loading branch information
Showing
19 changed files
with
243 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Built application files | ||
*.apk | ||
*.ap_ | ||
*.aab | ||
|
||
# Files for the ART/Dalvik VM | ||
*.dex | ||
|
||
# Java class files | ||
*.class | ||
|
||
# Generated files | ||
bin/ | ||
gen/ | ||
out/ | ||
|
||
# Gradle files | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Datadog SDK OpenTelemetry extensions for OkHttp | ||
|
||
See the dedicated [Datadog SDK instrumentation for OkHttp documentation][1] to learn how track network requests made by `OkHttp` library automatically. | ||
See the dedicated [Datadog SDK Android for OpenTelemetry documentation][2] to learn how to add a parent span to network requests made by `OkHttp` library. | ||
|
||
[1]: https://docs.datadoghq.com/real_user_monitoring/android/advanced_configuration/?tab=kotlin#automatically-track-network-requests | ||
[2]: https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/android?tab=kotlin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
fun okhttp3.Request.Builder.addParentSpan(io.opentelemetry.api.trace.Span): okhttp3.Request.Builder |
4 changes: 4 additions & 0 deletions
4
integrations/dd-sdk-android-okhttp-otel/api/dd-sdk-android-okhttp-otel.api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
public final class com/datadog/android/okhttp/otel/OkHttpExtKt { | ||
public static final fun addParentSpan (Lokhttp3/Request$Builder;Lio/opentelemetry/api/trace/Span;)Lokhttp3/Request$Builder; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import com.datadog.gradle.config.androidLibraryConfig | ||
import com.datadog.gradle.config.dependencyUpdateConfig | ||
import com.datadog.gradle.config.javadocConfig | ||
import com.datadog.gradle.config.junitConfig | ||
import com.datadog.gradle.config.kotlinConfig | ||
import com.datadog.gradle.config.publishingConfig | ||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget | ||
|
||
plugins { | ||
// Build | ||
id("com.android.library") | ||
kotlin("android") | ||
|
||
// Publish | ||
`maven-publish` | ||
signing | ||
id("org.jetbrains.dokka") | ||
|
||
// Analysis tools | ||
id("com.github.ben-manes.versions") | ||
|
||
// Tests | ||
id("de.mobilej.unmock") | ||
id("org.jetbrains.kotlinx.kover") | ||
|
||
// Internal Generation | ||
id("thirdPartyLicences") | ||
id("apiSurface") | ||
id("transitiveDependencies") | ||
id("binary-compatibility-validator") | ||
} | ||
|
||
android { | ||
namespace = "com.datadog.android.okhttp.otel" | ||
} | ||
|
||
dependencies { | ||
implementation(project(":integrations:dd-sdk-android-okhttp")) | ||
implementation(project(":features:dd-sdk-android-trace-otel")) | ||
implementation(libs.okHttp) | ||
implementation(libs.kotlin) | ||
|
||
testImplementation(project(":tools:unit")) { | ||
attributes { | ||
attribute( | ||
com.android.build.api.attributes.ProductFlavorAttr.of("platform"), | ||
objects.named("jvm") | ||
) | ||
} | ||
} | ||
testImplementation(libs.bundles.jUnit5) | ||
testImplementation(libs.bundles.testTools) | ||
testImplementation(libs.okHttpMock) | ||
} | ||
|
||
kotlinConfig(jvmBytecodeTarget = JvmTarget.JVM_11) | ||
androidLibraryConfig() | ||
junitConfig() | ||
javadocConfig() | ||
dependencyUpdateConfig() | ||
publishingConfig( | ||
"An OkHttp collection of extensions to be used in conjunction with OpenTelemetry Datadog SDK." | ||
) |
24 changes: 24 additions & 0 deletions
24
...s/dd-sdk-android-okhttp-otel/src/main/kotlin/com/datadog/android/okhttp/otel/OkHttpExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.okhttp.otel | ||
|
||
import com.datadog.android.okhttp.DdOtelContext | ||
import com.datadog.trace.api.sampling.PrioritySampling | ||
import io.opentelemetry.api.trace.Span | ||
import io.opentelemetry.api.trace.SpanContext | ||
import okhttp3.Request | ||
|
||
fun Request.Builder.addParentSpan(span: Span): Request.Builder { | ||
val context = span.spanContext | ||
val prioritySampling = resolveSamplingPriority(context) | ||
tag(DdOtelContext::class.java, DdOtelContext(context.traceId, context.spanId, prioritySampling)) | ||
return this | ||
} | ||
|
||
private fun resolveSamplingPriority(context: SpanContext): Int { | ||
return if (context.isSampled) PrioritySampling.SAMPLER_KEEP.toInt() else PrioritySampling.UNSET.toInt() | ||
} |
1 change: 1 addition & 0 deletions
1
...k-android-okhttp-otel/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mock-maker-inline |
14 changes: 14 additions & 0 deletions
14
integrations/dd-sdk-android-okhttp-otel/transitiveDependencies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Dependencies List | ||
|
||
com.squareup.okhttp3:okhttp:4.11.0 : 768 Kb | ||
com.squareup.okio:okio-jvm:3.2.0 : 337 Kb | ||
io.opentelemetry:opentelemetry-api:1.4.0 : 78 Kb | ||
io.opentelemetry:opentelemetry-context:1.4.0 : 42 Kb | ||
org.jetbrains.kotlin:kotlin-stdlib-common:1.8.22 : 216 Kb | ||
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.22 : 963 b | ||
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.22 : 969 b | ||
org.jetbrains.kotlin:kotlin-stdlib:1.8.22 : 1631 Kb | ||
org.jetbrains:annotations:13.0 : 17 Kb | ||
|
||
Total transitive dependencies size : 3 Mb | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...rations/dd-sdk-android-okhttp/src/main/kotlin/com/datadog/android/okhttp/DdOtelContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* 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.okhttp | ||
|
||
import com.datadog.android.lint.InternalApi | ||
|
||
@InternalApi | ||
data class DdOtelContext( | ||
val traceId: String, | ||
val spanId: String, | ||
val samplingPriority: Int | ||
) |
25 changes: 25 additions & 0 deletions
25
...android-okhttp/src/main/kotlin/com/datadog/android/okhttp/internal/otel/OtelContextExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* 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.okhttp.internal.otel | ||
|
||
import com.datadog.android.okhttp.DdOtelContext | ||
import com.datadog.opentracing.propagation.ExtractedContext | ||
import io.opentracing.SpanContext | ||
import java.math.BigInteger | ||
|
||
internal fun DdOtelContext.toOpenTracingContext(): SpanContext { | ||
val traceIdAsBigInteger = BigInteger(traceId, 16) | ||
val spanIdAsBigInteger = BigInteger(spanId, 16) | ||
return ExtractedContext( | ||
traceIdAsBigInteger, | ||
spanIdAsBigInteger, | ||
samplingPriority, | ||
null, | ||
emptyMap(), | ||
emptyMap() | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters