Line data Source code
1 : #pragma once 2 : 3 : #include <string> 4 : 5 : #include "envoy/data/accesslog/v3/accesslog.pb.h" 6 : #include "envoy/stream_info/stream_info.h" 7 : #include "envoy/tracing/trace_context.h" 8 : 9 : #include "absl/container/flat_hash_map.h" 10 : #include "absl/strings/string_view.h" 11 : 12 : namespace Envoy { 13 : namespace Tracing { 14 : 15 : /** 16 : * The context for the custom tag to obtain the tag value. 17 : */ 18 : struct CustomTagContext { 19 : const TraceContext& trace_context; 20 : const StreamInfo::StreamInfo& stream_info; 21 : }; 22 : 23 : class Span; 24 : 25 : /** 26 : * Tracing custom tag, with tag name and how it would be applied to the span. 27 : */ 28 : class CustomTag { 29 : public: 30 0 : virtual ~CustomTag() = default; 31 : 32 : /** 33 : * @return the tag name view. 34 : */ 35 : virtual absl::string_view tag() const PURE; 36 : 37 : /** 38 : * The way how to apply the custom tag to the span, 39 : * generally obtain the tag value from the context and attached it to the span. 40 : * @param span the active span. 41 : * @param ctx the custom tag context. 42 : */ 43 : virtual void applySpan(Span& span, const CustomTagContext& ctx) const PURE; 44 : 45 : /** 46 : * Get string tag value from various type of custom tags. (e.g. Literal, Environment, Header, 47 : * Metadata) 48 : * @param log entry. 49 : * @param ctx the custom tag context. 50 : */ 51 : virtual void applyLog(envoy::data::accesslog::v3::AccessLogCommon& entry, 52 : const CustomTagContext& ctx) const PURE; 53 : }; 54 : 55 : using CustomTagConstSharedPtr = std::shared_ptr<const CustomTag>; 56 : using CustomTagMap = absl::flat_hash_map<std::string, CustomTagConstSharedPtr>; 57 : 58 : } // namespace Tracing 59 : } // namespace Envoy