1
#include "source/common/tracing/tracer_config_impl.h"
2

            
3
namespace Envoy {
4
namespace Tracing {
5

            
6
ConnectionManagerTracingConfig::ConnectionManagerTracingConfig(
7
    envoy::config::core::v3::TrafficDirection traffic_direction,
8
    const ConnectionManagerTracingConfigProto& tracing_config,
9
50
    const Formatter::CommandParserPtrVector& command_parsers) {
10

            
11
  // Listener level traffic direction overrides the operation name
12
50
  switch (traffic_direction) {
13
    PANIC_ON_PROTO_ENUM_SENTINEL_VALUES;
14
46
  case envoy::config::core::v3::UNSPECIFIED:
15
    // Continuing legacy behavior; if unspecified, we treat this as ingress.
16
46
    operation_name_ = Tracing::OperationName::Ingress;
17
46
    break;
18
1
  case envoy::config::core::v3::INBOUND:
19
1
    operation_name_ = Tracing::OperationName::Ingress;
20
1
    break;
21
3
  case envoy::config::core::v3::OUTBOUND:
22
3
    operation_name_ = Tracing::OperationName::Egress;
23
3
    break;
24
50
  }
25

            
26
50
  spawn_upstream_span_ =
27
50
      PROTOBUF_GET_WRAPPED_OR_DEFAULT(tracing_config, spawn_upstream_span, false);
28

            
29
50
  no_context_propagation_ = tracing_config.no_context_propagation();
30

            
31
51
  for (const auto& tag : tracing_config.custom_tags()) {
32
10
    custom_tags_.emplace(tag.tag(),
33
10
                         Tracing::CustomTagUtility::createCustomTag(tag, command_parsers));
34
10
  }
35

            
36
50
  client_sampling_.set_numerator(
37
50
      tracing_config.has_client_sampling() ? tracing_config.client_sampling().value() : 100);
38

            
39
  // TODO: Random sampling historically was an integer and default to out of 10,000. We should
40
  // deprecate that and move to a straight fractional percent config.
41
50
  uint64_t random_sampling_numerator{PROTOBUF_PERCENT_TO_ROUNDED_INTEGER_OR_DEFAULT(
42
50
      tracing_config, random_sampling, 10000, 10000)};
43
50
  random_sampling_.set_numerator(random_sampling_numerator);
44
50
  random_sampling_.set_denominator(envoy::type::v3::FractionalPercent::TEN_THOUSAND);
45

            
46
50
  uint64_t overall_sampling_numerator{PROTOBUF_PERCENT_TO_ROUNDED_INTEGER_OR_DEFAULT(
47
50
      tracing_config, overall_sampling, 10000, 10000)};
48
50
  overall_sampling_.set_numerator(overall_sampling_numerator);
49
50
  overall_sampling_.set_denominator(envoy::type::v3::FractionalPercent::TEN_THOUSAND);
50

            
51
50
  verbose_ = tracing_config.verbose();
52
50
  max_path_tag_length_ = PROTOBUF_GET_WRAPPED_OR_DEFAULT(tracing_config, max_path_tag_length,
53
50
                                                         Tracing::DefaultMaxPathTagLength);
54

            
55
50
  if (!tracing_config.operation().empty()) {
56
1
    auto operation =
57
1
        Formatter::FormatterImpl::create(tracing_config.operation(), true, command_parsers);
58
1
    THROW_IF_NOT_OK_REF(operation.status());
59
1
    operation_ = std::move(operation.value());
60
1
  }
61

            
62
50
  if (!tracing_config.upstream_operation().empty()) {
63
1
    auto operation = Formatter::FormatterImpl::create(tracing_config.upstream_operation(), true,
64
1
                                                      command_parsers);
65
1
    THROW_IF_NOT_OK_REF(operation.status());
66
1
    upstream_operation_ = std::move(operation.value());
67
1
  }
68
50
}
69

            
70
} // namespace Tracing
71
} // namespace Envoy