-
Notifications
You must be signed in to change notification settings - Fork 20
feat(tracing): add DD_TRACE_PROPAGATION_EXTRACT_FIRST #356
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
Draft
MilanGarnier
wants to merge
2
commits into
main
Choose a base branch
from
milan.garnier/propagation-extract-first
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ | |
| #include <type_traits> | ||
| #include <utility> | ||
|
|
||
| #include "common/environment.h" | ||
| #include "matchers.h" | ||
| #include "mocks/collectors.h" | ||
| #include "mocks/dict_readers.h" | ||
|
|
@@ -70,6 +71,9 @@ TEST_TRACER("tracer span defaults") { | |
| config.name = "test.thing"; | ||
| config.tags = {{"some.thing", "thing value"}, | ||
| {"another.thing", "another value"}}; | ||
| // The test does not cover telemetry. Disabling it prevents an asynchronous | ||
| // request to a local agent from racing the logger assertion below. | ||
| config.telemetry.enabled = false; | ||
|
|
||
| const auto collector = std::make_shared<MockCollector>(); | ||
| config.collector = collector; | ||
|
|
@@ -1545,6 +1549,75 @@ TEST_TRACER("span extraction") { | |
| } | ||
| } | ||
|
|
||
| TEST_TRACER( | ||
| "extract first tries later styles after an unsuccessful extraction") { | ||
| const datadog::test::EnvGuard guard{"DD_TRACE_PROPAGATION_EXTRACT_FIRST", | ||
| "true"}; | ||
| TracerConfig config; | ||
| config.service = "testsvc"; | ||
| config.collector = std::make_shared<NullCollector>(); | ||
| config.telemetry.enabled = false; | ||
| config.extraction_styles = std::vector<PropagationStyle>{ | ||
| PropagationStyle::DATADOG, PropagationStyle::W3C}; | ||
|
|
||
| const auto finalized_config = finalize_config(config); | ||
| REQUIRE(finalized_config); | ||
| Tracer tracer{*finalized_config}; | ||
|
|
||
| const std::unordered_map<std::string, std::string> headers{ | ||
| {"traceparent", | ||
| "00-00000000000000000000000000000001-0000000000000002-01"}, | ||
| }; | ||
|
|
||
| MockDictReader reader{headers}; | ||
| const auto span = tracer.extract_span(reader); | ||
| REQUIRE(span); | ||
| CHECK(span->parent_id() == 2); | ||
| } | ||
|
|
||
| TEST_TRACER("extract first tries later styles after an incomplete extraction") { | ||
| struct TestCase { | ||
| int line; | ||
| std::string description; | ||
| std::string traceparent; | ||
| TraceID expected_trace_id; | ||
| }; | ||
|
|
||
| const auto test_case = GENERATE(values<TestCase>({ | ||
| {__LINE__, "matching trace ID", | ||
| "00-00000000000000000000000000000001-0000000000000002-01", TraceID{1}}, | ||
| {__LINE__, "different trace ID", | ||
| "00-00000000000000000000000000000003-0000000000000002-01", TraceID{3}}, | ||
| })); | ||
|
|
||
| CAPTURE(test_case.line); | ||
| CAPTURE(test_case.description); | ||
|
|
||
| const datadog::test::EnvGuard guard{"DD_TRACE_PROPAGATION_EXTRACT_FIRST", | ||
| "true"}; | ||
| TracerConfig config; | ||
| config.service = "testsvc"; | ||
| config.collector = std::make_shared<NullCollector>(); | ||
| config.telemetry.enabled = false; | ||
| config.extraction_styles = std::vector<PropagationStyle>{ | ||
| PropagationStyle::DATADOG, PropagationStyle::W3C}; | ||
|
|
||
| const auto finalized_config = finalize_config(config); | ||
| REQUIRE(finalized_config); | ||
| Tracer tracer{*finalized_config}; | ||
|
|
||
| const std::unordered_map<std::string, std::string> headers{ | ||
| {"x-datadog-trace-id", "1"}, | ||
| {"traceparent", test_case.traceparent}, | ||
| }; | ||
|
|
||
| MockDictReader reader{headers}; | ||
| const auto span = tracer.extract_span(reader); | ||
| REQUIRE(span); | ||
| CHECK(span->trace_id() == test_case.expected_trace_id); | ||
| CHECK(span->parent_id() == 2); | ||
| } | ||
|
|
||
| TEST_TRACER("continue extraction resumes the extracted trace") { | ||
| TracerConfig config; | ||
| config.service = "testsvc"; | ||
|
|
@@ -2019,6 +2092,7 @@ TEST_TRACER("heterogeneous extraction") { | |
| std::vector<PropagationStyle> injection_styles; | ||
| std::unordered_map<std::string, std::string> extracted_headers; | ||
| std::unordered_map<std::string, std::string> expected_injected_headers; | ||
| bool extract_first = false; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be added in the capture block (lines 2121-2126). |
||
| }; | ||
|
|
||
| // clang-format off | ||
|
|
@@ -2041,6 +2115,17 @@ TEST_TRACER("heterogeneous extraction") { | |
| {{"traceparent", "00-00000000000000000000000000000030-000000000000002a-01"}, | ||
| {"tracestate", "dd=s:2;p:000000000000002a;o:Kansas;ah:choo,competitor=stuff"}}}, | ||
|
|
||
| {__LINE__, "extract first ignores tracestate from subsequent style", | ||
| {PropagationStyle::DATADOG, PropagationStyle::W3C}, | ||
| {PropagationStyle::W3C}, | ||
| {{"x-datadog-trace-id", "48"}, {"x-datadog-parent-id", "64"}, | ||
| {"x-datadog-origin", "Kansas"}, {"x-datadog-sampling-priority", "2"}, | ||
| {"traceparent", "00-00000000000000000000000000000030-0000000000000040-01"}, | ||
| {"tracestate", "competitor=stuff,dd=o:Nebraska;s:1;ah:choo"}}, | ||
| {{"traceparent", "00-00000000000000000000000000000030-000000000000002a-01"}, | ||
| {"tracestate", "dd=s:2;p:000000000000002a;o:Kansas"}}, | ||
| true}, | ||
|
|
||
| {__LINE__, "ignore interlopers", | ||
| {PropagationStyle::DATADOG, PropagationStyle::B3, PropagationStyle::W3C}, | ||
| {PropagationStyle::W3C}, | ||
|
|
@@ -2087,8 +2172,12 @@ TEST_TRACER("heterogeneous extraction") { | |
| config.service = "testsvc"; | ||
| config.extraction_styles = test_case.extraction_styles; | ||
| config.injection_styles = test_case.injection_styles; | ||
| config.telemetry.enabled = false; | ||
| config.logger = std::make_shared<NullLogger>(); | ||
|
|
||
| const datadog::test::EnvGuard extract_first{ | ||
| "DD_TRACE_PROPAGATION_EXTRACT_FIRST", | ||
| test_case.extract_first ? "true" : "false"}; | ||
| auto finalized_config = finalize_config(config); | ||
| REQUIRE(finalized_config); | ||
| Tracer tracer{*finalized_config, std::make_shared<MockIDGenerator>()}; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think the
extracted_trace_contextname is misleading:Actually, because the existing code is not clean, I find it very difficult to reason about this:
dataname does not convey any useful meaning.Tracer::extract_span()function.I suggest adding a dedicated refactoring PR before this one to clean the
Tracer::extract_span()function: