1
#pragma once
2

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

            
7
#include "absl/strings/string_view.h"
8
#include "absl/types/variant.h"
9
#include "opentelemetry/common/attribute_value.h"
10
#include "opentelemetry/proto/common/v1/common.pb.h"
11
#include "opentelemetry/proto/trace/v1/trace.pb.h"
12

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

            
18
/**
19
 * @brief The type of the span.
20
 * see
21
 * https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md#spankind
22
 */
23
using OTelSpanKind = ::opentelemetry::proto::trace::v1::Span::SpanKind;
24

            
25
/**
26
 * @brief Based on Open-telemetry OwnedAttributeValue
27
 * see
28
 * https://github.com/open-telemetry/opentelemetry-cpp/blob/main/sdk/include/opentelemetry/sdk/common/attribute_utils.h
29
 */
30
using OTelAttribute =
31
    absl::variant<bool, int32_t, uint32_t, int64_t, double, std::string, absl::string_view,
32
                  std::vector<bool>, std::vector<int32_t>, std::vector<uint32_t>,
33
                  std::vector<int64_t>, std::vector<double>, std::vector<std::string>,
34
                  std::vector<absl::string_view>, uint64_t, std::vector<uint64_t>,
35
                  std::vector<uint8_t>>;
36

            
37
/**
38
 * @brief Container holding Open-telemetry Attributes
39
 */
40
using OtelAttributes = std::map<std::string, OTelAttribute>;
41

            
42
/**
43
 * Contains utility functions  for Otel
44
 */
45
class OtlpUtils {
46

            
47
public:
48
  /**
49
   * @brief Get the User-Agent header value to be used on the OTLP exporter request.
50
   *
51
   * The header value is compliant with the OpenTelemetry specification. See:
52
   * https://github.com/open-telemetry/opentelemetry-specification/blob/v1.30.0/specification/protocol/exporter.md#user-agent
53
   * @return std::string The User-Agent for the OTLP exporters in Envoy.
54
   */
55
  static const std::string& getOtlpUserAgentHeader();
56

            
57
  /**
58
   * @brief Set the Otel attribute on a Proto Value object
59
   *
60
   * @param value_proto Proto object which gets the value set.
61
   * @param attribute_value Value to set on the proto object.
62
   */
63
  static void populateAnyValue(opentelemetry::proto::common::v1::AnyValue& value_proto,
64
                               const OTelAttribute& attribute_value);
65
};
66

            
67
} // namespace OpenTelemetry
68
} // namespace Tracers
69
} // namespace Extensions
70
} // namespace Envoy