Module: Datadog::OpenTelemetry::Configuration::Settings

Included in:
Core::Configuration::Settings
Defined in:
lib/datadog/opentelemetry/configuration/settings.rb

Class Method Summary collapse

Class Method Details

.add_settings!(base) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/datadog/opentelemetry/configuration/settings.rb', line 61

def self.add_settings!(base)
  base.class_eval do
    settings :opentelemetry do
      settings :exporter do
        option :protocol do |o|
          o.type :string
          o.setter(&Settings.normalize_protocol('OTEL_EXPORTER_OTLP_PROTOCOL'))
          o.env 'OTEL_EXPORTER_OTLP_PROTOCOL'
          o.default 'http/protobuf'
        end

        option :timeout_millis do |o|
          o.type :int
          o.env 'OTEL_EXPORTER_OTLP_TIMEOUT'
          o.default 10_000
        end

        option :headers do |o|
          o.type :hash
          o.env 'OTEL_EXPORTER_OTLP_HEADERS'
          o.default { {} }
          o.env_parser(&Settings.headers_parser('OTEL_EXPORTER_OTLP_HEADERS'))
        end

        option :endpoint do |o|
          o.type :string, nilable: true
          o.env 'OTEL_EXPORTER_OTLP_ENDPOINT'
          o.default nil
        end
      end

      settings :metrics do
        # Metrics-specific options default to nil to detect unset state.
        # If a metrics-specific env var (e.g., OTEL_EXPORTER_OTLP_METRICS_TIMEOUT) is not set,
        # we fall back to the general OTLP env var (e.g., OTEL_EXPORTER_OTLP_TIMEOUT) per OpenTelemetry spec.
        option :enabled do |o|
          o.type :bool
          o.env 'DD_METRICS_OTEL_ENABLED'
          o.default false
        end

        option :exporter do |o|
          o.type :string
          o.env 'OTEL_METRICS_EXPORTER'
          o.default 'otlp'
        end

        option :export_interval_millis do |o|
          o.type :int
          o.env 'OTEL_METRIC_EXPORT_INTERVAL'
          o.default 10_000
        end

        option :export_timeout_millis do |o|
          o.type :int
          o.env 'OTEL_METRIC_EXPORT_TIMEOUT'
          o.default 7_500
        end

        option :temporality_preference do |o|
          o.type :string
          o.env 'OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'
          o.default 'delta'
          o.setter(&Settings.normalize_temporality_preference('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE'))
        end

        option :endpoint do |o|
          o.type :string, nilable: true
          o.env 'OTEL_EXPORTER_OTLP_METRICS_ENDPOINT'
          o.default nil
        end

        option :headers do |o|
          o.type :hash, nilable: true
          o.env 'OTEL_EXPORTER_OTLP_METRICS_HEADERS'
          o.default nil
          o.env_parser(&Settings.headers_parser('OTEL_EXPORTER_OTLP_METRICS_HEADERS'))
        end

        option :timeout_millis do |o|
          o.type :int, nilable: true
          o.env 'OTEL_EXPORTER_OTLP_METRICS_TIMEOUT'
          o.default nil
        end

        option :protocol do |o|
          o.type :string, nilable: true
          o.env 'OTEL_EXPORTER_OTLP_METRICS_PROTOCOL'
          o.default nil
          o.setter(&Settings.normalize_protocol('OTEL_EXPORTER_OTLP_METRICS_PROTOCOL'))
        end
      end
    end
  end
end

.extended(base) ⇒ Object



9
10
11
12
# File 'lib/datadog/opentelemetry/configuration/settings.rb', line 9

def self.extended(base)
  base = base.singleton_class unless base.is_a?(Class)
  add_settings!(base)
end

.headers_parser(env_var_name) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/datadog/opentelemetry/configuration/settings.rb', line 34

def self.headers_parser(env_var_name)
  lambda do |value|
    return {} if value.nil? || value.empty?

    headers = {}
    header_items = value.split(',')
    header_items.each do |key_value|
      key, header_value = key_value.split('=', 2)
      # If header is malformed, return an empty hash
      if key.nil? || header_value.nil?
        Datadog.logger.warn("#{env_var_name} has malformed header: #{key_value.inspect}")
        return {}
      end

      key.strip!
      header_value.strip!
      if key.empty? || header_value.empty?
        Datadog.logger.warn("#{env_var_name} has empty key or value in: #{key_value.inspect}")
        return {}
      end

      headers[key] = header_value
    end
    headers
  end
end

.normalize_protocol(env_var_name) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/datadog/opentelemetry/configuration/settings.rb', line 25

def self.normalize_protocol(env_var_name)
  proc do |value|
    if value && value.to_s.downcase != 'http/protobuf'
      Datadog.logger.warn("#{env_var_name}=#{value} is not supported. Using http/protobuf instead.")
    end
    'http/protobuf'
  end
end

.normalize_temporality_preference(env_var_name) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/datadog/opentelemetry/configuration/settings.rb', line 14

def self.normalize_temporality_preference(env_var_name)
  proc do |value|
    if value && value.to_s.downcase != 'delta' && value.to_s.downcase != 'cumulative'
      Datadog.logger.warn("#{env_var_name}=#{value} is not supported. Using delta instead.")
      'delta'
    else
      value
    end
  end
end