Skip to content

RUMM-2620 Allow the usage of OTel headers in distributed tracing#1229

Merged
plousada merged 15 commits into
developfrom
plousada/RUMM-2620/otel-headers-support
Jan 19, 2023
Merged

RUMM-2620 Allow the usage of OTel headers in distributed tracing#1229
plousada merged 15 commits into
developfrom
plousada/RUMM-2620/otel-headers-support

Conversation

@plousada

Copy link
Copy Markdown
Member

What does this PR do?

This PR introduces the ability to select OTel headers (B3, B3Multi & Trace Context) to be injected in requests made to first party hosts.
Here we introduce a new configuration API setFirstPartyHostsWithHeaderType allowing several types of tracing header to be configured for each host.

Additional Notes

I've removed the optimization of not creating a new Span in TracingInterceptor as Trace Context header specification requires spanId and traceId to be propagated, even if the request is sampled out.

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)

@plousada
plousada requested a review from a team as a code owner January 11, 2023 12:55
requestId,
fakeMethod,
fakeUrl,
fakeUrl.lowercase(Locale.US),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Because the regex for generating the host name in test changed to allow for upper case letters, and because of RUMM-2900 we must currently lowercase the expected result.

Comment thread dd-sdk-android/src/main/java/com/datadog/opentracing/DDTracer.java
Comment thread dd-sdk-android/src/main/kotlin/com/datadog/android/DatadogInterceptor.kt Outdated
if (length > 32) {
traceId = BigInteger.ZERO;
continue;
} else if (length > 16) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This confuses me a little bit --

There'a an edge case where a 16 character hex digit can be larger than the supported 63-bits. This may not be an issue if we're always generating the ID.

But if we're potentially extracting these IDs from user set headers (which I'm told we shouldn't be) then we likely need to handle the edge case (though it's possible validateUIng64BitsID does that?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is original code from the Java tracing lib.
validateUInt64BitsID only accepts IDs between 0 and 2^64-1. It throws an exception otherwise.

In Android we do support extracting the IDs from the Request. It's been like this for quite some time.

@plousada plousada added the size-huge This PR is huge sized label Jan 11, 2023

@0xnm 0xnm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great work! I went though the main code so far, will cover tests a bit later (big PR).

Comment thread dd-sdk-android/src/main/java/com/datadog/opentracing/propagation/B3HttpCodec.java Outdated
Comment thread dd-sdk-android/src/main/kotlin/com/datadog/android/tracing/TracingInterceptor.kt Outdated
Comment thread dd-sdk-android/src/main/kotlin/com/datadog/android/tracing/TracingInterceptor.kt Outdated

@0xnm 0xnm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Went through the tests, added some comments, but overall looks good.

fun rum_resource_tracking_with_first_party_hosts_and_header_types() {
// In this case because the Span is generated by the backend as "android.request" Span
// there is no metric automatically generated for it so we had to create a special
// custom metric: "rum_resource_tracking_with_first_party_hosts" to assert this behaviour

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this test will add more hits to the existing rum_resource_tracking_with_first_party_hosts metric, triggering this monitor "[RUM] [Android] Nightly - rum_resource_tracking_with_first_party_hosts: Number of spans generated from resource tracking should not be greater than 2/day as we only have one use case that should generate this Span".

I think we should either modify the value in this monitor, or create a separate metric for this test (and update the previous metric, so that it doesn't cover the new one as well).

new ContextualScopeManager(Config.get().getScopeDepthLimit(), createScopeEventFactory()),
HttpCodec.createInjector(config),
HttpCodec.createExtractor(config, config.getHeaderTags()),
new ContextualScopeManager(config.get().getScopeDepthLimit(), createScopeEventFactory()),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SHouldn't this one be config and not config.get()?

@plousada plousada Jan 12, 2023

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In theory yes, but for the sake of this PR it doesn't make a difference because we don't alter the properties that the ContextualScopeManager accesses.
I'll revert to avoid changing the original lib as much as possible.

Comment thread dd-sdk-android/src/main/java/com/datadog/opentracing/DDTracer.java Outdated
@codecov-commenter

codecov-commenter commented Jan 13, 2023

Copy link
Copy Markdown

Codecov Report

Merging #1229 (28bc7e1) into develop (c059b67) will decrease coverage by 0.78%.
The diff coverage is 50.00%.

@@             Coverage Diff             @@
##           develop    #1229      +/-   ##
===========================================
- Coverage    82.82%   82.05%   -0.78%     
===========================================
  Files          358      361       +3     
  Lines        12582    12827     +245     
  Branches      2093     2152      +59     
===========================================
+ Hits         10421    10524     +103     
- Misses        1523     1652     +129     
- Partials       638      651      +13     
Impacted Files Coverage Δ
...m/datadog/opentracing/propagation/B3HttpCodec.java 5.08% <0.00%> (+5.08%) ⬆️
.../datadog/opentracing/propagation/W3CHttpCodec.java 5.17% <5.17%> (ø)
.../datadog/opentracing/propagation/B3MHttpCodec.java 5.36% <5.36%> (ø)
...n/kotlin/com/datadog/android/DatadogInterceptor.kt 72.65% <30.00%> (-8.48%) ⬇️
.../com/datadog/android/tracing/TracingInterceptor.kt 84.55% <77.19%> (-12.25%) ⬇️
...com/datadog/opentracing/propagation/HttpCodec.java 47.06% <83.33%> (+22.06%) ⬆️
...e/internal/net/FirstPartyHostHeaderTypeResolver.kt 88.24% <88.24%> (ø)
...atadog/android/core/configuration/Configuration.kt 98.13% <91.67%> (-0.33%) ⬇️
...rc/main/java/com/datadog/opentracing/DDTracer.java 56.07% <100.00%> (ø)
...id/src/main/java/com/datadog/trace/api/Config.java 65.75% <100.00%> (+0.46%) ⬆️
... and 24 more

@mariusc83 mariusc83 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Apart from all the other comments LGTM

@plousada
plousada merged commit dbb4000 into develop Jan 19, 2023
@plousada
plousada deleted the plousada/RUMM-2620/otel-headers-support branch January 19, 2023 15:07
@xgouchet xgouchet added this to the 1.17.0 milestone Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size-huge This PR is huge sized

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants