RUM-3438 Add the OkHttp Otel extensions module#2073
Conversation
| import io.opentelemetry.api.trace.Span | ||
| import okhttp3.Request | ||
|
|
||
| fun Request.Builder.addParenSpan(span: Span) { |
716fa50 to
9e598bb
Compare
0xnm
left a comment
There was a problem hiding this comment.
approach lgtm, I left some suggestions.
| api(libs.openTelemetryApi) | ||
| implementation(libs.kotlin) | ||
| implementation(libs.androidXAnnotation) | ||
| implementation(libs.okHttp) |
There was a problem hiding this comment.
this one shouldn't be here, there is no code change in dd-sdk-android-trace-otel module.
There was a problem hiding this comment.
yes was a left over from previous try outs :)
| id("com.github.ben-manes.versions") | ||
|
|
||
| // Tests | ||
| id("de.mobilej.unmock") |
There was a problem hiding this comment.
this one is probably useless for this module
| 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
yeah was not sure about the naming
| val traceId: String, | ||
| val spanId: String, | ||
| val samplingPriority: Int |
There was a problem hiding this comment.
Detekt Public API check will require adding javadoc
9e598bb to
178a467
Compare
178a467 to
a760ab7
Compare
| } catch (e: NumberFormatException) { | ||
| BigInteger.ZERO | ||
| } catch (e: ArithmeticException) { | ||
| BigInteger.ZERO | ||
| } |
There was a problem hiding this comment.
we can maybe log that using InternalLogger
There was a problem hiding this comment.
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.
buraizu
left a comment
There was a problem hiding this comment.
Thanks, I've suggested some very minor updates to the README.md, but mainly want to flag what appears to be a broken link
| 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 No newline at end of file |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
Co-authored-by: Bryce Eadie <[email protected]>
Co-authored-by: Bryce Eadie <[email protected]>
…/android/okhttp/TraceContext.kt Co-authored-by: Nikita Ogorodnikov <[email protected]>
87fa0b3 to
dc9c63f
Compare
Codecov ReportAttention: Patch coverage is
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
|
| val context = span.spanContext | ||
| val prioritySampling = resolveSamplingPriority(context) | ||
| // the context will always be a TraceContext | ||
| @Suppress("UnsafeThirdPartyFunctionCall") |
There was a problem hiding this comment.
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 hereThere was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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
buraizu
left a comment
There was a problem hiding this comment.
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 No newline at end of file |
There was a problem hiding this comment.
| [2]: https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/android?tab=kotlin | |
| [2]: https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/android |
What does this PR do?
In this PR:
dd-sdk-android-okhttp-otelmodule in which we will provide theRequest.Builder.addParentSpanextension methodMotivation
What inspired you to submit this pull request?
Additional Notes
Anything else we should know when reviewing?
Review checklist (to be filled by reviewers)