1
#pragma once
2

            
3
#include <cstdint>
4
#include <string>
5

            
6
#include "absl/strings/string_view.h"
7

            
8
namespace Envoy {
9
namespace Extensions {
10
namespace Tracers {
11
namespace OpenTelemetry {
12

            
13
/**
14
 * This class represents the context of an OpenTelemetry span, including the following
15
 * characteristics: trace id, span id, parent id, and trace flags.
16
 */
17
class SpanContext {
18
public:
19
  /*
20
   * Default constructor creates an empty context.
21
   */
22
  SpanContext() = default;
23

            
24
  /*
25
   * Constructor that creates a context object from the supplied attributes.
26
   */
27
  SpanContext(absl::string_view version, absl::string_view trace_id, absl::string_view span_id,
28
              bool sampled, std::string tracestate)
29
81
      : version_(version), trace_id_(trace_id), span_id_(span_id), sampled_(sampled),
30
81
        tracestate_(std::move(tracestate)) {}
31

            
32
  /**
33
   * @return the span's version as a hex string.
34
   */
35
2
  const std::string& version() const { return version_; }
36

            
37
  /**
38
   * @return the span's id as a hex string.
39
   */
40
66
  const std::string& spanId() const { return span_id_; }
41

            
42
  /**
43
   * @return the trace id as an integer.
44
   */
45
56
  const std::string& traceId() const { return trace_id_; }
46

            
47
  /**
48
   * @return the sampled flag.
49
   */
50
47
  bool sampled() const { return sampled_; }
51

            
52
  /**
53
   * @return the parsed tracestate header.
54
   */
55
80
  const std::string& tracestate() const { return tracestate_; }
56

            
57
private:
58
  std::string version_;
59
  std::string trace_id_;
60
  std::string span_id_;
61
  bool sampled_{false};
62
  std::string tracestate_;
63
};
64

            
65
} // namespace OpenTelemetry
66
} // namespace Tracers
67
} // namespace Extensions
68
} // namespace Envoy