-
Notifications
You must be signed in to change notification settings - Fork 5.4k
datadog: span portion of new tracing library #25121
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
Changes from all commits
2e32f68
4a02d36
fd44001
7f48705
dbb80b1
c8e308b
aff76d1
4a0f316
be5ca87
78a3a6f
6944056
984d3a7
09f0519
b58bc6d
59c8a6c
a3f290a
0ae865a
be83634
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| #include "source/extensions/tracers/datadog/span.h" | ||
|
|
||
| #include <utility> | ||
|
|
||
| #include "source/common/tracing/null_span_impl.h" | ||
| #include "source/extensions/tracers/datadog/time_util.h" | ||
|
|
||
| #include "absl/strings/str_cat.h" | ||
| #include "absl/strings/string_view.h" | ||
| #include "datadog/dict_writer.h" | ||
| #include "datadog/sampling_priority.h" | ||
| #include "datadog/span_config.h" | ||
| #include "datadog/trace_segment.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace Tracers { | ||
| namespace Datadog { | ||
| namespace { | ||
|
|
||
| class TraceContextWriter : public datadog::tracing::DictWriter { | ||
| public: | ||
| explicit TraceContextWriter(Tracing::TraceContext& context) : context_(context) {} | ||
|
|
||
| void set(datadog::tracing::StringView key, datadog::tracing::StringView value) override { | ||
| context_.setByKey(key, value); | ||
| } | ||
|
|
||
| private: | ||
| Tracing::TraceContext& context_; | ||
| }; | ||
|
|
||
| } // namespace | ||
|
|
||
| Span::Span(datadog::tracing::Span&& span) : span_(std::move(span)) {} | ||
|
|
||
| const datadog::tracing::Optional<datadog::tracing::Span>& Span::impl() const { return span_; } | ||
|
|
||
| void Span::setOperation(absl::string_view operation) { | ||
| if (!span_) { | ||
| return; | ||
| } | ||
|
|
||
| span_->set_name(operation); | ||
| } | ||
|
|
||
| void Span::setTag(absl::string_view name, absl::string_view value) { | ||
| if (!span_) { | ||
| return; | ||
| } | ||
|
|
||
| span_->set_tag(name, value); | ||
| } | ||
|
|
||
| void Span::log(SystemTime, const std::string&) { | ||
| // Datadog spans don't have in-bound "events" or "logs". | ||
| } | ||
|
|
||
| void Span::finishSpan() { span_.reset(); } | ||
|
|
||
| void Span::injectContext(Tracing::TraceContext& trace_context, | ||
| const Upstream::HostDescriptionConstSharedPtr&) { | ||
| if (!span_) { | ||
| return; | ||
| } | ||
|
|
||
| TraceContextWriter writer{trace_context}; | ||
| span_->inject(writer); | ||
| } | ||
|
|
||
| Tracing::SpanPtr Span::spawnChild(const Tracing::Config&, const std::string& name, | ||
| SystemTime start_time) { | ||
| if (!span_) { | ||
| // I don't expect this to happen. This means that `spawnChild` was called | ||
| // after `finishSpan`. | ||
|
Contributor
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. should we use an ENVOY_BUG here (logs a message in production build, asserts in debug/default builds)?
Contributor
Author
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. That might be worth doing. I'd reserve You mentioned the idea of @moderation looking over the behavior of this |
||
| return std::make_unique<Tracing::NullSpan>(); | ||
| } | ||
|
|
||
| // The OpenTracing implementation ignored the `Tracing::Config` argument, | ||
| // so we will as well. | ||
| datadog::tracing::SpanConfig config; | ||
| config.name = name; | ||
| config.start = estimateTime(start_time); | ||
|
|
||
| return std::make_unique<Span>(span_->create_child(config)); | ||
| } | ||
|
|
||
| void Span::setSampled(bool sampled) { | ||
| if (!span_) { | ||
| return; | ||
| } | ||
|
|
||
| auto priority = static_cast<int>(sampled ? datadog::tracing::SamplingPriority::USER_KEEP | ||
| : datadog::tracing::SamplingPriority::USER_DROP); | ||
| span_->trace_segment().override_sampling_priority(priority); | ||
| } | ||
|
|
||
| std::string Span::getBaggage(absl::string_view) { | ||
| // not implemented | ||
| return std::string{}; | ||
| } | ||
|
|
||
| void Span::setBaggage(absl::string_view, absl::string_view) { | ||
| // not implemented | ||
| } | ||
|
|
||
| std::string Span::getTraceIdAsHex() const { | ||
| if (!span_) { | ||
| return std::string{}; | ||
| } | ||
| return absl::StrCat(absl::Hex(span_->id())); | ||
|
Member
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. @dgoffredo Is this right? |
||
| } | ||
|
|
||
| } // namespace Datadog | ||
| } // namespace Tracers | ||
| } // namespace Extensions | ||
| } // namespace Envoy | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| #pragma once | ||
|
|
||
| #include <optional> | ||
|
|
||
| #include "envoy/common/time.h" | ||
| #include "envoy/tracing/trace_driver.h" | ||
|
|
||
| #include "datadog/span.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace Tracers { | ||
| namespace Datadog { | ||
|
|
||
| /** | ||
| * Tracing::Span implementation for use in Datadog tracing. This class contains | ||
| * an optional<datadog::tracing::Span> and forwards its member functions to the | ||
| * corresponding member functions of datadog::tracing::Span. | ||
| * | ||
| * datadog::tracing::Span is the span type used in Datadog's core tracing | ||
| * library, dd-trace-cpp. It's wrapped in an optional<> because the lifetime | ||
| * of a datadog::tracing::Span is tied to the scope of the object itself, | ||
| * whereas the Tracing::Span implemented here has a finishSpan() member | ||
| * function that allows the span's lifetime to end without destroying the | ||
| * object. | ||
| * | ||
| * For the same reason, this class has two states: one when the | ||
| * optional<datadog::tracing::Span> is not empty and member functions are | ||
| * forwarded to it, and another state when the optional<datadog::tracing::Span> | ||
| * is empty and member functions have no effect. | ||
| */ | ||
| class Span : public Tracing::Span { | ||
| public: | ||
| explicit Span(datadog::tracing::Span&& span); | ||
|
|
||
| const datadog::tracing::Optional<datadog::tracing::Span>& impl() const; | ||
|
|
||
|
dgoffredo marked this conversation as resolved.
|
||
| // Envoy::Tracing::Span | ||
| void setOperation(absl::string_view operation) override; | ||
| void setTag(absl::string_view name, absl::string_view value) override; | ||
| void log(SystemTime, const std::string&) override; | ||
| void finishSpan() override; | ||
| void injectContext(Tracing::TraceContext& trace_context, | ||
| const Upstream::HostDescriptionConstSharedPtr& upstream) override; | ||
| Tracing::SpanPtr spawnChild(const Tracing::Config& config, const std::string& name, | ||
| SystemTime start_time) override; | ||
| void setSampled(bool sampled) override; | ||
| std::string getBaggage(absl::string_view key) override; | ||
| void setBaggage(absl::string_view key, absl::string_view value) override; | ||
| std::string getTraceIdAsHex() const override; | ||
|
|
||
| private: | ||
| datadog::tracing::Optional<datadog::tracing::Span> span_; | ||
| }; | ||
|
|
||
| } // namespace Datadog | ||
| } // namespace Tracers | ||
| } // namespace Extensions | ||
| } // namespace Envoy | ||
Uh oh!
There was an error while loading. Please reload this page.