-
Notifications
You must be signed in to change notification settings - Fork 61
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
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one NO !!
716fa50
to
9e598bb
Compare
There was a problem hiding this 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
val traceId: String, | ||
val spanId: String, | ||
val samplingPriority: Int |
There was a problem hiding this comment.
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
9e598bb
to
178a467
Compare
178a467
to
a760ab7
Compare
...ions/dd-sdk-android-okhttp-otel/src/main/kotlin/com/datadog/android/okhttp/otel/OkHttpExt.kt
Outdated
Show resolved
Hide resolved
integrations/dd-sdk-android-okhttp/src/main/kotlin/com/datadog/android/okhttp/TraceContext.kt
Outdated
Show resolved
Hide resolved
} catch (e: NumberFormatException) { | ||
BigInteger.ZERO | ||
} catch (e: ArithmeticException) { | ||
BigInteger.ZERO | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this 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
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
Co-authored-by: Bryce Eadie <bryce.eadie@datadoghq.com>
Co-authored-by: Bryce Eadie <bryce.eadie@datadoghq.com>
…/android/okhttp/TraceContext.kt Co-authored-by: Nikita Ogorodnikov <4046447+0xnm@users.noreply.github.com>
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
|
...ions/dd-sdk-android-okhttp-otel/src/main/kotlin/com/datadog/android/okhttp/otel/OkHttpExt.kt
Outdated
Show resolved
Hide resolved
val context = span.spanContext | ||
val prioritySampling = resolveSamplingPriority(context) | ||
// the context will always be a TraceContext | ||
@Suppress("UnsafeThirdPartyFunctionCall") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[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-otel
module in which we will provide theRequest.Builder.addParentSpan
extension 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)