Line data Source code
1 : #pragma once 2 : 3 : #include "envoy/common/exception.h" 4 : #include "envoy/tracing/tracer.h" 5 : 6 : #include "source/common/http/header_map_impl.h" 7 : 8 : namespace Envoy { 9 : namespace Extensions { 10 : namespace Tracers { 11 : namespace Zipkin { 12 : 13 : class SpanContext; 14 : 15 : struct ExtractorException : public EnvoyException { 16 0 : ExtractorException(const std::string& what) : EnvoyException(what) {} 17 : }; 18 : 19 : /** 20 : * This class is used to SpanContext extracted from the Http header 21 : */ 22 : class SpanContextExtractor { 23 : public: 24 : SpanContextExtractor(Tracing::TraceContext& trace_context); 25 : ~SpanContextExtractor(); 26 : bool extractSampled(const Tracing::Decision tracing_decision); 27 : std::pair<SpanContext, bool> extractSpanContext(bool is_sampled); 28 : 29 : private: 30 : /* 31 : * Use to SpanContext extracted from B3 single format Http header 32 : * b3: {x-b3-traceid}-{x-b3-spanid}-{if x-b3-flags 'd' else x-b3-sampled}-{x-b3-parentspanid} 33 : * See: "https://github.com/openzipkin/b3-propagation 34 : */ 35 : std::pair<SpanContext, bool> extractSpanContextFromB3SingleFormat(bool is_sampled); 36 : bool tryExtractSampledFromB3SingleFormat(); 37 : const Tracing::TraceContext& trace_context_; 38 : }; 39 : 40 : } // namespace Zipkin 41 : } // namespace Tracers 42 : } // namespace Extensions 43 : } // namespace Envoy