1
#pragma once
2

            
3
#include <memory>
4
#include <string>
5
#include <vector>
6

            
7
#include "envoy/common/pure.h"
8
#include "envoy/config/trace/v3/zipkin.pb.h"
9
#include "envoy/tracing/trace_config.h"
10

            
11
#include "source/extensions/tracers/zipkin/span_context.h"
12

            
13
namespace Envoy {
14
namespace Extensions {
15
namespace Tracers {
16
namespace Zipkin {
17

            
18
using TraceContextOption = envoy::config::trace::v3::ZipkinConfig::TraceContextOption;
19

            
20
class Span;
21
using SpanPtr = std::unique_ptr<Span>;
22

            
23
/**
24
 * Abstract class that delegates to users of the Tracer class the responsibility
25
 * of "reporting" a Zipkin span that has ended its life cycle. "Reporting" can mean that the
26
 * span will be sent to out to Zipkin, or buffered so that it can be sent out later.
27
 */
28
class Reporter {
29
public:
30
  /**
31
   * Destructor.
32
   */
33
102
  virtual ~Reporter() = default;
34

            
35
  /**
36
   * Method that a concrete Reporter class must implement to handle finished spans.
37
   * For example, a span-buffer management policy could be implemented.
38
   *
39
   * This method is invoked by the Span object when its finish() method is called.
40
   *
41
   * @param span The span that needs action.
42
   */
43
  virtual void reportSpan(Span&& span) PURE;
44
};
45

            
46
using ReporterPtr = std::unique_ptr<Reporter>;
47

            
48
/**
49
 * This interface must be observed by a Zipkin tracer.
50
 */
51
class TracerInterface : public Reporter {
52
public:
53
  /**
54
   * Creates a "root" Zipkin span.
55
   *
56
   * @param config The tracing configuration
57
   * @param span_name Name of the new span.
58
   * @param start_time The time indicating the beginning of the span.
59
   * @return SpanPtr The root span.
60
   */
61
  virtual SpanPtr startSpan(const Tracing::Config&, const std::string& span_name,
62
                            SystemTime timestamp) PURE;
63

            
64
  /**
65
   * Depending on the given context, creates either a "child" or a "shared-context" Zipkin span.
66
   *
67
   * @param config The tracing configuration
68
   * @param span_name Name of the new span.
69
   * @param start_time The time indicating the beginning of the span.
70
   * @param previous_context The context of the span preceding the one to be created.
71
   * @return SpanPtr The child span.
72
   */
73
  virtual SpanPtr startSpan(const Tracing::Config&, const std::string& span_name,
74
                            SystemTime timestamp, const SpanContext& previous_context) PURE;
75

            
76
  /**
77
   * Gets the current trace context option for header injection behavior.
78
   * @return The current trace context option.
79
   */
80
  virtual TraceContextOption traceContextOption() const PURE;
81
};
82

            
83
/**
84
 * Buffered pending spans serializer.
85
 */
86
class Serializer {
87
public:
88
55
  virtual ~Serializer() = default;
89

            
90
  /**
91
   * Serialize buffered pending spans.
92
   *
93
   * @return std::string serialized buffered pending spans.
94
   */
95
  virtual std::string serialize(const std::vector<Span>& spans) PURE;
96
};
97

            
98
using SerializerPtr = std::unique_ptr<Serializer>;
99

            
100
} // namespace Zipkin
101
} // namespace Tracers
102
} // namespace Extensions
103
} // namespace Envoy