From 776c700ebf265d2c3de56538f3921e696b28caf6 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Mon, 19 Aug 2019 16:41:36 -0700 Subject: [PATCH 1/4] Fix inject. --- src/dynamic_tracer.cpp | 45 +++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/src/dynamic_tracer.cpp b/src/dynamic_tracer.cpp index e1f7863..f646840 100644 --- a/src/dynamic_tracer.cpp +++ b/src/dynamic_tracer.cpp @@ -23,12 +23,12 @@ class DynamicSpanContext final : public opentracing::SpanContext { } private: - std::shared_ptr tracer_; - std::unique_ptr span_context_; + std::shared_ptr tracer_; + std::unique_ptr span_context_; - friend class DynamicTracer; + friend class DynamicTracer; }; -} // namespace +} // namespace //------------------------------------------------------------------------------ // DynamicSpan @@ -78,7 +78,9 @@ class DynamicSpan final : public opentracing::Span { return span_->context(); } - const opentracing::Tracer& tracer() const noexcept override { return *tracer_; } + const opentracing::Tracer& tracer() const noexcept override { + return *tracer_; + } }; } // namespace @@ -87,7 +89,7 @@ class DynamicSpan final : public opentracing::Span { //------------------------------------------------------------------------------ namespace { class DynamicTracer final : public opentracing::Tracer, - public std::enable_shared_from_this { + public std::enable_shared_from_this { public: DynamicTracer(opentracing::DynamicTracingLibraryHandle&& handle, std::shared_ptr&& tracer) noexcept @@ -102,7 +104,8 @@ class DynamicTracer final : public opentracing::Tracer, const opentracing::StartSpanOptions& options) const noexcept override { auto options_prime = options; for (auto& reference : options_prime.references) { - auto span_context = dynamic_cast(reference.second); + auto span_context = + dynamic_cast(reference.second); if (span_context != nullptr) { reference.second = span_context->span_context_.get(); } @@ -117,25 +120,45 @@ class DynamicTracer final : public opentracing::Tracer, opentracing::expected Inject(const opentracing::SpanContext& sc, std::ostream& writer) const override { - return tracer_->Inject(sc, writer); + auto span_context = dynamic_cast(&sc); + if (span_context != nullptr) { + return tracer_->Inject(*span_context, writer); + } + return opentracing::make_unexpected( + opentracing::invalid_span_context_error); } opentracing::expected Inject( const opentracing::SpanContext& sc, const opentracing::TextMapWriter& writer) const override { - return tracer_->Inject(sc, writer); + auto span_context = dynamic_cast(&sc); + if (span_context != nullptr) { + return tracer_->Inject(*span_context, writer); + } + return opentracing::make_unexpected( + opentracing::invalid_span_context_error); } opentracing::expected Inject( const opentracing::SpanContext& sc, const opentracing::HTTPHeadersWriter& writer) const override { - return tracer_->Inject(sc, writer); + auto span_context = dynamic_cast(&sc); + if (span_context != nullptr) { + return tracer_->Inject(*span_context, writer); + } + return opentracing::make_unexpected( + opentracing::invalid_span_context_error); } opentracing::expected Inject( const opentracing::SpanContext& sc, const opentracing::CustomCarrierWriter& writer) const override { - return tracer_->Inject(sc, writer); + auto span_context = dynamic_cast(&sc); + if (span_context != nullptr) { + return tracer_->Inject(*span_context, writer); + } + return opentracing::make_unexpected( + opentracing::invalid_span_context_error); } opentracing::expected> Extract( From b07002a7c168e785b7d650d6956e035b0d0e7813 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Mon, 19 Aug 2019 16:49:08 -0700 Subject: [PATCH 2/4] Fix span context type. --- src/dynamic_tracer.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/dynamic_tracer.cpp b/src/dynamic_tracer.cpp index f646840..f59d805 100644 --- a/src/dynamic_tracer.cpp +++ b/src/dynamic_tracer.cpp @@ -22,6 +22,10 @@ class DynamicSpanContext final : public opentracing::SpanContext { span_context_->ForeachBaggageItem(callback); } + const opentracing::SpanContext& context() const noexcept { + *return span_context_; + } + private: std::shared_ptr tracer_; std::unique_ptr span_context_; @@ -122,7 +126,7 @@ class DynamicTracer final : public opentracing::Tracer, std::ostream& writer) const override { auto span_context = dynamic_cast(&sc); if (span_context != nullptr) { - return tracer_->Inject(*span_context, writer); + return tracer_->Inject(span_context->context(), writer); } return opentracing::make_unexpected( opentracing::invalid_span_context_error); @@ -133,7 +137,7 @@ class DynamicTracer final : public opentracing::Tracer, const opentracing::TextMapWriter& writer) const override { auto span_context = dynamic_cast(&sc); if (span_context != nullptr) { - return tracer_->Inject(*span_context, writer); + return tracer_->Inject(span_context->context(), writer); } return opentracing::make_unexpected( opentracing::invalid_span_context_error); @@ -144,7 +148,7 @@ class DynamicTracer final : public opentracing::Tracer, const opentracing::HTTPHeadersWriter& writer) const override { auto span_context = dynamic_cast(&sc); if (span_context != nullptr) { - return tracer_->Inject(*span_context, writer); + return tracer_->Inject(span_context->context(), writer); } return opentracing::make_unexpected( opentracing::invalid_span_context_error); @@ -155,7 +159,7 @@ class DynamicTracer final : public opentracing::Tracer, const opentracing::CustomCarrierWriter& writer) const override { auto span_context = dynamic_cast(&sc); if (span_context != nullptr) { - return tracer_->Inject(*span_context, writer); + return tracer_->Inject(span_context->context(), writer); } return opentracing::make_unexpected( opentracing::invalid_span_context_error); From 72b6195cc1f00bcc5e7ebbe595cf825897b67484 Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Mon, 19 Aug 2019 16:52:57 -0700 Subject: [PATCH 3/4] Fix return statement. --- src/dynamic_tracer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dynamic_tracer.cpp b/src/dynamic_tracer.cpp index f59d805..3a415ee 100644 --- a/src/dynamic_tracer.cpp +++ b/src/dynamic_tracer.cpp @@ -23,7 +23,7 @@ class DynamicSpanContext final : public opentracing::SpanContext { } const opentracing::SpanContext& context() const noexcept { - *return span_context_; + return *span_context_; } private: From f230812e549bbb26b9e2d48aa4cdc45aab81663b Mon Sep 17 00:00:00 2001 From: Ryan Burn Date: Mon, 19 Aug 2019 16:57:04 -0700 Subject: [PATCH 4/4] Fix inject direct span. --- src/dynamic_tracer.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/dynamic_tracer.cpp b/src/dynamic_tracer.cpp index 3a415ee..68b991e 100644 --- a/src/dynamic_tracer.cpp +++ b/src/dynamic_tracer.cpp @@ -128,8 +128,7 @@ class DynamicTracer final : public opentracing::Tracer, if (span_context != nullptr) { return tracer_->Inject(span_context->context(), writer); } - return opentracing::make_unexpected( - opentracing::invalid_span_context_error); + return tracer_->Inject(sc, writer); } opentracing::expected Inject( @@ -139,8 +138,7 @@ class DynamicTracer final : public opentracing::Tracer, if (span_context != nullptr) { return tracer_->Inject(span_context->context(), writer); } - return opentracing::make_unexpected( - opentracing::invalid_span_context_error); + return tracer_->Inject(sc, writer); } opentracing::expected Inject( @@ -150,8 +148,7 @@ class DynamicTracer final : public opentracing::Tracer, if (span_context != nullptr) { return tracer_->Inject(span_context->context(), writer); } - return opentracing::make_unexpected( - opentracing::invalid_span_context_error); + return tracer_->Inject(sc, writer); } opentracing::expected Inject( @@ -161,8 +158,7 @@ class DynamicTracer final : public opentracing::Tracer, if (span_context != nullptr) { return tracer_->Inject(span_context->context(), writer); } - return opentracing::make_unexpected( - opentracing::invalid_span_context_error); + return tracer_->Inject(sc, writer); } opentracing::expected> Extract(