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

RUM-3438 Add the OkHttp Otel extensions module #2073

Conversation

mariusc83
Copy link
Member

@mariusc83 mariusc83 commented Jun 4, 2024

What does this PR do?

In this PR:

  • we are adding the dd-sdk-android-okhttp-otel module in which we will provide the Request.Builder.addParentSpan extension method
  • we are adding the use case for this new Otel extension in the Sample application

Motivation

What inspired you to submit this pull request?

Additional Notes

Anything else we should know when reviewing?

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@mariusc83 mariusc83 self-assigned this Jun 4, 2024
import io.opentelemetry.api.trace.Span
import okhttp3.Request

fun Request.Builder.addParenSpan(span: Span) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one NO !!

@mariusc83 mariusc83 force-pushed the mconstantin/rum-3438/support-parent-otel-span-in-interceptor branch 3 times, most recently from 716fa50 to 9e598bb Compare June 4, 2024 15:22
Copy link
Member

@0xnm 0xnm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approach lgtm, I left some suggestions.

@@ -61,6 +61,7 @@ dependencies {
api(libs.openTelemetryApi)
implementation(libs.kotlin)
implementation(libs.androidXAnnotation)
implementation(libs.okHttp)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one shouldn't be here, there is no code change in dd-sdk-android-trace-otel module.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes was a left over from previous try outs :)

id("com.github.ben-manes.versions")

// Tests
id("de.mobilej.unmock")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one is probably useless for this module

@@ -23,6 +23,8 @@ open class com.datadog.android.okhttp.DatadogInterceptor : com.datadog.android.o
override fun onRequestIntercepted(com.datadog.android.api.feature.FeatureSdkCore, okhttp3.Request, io.opentracing.Span?, okhttp3.Response?, Throwable?)
override fun canSendSpan(): Boolean
override fun onSdkInstanceReady(com.datadog.android.core.InternalSdkCore)
data class com.datadog.android.okhttp.DdOtelContext
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you probably can name this something like TraceContext (even without Dd prefix), because there is nothing from Otel here actually, this class only contains trace ID, span ID and sampling as int, all of these are applicable to the OpenTracing as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah was not sure about the naming

Comment on lines 13 to 15
val traceId: String,
val spanId: String,
val samplingPriority: Int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Detekt Public API check will require adding javadoc

@mariusc83 mariusc83 force-pushed the mconstantin/rum-3438/support-parent-otel-span-in-interceptor branch from 9e598bb to 178a467 Compare June 5, 2024 13:37
@mariusc83 mariusc83 marked this pull request as ready for review June 5, 2024 13:46
@mariusc83 mariusc83 requested review from a team as code owners June 5, 2024 13:46
@mariusc83 mariusc83 force-pushed the mconstantin/rum-3438/support-parent-otel-span-in-interceptor branch from 178a467 to a760ab7 Compare June 5, 2024 14:39
0xnm
0xnm previously approved these changes Jun 5, 2024
Comment on lines +35 to +39
} catch (e: NumberFormatException) {
BigInteger.ZERO
} catch (e: ArithmeticException) {
BigInteger.ZERO
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can maybe log that using InternalLogger

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was thinking about that, need to check to see if I have access to it but in the same time this problem will never arrive as I mentioned there we are the ones providing this values from the CoreTracer so there's no outside input. I don't think it is worth it to bring the internal logger here.

Copy link
Contributor

@buraizu buraizu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've suggested some very minor updates to the README.md, but mainly want to flag what appears to be a broken link

integrations/dd-sdk-android-okhttp-otel/README.md Outdated Show resolved Hide resolved
integrations/dd-sdk-android-okhttp-otel/README.md Outdated Show resolved Hide resolved
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This link doesn't seem to be working. Is there another page it should open, or is the linked page expected to be merged soon?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will be available soon, the PR is in review on the documentation repo. We will merge that PR once we release this feature. This is the PR: DataDog/documentation#23389

mariusc83 and others added 5 commits June 6, 2024 12:00
@mariusc83 mariusc83 force-pushed the mconstantin/rum-3438/support-parent-otel-span-in-interceptor branch from 87fa0b3 to dc9c63f Compare June 6, 2024 10:00
@mariusc83 mariusc83 requested a review from 0xnm June 6, 2024 11:06
0xnm
0xnm previously approved these changes Jun 6, 2024
@codecov-commenter
Copy link

codecov-commenter commented Jun 6, 2024

Codecov Report

Attention: Patch coverage is 87.50000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 67.20%. Comparing base (ee23810) to head (eb5ffe8).

Additional details and impacted files
@@                   Coverage Diff                    @@
##           feature/otel-support    #2073      +/-   ##
========================================================
- Coverage                 67.39%   67.20%   -0.19%     
========================================================
  Files                       733      736       +3     
  Lines                     27028    27046      +18     
  Branches                   4574     4576       +2     
========================================================
- Hits                      18213    18174      -39     
- Misses                     7587     7654      +67     
+ Partials                   1228     1218      -10     
Files Coverage Δ
.../kotlin/com/datadog/android/okhttp/TraceContext.kt 100.00% <100.00%> (ø)
...datadog/android/okhttp/trace/TracingInterceptor.kt 81.92% <100.00%> (-0.32%) ⬇️
...otlin/com/datadog/android/okhttp/otel/OkHttpExt.kt 75.00% <75.00%> (ø)
...og/android/okhttp/internal/otel/TraceContextExt.kt 86.67% <86.67%> (ø)

... and 35 files with indirect coverage changes

val context = span.spanContext
val prioritySampling = resolveSamplingPriority(context)
// the context will always be a TraceContext
@Suppress("UnsafeThirdPartyFunctionCall")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

If I am not mistaken, the tag method can throw an NPE. It would be better to let the comment address the exact issue we're suppressing. It's also a best practice to have the comment on the same line as the suppress as it will appear when searching for @Suppress in the codebase, e.g.:

    @Suppress("UnsafeThirdPartyFunctionCall") // NPE cannot happen here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It throws a ClassCastException if your values is not of the given type but in this case this cannot happen.


// Then
val taggedContext = request.tag(TraceContext::class.java)
assertThat(taggedContext).isNotNull()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

You can both check this and mark the result as non null for the compiler by doing checkNotNull(taggedContext). That way you can remove the ?.` in following lines

import com.datadog.tools.unit.forge.BaseConfigurator
import fr.xgouchet.elmyr.Forge

internal class Configurator : BaseConfigurator() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

As we have a Configurator in every module, it'd be better to rename this to reflect which module it's in, otherwise it's sometimes difficult to navigate to the one you want. E.g.: OkHttpConfigurator

Copy link
Contributor

@buraizu buraizu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for confirming about the link. I've left an optional suggestion to remove the tab from the new link, but feel free to ignore this suggestion if it's expected that the users should be on the Kotlin tab when opening the link.

See the dedicated [Datadog SDK Android for OpenTelemetry documentation][2] to learn how to add a parent span to network requests made by the `OkHttp` library.

[1]: https://docs.datadoghq.com/real_user_monitoring/android/advanced_configuration/#automatically-track-network-requests
[2]: https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/android?tab=kotlin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[2]: https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/android?tab=kotlin
[2]: https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/android

@mariusc83 mariusc83 requested review from xgouchet and 0xnm June 7, 2024 07:18
@mariusc83 mariusc83 merged commit 8805d24 into feature/otel-support Jun 7, 2024
22 checks passed
@mariusc83 mariusc83 deleted the mconstantin/rum-3438/support-parent-otel-span-in-interceptor branch June 7, 2024 09:43
@xgouchet xgouchet added this to the 2.11.x milestone Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants