-
Notifications
You must be signed in to change notification settings - Fork 19
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
15
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
15 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 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,41 @@ | ||
| #pragma once | ||
|
|
||
| // This component defines `SpanLink`, a causal association between the span that | ||
| // owns the link and another span (possibly in another trace). Span links carry | ||
| // the linked span's identifiers plus optional W3C tracestate, trace flags, and | ||
| // arbitrary string attributes. They are serialized into the owning span under | ||
| // the `span_links` key in a format shared by all Datadog tracers. | ||
|
|
||
| #include <cstdint> | ||
| #include <string> | ||
| #include <unordered_map> | ||
|
|
||
| #include "expected.h" | ||
| #include "optional.h" | ||
| #include "trace_id.h" | ||
|
|
||
| namespace datadog { | ||
| namespace tracing { | ||
|
|
||
| // Convenience alias: the map type used for span link user attributes. | ||
| using SpanLinkAttributes = std::unordered_map<std::string, std::string>; | ||
|
|
||
| struct SpanLink { | ||
| // 128-bit trace ID of the linked span. | ||
| TraceID trace_id; | ||
| // The linked span's ID. | ||
| std::uint64_t span_id = 0; | ||
| // W3C `tracestate` header value from the linked context, if any. | ||
| Optional<std::string> tracestate; | ||
| // Additional string attributes associated with the link. | ||
| std::unordered_map<std::string, std::string> attributes; | ||
| // W3C trace flags from the linked context, if any. | ||
| Optional<std::uint32_t> flags; | ||
| }; | ||
|
|
||
| // Append to the specified `destination` the MessagePack representation of the | ||
| // specified `link`. | ||
| Expected<void> msgpack_encode(std::string& destination, const SpanLink& link); | ||
|
|
||
| } // namespace tracing | ||
| } // namespace datadog |
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,71 @@ | ||
| #include <datadog/span_link.h> | ||
|
|
||
| #include <cstddef> | ||
| #include <string> | ||
|
|
||
| #include "msgpack.h" | ||
|
|
||
| namespace datadog { | ||
| namespace tracing { | ||
|
|
||
| Expected<void> msgpack_encode(std::string& destination, const SpanLink& link) { | ||
| const bool has_trace_id_high = link.trace_id.high != 0; | ||
| const bool has_attributes = !link.attributes.empty(); | ||
| const bool has_tracestate = link.tracestate && !link.tracestate->empty(); | ||
| const bool has_flags = link.flags.has_value(); | ||
|
|
||
| std::size_t size = 2; // trace_id + span_id are always present | ||
| if (has_trace_id_high) ++size; | ||
| if (has_attributes) ++size; | ||
| if (has_tracestate) ++size; | ||
| if (has_flags) ++size; | ||
|
|
||
| auto result = msgpack::pack_map(destination, size); | ||
| if (!result) return result; | ||
|
|
||
| // trace_id (low 64 bits) | ||
| result = msgpack::pack_string(destination, "trace_id"); | ||
| if (!result) return result; | ||
| msgpack::pack_integer(destination, link.trace_id.low); | ||
|
|
||
| if (has_trace_id_high) { | ||
| result = msgpack::pack_string(destination, "trace_id_high"); | ||
| if (!result) return result; | ||
| msgpack::pack_integer(destination, link.trace_id.high); | ||
| } | ||
|
|
||
| result = msgpack::pack_string(destination, "span_id"); | ||
| if (!result) return result; | ||
| msgpack::pack_integer(destination, link.span_id); | ||
|
|
||
| if (has_attributes) { | ||
| result = msgpack::pack_string(destination, "attributes"); | ||
| if (!result) return result; | ||
| result = | ||
| msgpack::pack_map(destination, link.attributes, | ||
| [](std::string& destination, const auto& value) { | ||
| return msgpack::pack_string(destination, value); | ||
| }); | ||
| if (!result) return result; | ||
| } | ||
|
|
||
| if (has_tracestate) { | ||
| result = msgpack::pack_string(destination, "tracestate"); | ||
| if (!result) return result; | ||
| result = msgpack::pack_string(destination, *link.tracestate); | ||
| if (!result) return result; | ||
| } | ||
|
|
||
| if (has_flags) { | ||
| result = msgpack::pack_string(destination, "flags"); | ||
| if (!result) return result; | ||
| // 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 nullopt; | ||
| } | ||
|
|
||
| } // namespace tracing | ||
| } // namespace datadog |
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
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.
Uh oh!
There was an error while loading. Please reload this page.