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 Formatter {
14
class Context;
15
}
16
namespace Tracing {
17

            
18
/**
19
 * The context for the custom tag to obtain the tag value.
20
 */
21
struct CustomTagContext {
22
  const TraceContext& trace_context;
23
  const StreamInfo::StreamInfo& stream_info;
24
  const Formatter::Context& formatter_context;
25
};
26

            
27
class Span;
28

            
29
/**
30
 * Tracing custom tag, with tag name and how it would be applied to the span.
31
 */
32
class CustomTag {
33
public:
34
303
  virtual ~CustomTag() = default;
35

            
36
  /**
37
   * @return the tag name view.
38
   */
39
  virtual absl::string_view tag() const PURE;
40

            
41
  /**
42
   * The way how to apply the custom tag to the span,
43
   * generally obtain the tag value from the context and attached it to the span.
44
   * @param span the active span.
45
   * @param ctx the custom tag context.
46
   */
47
  virtual void applySpan(Span& span, const CustomTagContext& ctx) const PURE;
48

            
49
  /**
50
   * Get string tag value from various type of custom tags. (e.g. Literal, Environment, Header,
51
   * Metadata)
52
   * @param log entry.
53
   * @param ctx the custom tag context.
54
   */
55
  virtual void applyLog(envoy::data::accesslog::v3::AccessLogCommon& entry,
56
                        const CustomTagContext& ctx) const PURE;
57
};
58

            
59
using CustomTagConstSharedPtr = std::shared_ptr<const CustomTag>;
60
using CustomTagMap = absl::flat_hash_map<std::string, CustomTagConstSharedPtr>;
61

            
62
} // namespace Tracing
63
} // namespace Envoy