-
Notifications
You must be signed in to change notification settings - Fork 20
feat(tracing): add span link support #330
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
Open
MilanGarnier
wants to merge
27
commits into
main
Choose a base branch
from
milan.garnier/span-links-support
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.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
fad515b
add span link struct and test
MilanGarnier 0796973
enable span link tests
MilanGarnier 0fecaca
implement Span::add_link
MilanGarnier f254562
add span link to msg pack encoding
MilanGarnier 58cf95d
add spn link test for the Span class
MilanGarnier 84a7ef4
implenent add_link endpoint for parametric tests
MilanGarnier 65382c4
flatten array
MilanGarnier ecfb7cc
cleaner spanlink construction
MilanGarnier eecfe93
add extracted context struct
MilanGarnier c4ae457
cleaning up (move logic to span.cpp)
MilanGarnier 86d189e
format
MilanGarnier dff6677
fix BAZEL build
MilanGarnier 1a36ade
derive W3C flags from sampling priority in add_link(ExtractedContext)
MilanGarnier 6c2f121
resolve https://github.com/DataDog/dd-trace-cpp/pull/330#discussion_r…
MilanGarnier 5c93eca
change scope of ExtractedHeaders struct (restrict to parametric server)
MilanGarnier 5311345
case insensitive lookup for headers
MilanGarnier f62084f
nit: nested namespace syntax
MilanGarnier 9ac8c2b
clearer variable names
MilanGarnier f736ab5
get rid of magic values in span_data::msgpack
MilanGarnier 0da2fea
Cleaner msgpack_encode for span_link.cpp
MilanGarnier 64882ca
split RequestHandler::on_add_link
MilanGarnier a1a3484
make storedLinkContexts outside of on_extract_headers function
MilanGarnier 0b3959a
bugfix: do not force sampling decision when writing tracestate in
MilanGarnier f033eef
avoid collisions when adding links consecutively (parent_id=0)
MilanGarnier a035447
move span link into private types, expose spancontext and spanlinkatt…
MilanGarnier 6762038
always store trace_id_high
MilanGarnier 58fcb18
fix typo in parametric server
MilanGarnier 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #pragma once | ||
|
|
||
| // This component defines `SpanContext`, the identifying and propagation state | ||
| // of a span. It can be supplied to `Span::add_link` to associate a span with a | ||
| // span in this or another trace. | ||
|
|
||
| #include <cstdint> | ||
| #include <string> | ||
| #include <unordered_map> | ||
|
|
||
| #include "optional.h" | ||
| #include "trace_id.h" | ||
|
|
||
| namespace datadog::tracing { | ||
|
|
||
| // The map type used for user-supplied span-link attributes. | ||
| using SpanLinkAttributes = std::unordered_map<std::string, std::string>; | ||
|
|
||
| struct SpanContext { | ||
| // 128-bit trace ID of the span. | ||
| TraceID trace_id; | ||
| // ID of the span within its trace. | ||
| std::uint64_t span_id = 0; | ||
| // W3C `tracestate` header value, if any. | ||
| Optional<std::string> tracestate; | ||
| // W3C trace flags, if any. | ||
| Optional<std::uint32_t> flags; | ||
| }; | ||
|
|
||
| } // namespace datadog::tracing |
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 |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| #include "span_link.h" | ||
|
|
||
| #include <algorithm> | ||
| #include <array> | ||
| #include <cstddef> | ||
| #include <functional> | ||
| #include <string> | ||
| #include <tuple> | ||
|
|
||
| #include "msgpack.h" | ||
|
|
||
| namespace datadog::tracing { | ||
|
|
||
| Expected<void> msgpack_encode(std::string& destination, const SpanLink& link) { | ||
|
MilanGarnier marked this conversation as resolved.
|
||
| // array of (is_present, field_name, pack_function) | ||
| const std::array< | ||
| std::tuple<bool, StringView, std::function<Expected<void>(std::string&)>>, | ||
| 6> | ||
| fields{{ | ||
| {true, "trace_id", | ||
| [&](std::string& destination) { | ||
| msgpack::pack_integer(destination, link.trace_id.low); | ||
| return Expected<void>{}; | ||
| }}, | ||
| {true, "span_id", | ||
| [&](std::string& destination) { | ||
| msgpack::pack_integer(destination, link.span_id); | ||
| return Expected<void>{}; | ||
| }}, | ||
| {true, "trace_id_high", | ||
| [&](std::string& destination) { | ||
| msgpack::pack_integer(destination, link.trace_id.high); | ||
| return Expected<void>{}; | ||
| }}, | ||
| {!link.attributes.empty(), "attributes", | ||
| [&](std::string& destination) { | ||
| return msgpack::pack_map( | ||
| destination, link.attributes, | ||
| [](std::string& destination, const auto& value) { | ||
| return msgpack::pack_string(destination, value); | ||
| }); | ||
| }}, | ||
| {link.tracestate.has_value() && !link.tracestate->empty(), | ||
| "tracestate", | ||
| [&](std::string& destination) { | ||
| return msgpack::pack_string(destination, *link.tracestate); | ||
| }}, | ||
| {link.flags.has_value(), "flags", | ||
| [&](std::string& destination) { | ||
| // The high bit marks "flags is present" so a receiver can | ||
| // distinguish an explicit value of 0 from an omitted field. | ||
| msgpack::pack_integer(destination, | ||
| std::uint64_t(*link.flags | (1u << 31))); | ||
| return Expected<void>{}; | ||
| }}, | ||
| }}; | ||
|
|
||
| const auto size = std::count_if(fields.begin(), fields.end(), | ||
| [](const auto& f) { return std::get<0>(f); }); | ||
|
|
||
| auto result = msgpack::pack_map(destination, size); | ||
| if (!result) return result; | ||
|
|
||
| for (const auto& [present, field, pack] : fields) { | ||
| if (present) { | ||
| result = msgpack::pack_map_suffix(destination, field, pack); | ||
| if (!result) break; | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| } // namespace datadog::tracing | ||
Oops, something went wrong.
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.
Is there a reason for splitting the behavior when there are no span links? I imagine it would be okay to run this even if we have an empty array of span links
Uh oh!
There was an error while loading. Please reload this page.
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.
In other tracers the field is omitted when empty, I was following the same logic. I'm also not satisfied with how it looks that way, the other option I had was using a magic number for the number of fields and several msg_pack_suffix to avoid splitting the logic.
e.g. Go uses :