#include namespace opentracing { BEGIN_OPENTRACING_ABI_NAMESPACE namespace { class NoopSpanContext : public SpanContext { public: void ForeachBaggageItem( std::function /*f*/) const override {} std::unique_ptr Clone() const noexcept override { return std::unique_ptr{new (std::nothrow) NoopSpanContext{}}; } }; class NoopSpan : public Span { public: explicit NoopSpan(std::shared_ptr&& tracer) noexcept : tracer_(std::move(tracer)) {} void FinishWithOptions( const FinishSpanOptions& /*finish_span_options*/) noexcept override {} void SetOperationName(string_view /*name*/) noexcept override {} void SetTag(string_view /*key*/, const Value& /*value*/) noexcept override {} void SetBaggageItem(string_view /*restricted_key*/, string_view /*value*/) noexcept override {} std::string BaggageItem(string_view /*restricted_key*/) const noexcept override { return {}; } void Log(std::initializer_list> /*fields*/) noexcept override {} void Log(SystemTime /*timestamp*/, std::initializer_list< std::pair> /*fields*/) noexcept override {} void Log(SystemTime /*timestamp*/, const std::vector< std::pair>& /*fields*/) noexcept override {} const SpanContext& context() const noexcept override { return span_context_; } const Tracer& tracer() const noexcept override { return *tracer_; } private: std::shared_ptr tracer_; NoopSpanContext span_context_; }; class NoopTracer : public Tracer, public std::enable_shared_from_this { public: std::unique_ptr StartSpanWithOptions( string_view /*operation_name*/, const StartSpanOptions& /*options*/) const noexcept override { return std::unique_ptr(new (std::nothrow) NoopSpan(shared_from_this())); } expected Inject(const SpanContext& /*sc*/, std::ostream& /*writer*/) const override { return {}; } expected Inject(const SpanContext& /*sc*/, const TextMapWriter& /*writer*/) const override { return {}; } expected Inject(const SpanContext& /*sc*/, const HTTPHeadersWriter& /*writer*/) const override { return {}; } expected> Extract( std::istream& /*reader*/) const override { return std::unique_ptr(nullptr); } expected> Extract( const TextMapReader& /*reader*/) const override { return std::unique_ptr(nullptr); } expected> Extract( const HTTPHeadersReader& /*reader*/) const override { return std::unique_ptr(nullptr); } }; } // anonymous namespace std::shared_ptr MakeNoopTracer() noexcept { return std::shared_ptr(new (std::nothrow) NoopTracer()); } END_OPENTRACING_ABI_NAMESPACE } // namespace opentracing