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

Consider Baggage when creating new root traces #4520

Merged
merged 1 commit into from
Jan 27, 2023
Merged

Consider Baggage when creating new root traces #4520

merged 1 commit into from
Jan 27, 2023

Conversation

Xyaren
Copy link
Contributor

@Xyaren Xyaren commented Jan 10, 2023

What Does This Do

Solves #4516

This PR modifies which extracted information is used when creating a new trace.

Motivation

Due to Baggage mapping, there now is a possible need to map headers into new created traces.

Additional Notes

No failing test - If someone can point me to the correct test cases to improve to cover this change please do so.

@Xyaren Xyaren requested a review from a team as a code owner January 10, 2023 15:30
Copy link
Contributor

@bantonsson bantonsson left a comment

Choose a reason for hiding this comment

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

Thanks @Xyaren

I think you need to re-authenticate with CircleCI or push something to the branch to make CI run again.

@Xyaren
Copy link
Contributor Author

Xyaren commented Jan 12, 2023

I think you need to re-authenticate with CircleCI or push something to the branch to make CI run again.

image

What should I do here ?

@bantonsson
Copy link
Contributor

@Xyaren from the build number in your image, it looks like CircleCI is enabled on your fork of the repo, and it is trying to build it using your account. The CircleCI setup is a bit messy, but you need to disable CircleCI for your fork (in CircleCI).

@Xyaren
Copy link
Contributor Author

Xyaren commented Jan 13, 2023

@bantonsson I "unfollowed" the project, can you trigger the CI again ?

@bantonsson
Copy link
Contributor

@Xyaren I'm unfortunately unable to trigger anything, since CircleCI seems to think that you want to run CI on your fork https://github.com/Xyaren/dd-trace-java and not on https://github.com/Datadog/dd-trace-java

If you go to the projects for your GitHub account organization in CircleCI, you should see something like this (for your GitHub user):
Screenshot 2023-01-13 at 15 35 45
Make sure that you disable the dd-trace-java project there by clicking the ... on the dd-trace-java line (mine is greyed out since I haven't enabled CircleCI for my fork).

@Xyaren
Copy link
Contributor Author

Xyaren commented Jan 13, 2023

image

That's how it looks like already.
I'll try to re-trigger by adding a new commit.

@bantonsson bantonsson added tag: community Community contribution comp: context propagation Trace context propagation labels Jan 18, 2023
@Xyaren
Copy link
Contributor Author

Xyaren commented Jan 24, 2023

Rebased.

@bantonsson
Copy link
Contributor

@Xyaren there is one code formatting issue. Running ./gradlew formatCode will fix it.

@Xyaren
Copy link
Contributor Author

Xyaren commented Jan 25, 2023

@bantonsson I really struggle to find the test failures in the CI Logs.
Some ci steps seem to require an API Key ?

@bantonsson
Copy link
Contributor

bantonsson commented Jan 25, 2023

@Xyaren sorry about that.

  • You can ignore all the ones named system-tests-* since they need an API key secret that is not available to outside contributors.
  • If you see several failing jobs named with a similar pattern, i.e. z_test_??_base, then there is probably an issue in that category of tests.

There are two failing tests here:

@Xyaren
Copy link
Contributor Author

Xyaren commented Jan 25, 2023

I see.
The Problem is around the Haystack Span,Trace and Parent Id, which is handled as baggage.

https://github.com/Xyaren/dd-trace-java/blob/c99bec69e0a7f72ecc427e0ecb19c877e8bacf81/dd-trace-core/src/main/java/datadog/trace/core/propagation/HaystackHttpCodec.java#L204-L214

This is only in the special case, when the haystack trace Id is zero, as this would normally result in no trace being created.
Due to the addition of haystack trace (and span) ids to the baggage map, this would result in a new context despite a 0 trace id.
image

I feel like this would still qualify for creating a new trace context including the extracted baggage of the zero-only haystack ids. Thats in fact what was correctly extracted, so why not keep it and propagate it ?

Alternatively one could invalidate the context similar to the case when the trace id is negative:
image

Another option is to remove the baggage after extraction, but this would require some additional mechanism for HttpCodec.Extractor Implementations to "cleanUp" the baggage after extraction in TagContextExtractor.extract.

I could also split the baggage into two separate maps i.e.: predefinedBaggage & baggage, so the check in the ContextInterpreter.build() can evaluate if the baggage is sourced from ot-*/mapped baggage or predefined like the haystack ids.

What do you prefer ?

@Xyaren
Copy link
Contributor Author

Xyaren commented Jan 25, 2023

ProxyRequestHelperTest#Test baggage headers to be correctly ignored through proxy
Is probably obsolete after this PR, as it tests exactly the opposite of what this PR is trying to achieve: Creating a new context when baggage is received.

My questions are:

  • Does a received trace id of 0 represent a special case ? If so, what is it ?
    I've noticed we're still considering mapped tags (from headers), so the same could apply to baggage.
  • Should ot-* baggage be propagated next to configured mapped baggage as well when received without a trace id?

@bantonsson
Copy link
Contributor

@Xyaren If we receive a traceId of 0 we interpret that as no ingoing trace, so we will create a new Trace starting here. I think it's fine to always propagate the baggage, and you don't need to split up the different baggage types. The test makes the wrong assumptions and instead it should check that the baggage contains the expected items, something like this:

    ...
    baggage = [ ... ]

    when:
    final TagContext context = extractor.extract(headers, ContextVisitors.stringValuesMap())

    then:
    if (expectedTraceId) {
      ExtractedContext ec = context as ExtractedContext
      assert ec.traceId == expectedTraceId
      assert ec.spanId == expectedSpanId
    }
    context.baggageItems() == baggage
    ...

@Xyaren
Copy link
Contributor Author

Xyaren commented Jan 26, 2023

@bantonsson Thank you for the explanation.
I decided to split the test up and added one explicitly for the baggage propagation.

@bantonsson
Copy link
Contributor

@Xyaren I think you need to update this PR since there is now a conflict with your changes from #4513

@Xyaren
Copy link
Contributor Author

Xyaren commented Jan 27, 2023

Rebased & Squashed 👍

@bantonsson bantonsson merged commit 22ce703 into DataDog:master Jan 27, 2023
@bantonsson bantonsson added this to the 1.7.0 milestone Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp: context propagation Trace context propagation tag: community Community contribution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants