LCOV - code coverage report
Current view: top level - source/extensions/tracers/common/ot - opentracing_driver_impl.h (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 0 3 0.0 %
Date: 2024-01-05 06:35:25 Functions: 0 3 0.0 %

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include <memory>
       4             : 
       5             : #include "envoy/stats/scope.h"
       6             : #include "envoy/tracing/trace_driver.h"
       7             : 
       8             : #include "source/common/common/empty_string.h"
       9             : #include "source/common/common/logger.h"
      10             : #include "source/common/singleton/const_singleton.h"
      11             : 
      12             : #include "opentracing/ext/tags.h"
      13             : #include "opentracing/tracer.h"
      14             : 
      15             : namespace Envoy {
      16             : namespace Extensions {
      17             : namespace Tracers {
      18             : namespace Common {
      19             : namespace Ot {
      20             : 
      21             : #define OPENTRACING_TRACER_STATS(COUNTER)                                                          \
      22             :   COUNTER(span_context_extraction_error)                                                           \
      23             :   COUNTER(span_context_injection_error)
      24             : 
      25             : struct OpenTracingTracerStats {
      26             :   OPENTRACING_TRACER_STATS(GENERATE_COUNTER_STRUCT)
      27             : };
      28             : 
      29             : class OpenTracingDriver;
      30             : 
      31             : class OpenTracingSpan : public Tracing::Span, Logger::Loggable<Logger::Id::tracing> {
      32             : public:
      33             :   OpenTracingSpan(OpenTracingDriver& driver, std::unique_ptr<opentracing::Span>&& span);
      34             : 
      35             :   // Tracing::Span
      36             :   void finishSpan() override;
      37             :   void setOperation(absl::string_view operation) override;
      38             :   void setTag(absl::string_view name, const absl::string_view) override;
      39             :   void log(SystemTime timestamp, const std::string& event) override;
      40             :   void injectContext(Tracing::TraceContext& trace_context,
      41             :                      const Upstream::HostDescriptionConstSharedPtr&) override;
      42             :   Tracing::SpanPtr spawnChild(const Tracing::Config& config, const std::string& name,
      43             :                               SystemTime start_time) override;
      44             :   void setSampled(bool) override;
      45             :   std::string getBaggage(absl::string_view key) override;
      46             :   void setBaggage(absl::string_view key, absl::string_view value) override;
      47             : 
      48             :   // TODO: This method is unimplemented for OpenTracing.
      49           0 :   std::string getTraceIdAsHex() const override { return EMPTY_STRING; };
      50             : 
      51             : private:
      52             :   OpenTracingDriver& driver_;
      53             :   opentracing::FinishSpanOptions finish_options_;
      54             :   std::unique_ptr<opentracing::Span> span_;
      55             : };
      56             : 
      57             : /**
      58             :  * This driver can be used by tracing libraries implementing the OpenTracing API (see
      59             :  * https://github.com/opentracing/opentracing-cpp) to hook into Envoy's tracing functionality with a
      60             :  * minimal amount of effort. Libraries need only provide an opentracing::Tracer implementation; the
      61             :  * rest of span creation is taken care of by this class.
      62             :  */
      63             : class OpenTracingDriver : public Tracing::Driver, protected Logger::Loggable<Logger::Id::tracing> {
      64             : public:
      65             :   explicit OpenTracingDriver(Stats::Scope& scope);
      66             : 
      67             :   // Tracing::Driver
      68             :   Tracing::SpanPtr startSpan(const Tracing::Config& config, Tracing::TraceContext& trace_context,
      69             :                              const StreamInfo::StreamInfo& stream_info,
      70             :                              const std::string& operation_name,
      71             :                              Tracing::Decision tracing_decision) override;
      72             : 
      73             :   virtual opentracing::Tracer& tracer() PURE;
      74             : 
      75             :   enum class PropagationMode { SingleHeader, TracerNative };
      76             : 
      77             :   /**
      78             :    * Controls how span context is propagated in HTTP headers. PropagationMode::SingleHeader will
      79             :    * propagate span context as a single header within the inline header HeaderMap::OtSpanContext;
      80             :    * otherwise, span context will be propagated using the native format of the tracing library.
      81             :    */
      82           0 :   virtual PropagationMode propagationMode() const { return PropagationMode::SingleHeader; }
      83             : 
      84           0 :   OpenTracingTracerStats& tracerStats() { return tracer_stats_; }
      85             : 
      86             : private:
      87             :   OpenTracingTracerStats tracer_stats_;
      88             : };
      89             : } // namespace Ot
      90             : } // namespace Common
      91             : } // namespace Tracers
      92             : } // namespace Extensions
      93             : } // namespace Envoy

Generated by: LCOV version 1.15