opentelemetry-config 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.yardopts +9 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE +201 -0
- data/README.md +185 -0
- data/lib/opentelemetry/config/constants.rb +43 -0
- data/lib/opentelemetry/config/generated_constants.rb +1360 -0
- data/lib/opentelemetry/config/propagation.rb +78 -0
- data/lib/opentelemetry/config/resource.rb +127 -0
- data/lib/opentelemetry/config/trace.rb +180 -0
- data/lib/opentelemetry/config/version.rb +10 -0
- data/lib/opentelemetry/config.rb +107 -0
- data/lib/opentelemetry-config.rb +6 -0
- metadata +111 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Copyright The OpenTelemetry Authors
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
module OpenTelemetry
|
|
7
|
+
# Config module — propagation configuration helpers.
|
|
8
|
+
module Config
|
|
9
|
+
class << self
|
|
10
|
+
private
|
|
11
|
+
|
|
12
|
+
# Configures the global text-map propagator from the propagator_cfg hash.
|
|
13
|
+
def configure_propagation(propagator_cfg)
|
|
14
|
+
return unless propagator_cfg
|
|
15
|
+
|
|
16
|
+
propagators = extract_propagator_names(propagator_cfg)
|
|
17
|
+
return if propagators.empty?
|
|
18
|
+
|
|
19
|
+
composite_propagators = propagators.filter_map { |name| resolve_propagator(name) }
|
|
20
|
+
return if composite_propagators.empty?
|
|
21
|
+
|
|
22
|
+
OpenTelemetry::Context::Propagation::CompositeTextMapPropagator.compose_propagators(composite_propagators)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Extracts an ordered, deduplicated list of propagator name strings from
|
|
26
|
+
# the config. Names from +composite+ come first, then any additional names
|
|
27
|
+
# from +composite_list+ that were not already included.
|
|
28
|
+
def extract_propagator_names(cfg)
|
|
29
|
+
propagators = []
|
|
30
|
+
Array(cfg.composite).each do |entry|
|
|
31
|
+
next unless entry
|
|
32
|
+
|
|
33
|
+
entry.members.each do |m|
|
|
34
|
+
next if m == :additional_properties
|
|
35
|
+
|
|
36
|
+
propagators << m.to_s if entry[m]
|
|
37
|
+
end
|
|
38
|
+
(entry.additional_properties || {}).each_key { |k| propagators << k.to_s }
|
|
39
|
+
end
|
|
40
|
+
propagators += cfg.composite_list.split(',').map(&:strip) if cfg.composite_list.is_a?(String)
|
|
41
|
+
propagators.uniq
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Returns a propagator instance for the given name, or nil with a warning.
|
|
45
|
+
def resolve_propagator(name)
|
|
46
|
+
case name
|
|
47
|
+
when 'tracecontext'
|
|
48
|
+
OpenTelemetry::Trace::Propagation::TraceContext.text_map_propagator
|
|
49
|
+
when 'baggage'
|
|
50
|
+
OpenTelemetry::Baggage::Propagation.text_map_propagator
|
|
51
|
+
when 'b3'
|
|
52
|
+
const_get_propagator('OpenTelemetry::Propagator::B3::Single')
|
|
53
|
+
when 'b3multi'
|
|
54
|
+
const_get_propagator('OpenTelemetry::Propagator::B3::Multi')
|
|
55
|
+
when 'jaeger'
|
|
56
|
+
const_get_propagator('OpenTelemetry::Propagator::Jaeger')
|
|
57
|
+
when 'ottrace'
|
|
58
|
+
const_get_propagator('OpenTelemetry::Propagator::OTTrace')
|
|
59
|
+
when 'xray'
|
|
60
|
+
const_get_propagator('OpenTelemetry::Propagator::XRay')
|
|
61
|
+
when 'google_cloud_trace_context'
|
|
62
|
+
const_get_propagator('OpenTelemetry::Propagator::GoogleCloudTraceContext')
|
|
63
|
+
else
|
|
64
|
+
OpenTelemetry.logger.warn("Unknown propagator: #{name}")
|
|
65
|
+
nil
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Looks up a propagator class by fully-qualified name and returns its text_map_propagator.
|
|
70
|
+
def const_get_propagator(class_name)
|
|
71
|
+
Kernel.const_get(class_name).text_map_propagator
|
|
72
|
+
rescue NameError
|
|
73
|
+
OpenTelemetry.logger.warn("Propagator #{class_name} not available — is the gem installed?")
|
|
74
|
+
nil
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Copyright The OpenTelemetry Authors
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
module OpenTelemetry
|
|
7
|
+
# Config module — resource configuration helpers.
|
|
8
|
+
module Config
|
|
9
|
+
class << self
|
|
10
|
+
private
|
|
11
|
+
|
|
12
|
+
# Priority: attributes > attribute_list > detected > base
|
|
13
|
+
def build_resource(resource_cfg)
|
|
14
|
+
base = OpenTelemetry::SDK::Resources::Resource.default
|
|
15
|
+
|
|
16
|
+
return base unless resource_cfg
|
|
17
|
+
|
|
18
|
+
detected = build_detected_attributes(resource_cfg.detection_development)
|
|
19
|
+
|
|
20
|
+
explicit = {}
|
|
21
|
+
Array(resource_cfg.attributes).each do |attr|
|
|
22
|
+
next unless attr.name && !attr.value.nil?
|
|
23
|
+
|
|
24
|
+
explicit[attr.name] = coerce_attribute_value(attr.value, attr.type)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
if resource_cfg.attributes_list.is_a?(String)
|
|
28
|
+
resource_cfg.attributes_list.split(',').each do |pair|
|
|
29
|
+
key, value = pair.strip.split('=', 2)
|
|
30
|
+
explicit[key] ||= value if key && value
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
OpenTelemetry.logger.warn('Config: schema_url is supported; ignoring.') if resource_cfg.schema_url
|
|
35
|
+
|
|
36
|
+
attrs = detected.merge(explicit)
|
|
37
|
+
custom = OpenTelemetry::SDK::Resources::Resource.create(attrs)
|
|
38
|
+
base.merge(custom)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# type coercion
|
|
42
|
+
def coerce_attribute_value(value, type)
|
|
43
|
+
case type
|
|
44
|
+
when 'string' then value.to_s
|
|
45
|
+
when 'bool' then coerce_bool?(value)
|
|
46
|
+
when 'int' then Integer(value)
|
|
47
|
+
when 'double' then Float(value)
|
|
48
|
+
when 'string_array' then Array(value).map(&:to_s)
|
|
49
|
+
when 'bool_array' then Array(value).map { |v| coerce_bool?(v) }
|
|
50
|
+
when 'int_array' then Array(value).map { |v| Integer(v) }
|
|
51
|
+
when 'double_array' then Array(value).map { |v| Float(v) }
|
|
52
|
+
else value # no type field → use the YAML-parsed value as-is
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def coerce_bool?(value)
|
|
57
|
+
case value
|
|
58
|
+
when true, 'true', 1 then true
|
|
59
|
+
when false, 'false', 0 then false
|
|
60
|
+
else !!value
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Extract the attributes from an ExperimentalResourceDetection struct.
|
|
65
|
+
def build_detected_attributes(detection_cfg)
|
|
66
|
+
return {} unless detection_cfg
|
|
67
|
+
|
|
68
|
+
included_patterns = Array(detection_cfg.attributes&.included)
|
|
69
|
+
excluded_patterns = Array(detection_cfg.attributes&.excluded)
|
|
70
|
+
detector_names = detector_names_from(detection_cfg.detectors)
|
|
71
|
+
|
|
72
|
+
raw = detector_names.each_with_object({}) do |name, attrs|
|
|
73
|
+
attrs.merge!(run_detector(name).attribute_enumerator.to_h)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# File.fnmatch: * matches any chars except /, so "process.*" covers
|
|
77
|
+
# "process.pid", "process.runtime.name", etc.
|
|
78
|
+
raw.select do |key, _|
|
|
79
|
+
included = included_patterns.empty? || included_patterns.any? { |pat| File.fnmatch(pat, key) }
|
|
80
|
+
excluded = excluded_patterns.any? { |pat| File.fnmatch(pat, key) }
|
|
81
|
+
included && !excluded
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Flattens an array of ExperimentalResourceDetector structs into the list
|
|
86
|
+
# of detector names whose presence flag is set (e.g. container, host).
|
|
87
|
+
def detector_names_from(detectors)
|
|
88
|
+
Array(detectors).flat_map do |detector|
|
|
89
|
+
next [] unless detector
|
|
90
|
+
|
|
91
|
+
names = detector.members.filter_map do |m|
|
|
92
|
+
next if m == :additional_properties
|
|
93
|
+
|
|
94
|
+
m.to_s if detector[m]
|
|
95
|
+
end
|
|
96
|
+
names + Array(detector.additional_properties&.keys).map(&:to_s)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Returns a Resource for the given detector name.
|
|
101
|
+
def run_detector(name)
|
|
102
|
+
case name
|
|
103
|
+
when 'container'
|
|
104
|
+
detect_resource('OpenTelemetry::Resource::Detector::Container')
|
|
105
|
+
when 'aws'
|
|
106
|
+
# Run all AWS sub-detectors; each returns an empty resource if not on that platform.
|
|
107
|
+
detect_resource('OpenTelemetry::Resource::Detector::AWS', %i[ec2 ecs eks lambda])
|
|
108
|
+
when 'azure'
|
|
109
|
+
detect_resource('OpenTelemetry::Resource::Detector::Azure')
|
|
110
|
+
when 'google_cloud_platform'
|
|
111
|
+
detect_resource('OpenTelemetry::Resource::Detector::GoogleCloudPlatform')
|
|
112
|
+
else
|
|
113
|
+
OpenTelemetry.logger.warn("Config: unknown resource detector '#{name}'; skipping.")
|
|
114
|
+
OpenTelemetry::SDK::Resources::Resource.create({})
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# Looks up a resource detector class by fully-qualified name and calls detect.
|
|
119
|
+
def detect_resource(class_name, *)
|
|
120
|
+
Kernel.const_get(class_name).detect(*)
|
|
121
|
+
rescue NameError
|
|
122
|
+
OpenTelemetry.logger.warn("Config: resource detector '#{class_name}' is not available — is the gem installed?")
|
|
123
|
+
OpenTelemetry::SDK::Resources::Resource.create({})
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Copyright The OpenTelemetry Authors
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
module OpenTelemetry
|
|
7
|
+
module Config
|
|
8
|
+
# Trace component builder for configuring TracerProvider from declarative config.
|
|
9
|
+
module Trace
|
|
10
|
+
module_function
|
|
11
|
+
|
|
12
|
+
# Builds a TracerProvider from the parsed YAML tracer_provider config.
|
|
13
|
+
# Returns a noop-configured provider if config is nil.
|
|
14
|
+
def build_tracer_provider(config, resource)
|
|
15
|
+
return OpenTelemetry::Trace::TracerProvider.new unless config
|
|
16
|
+
|
|
17
|
+
sampler = build_sampler(config.sampler)
|
|
18
|
+
span_limits = build_span_limits(config.limits)
|
|
19
|
+
|
|
20
|
+
tp = OpenTelemetry::SDK::Trace::TracerProvider.new(
|
|
21
|
+
resource: resource,
|
|
22
|
+
sampler: sampler,
|
|
23
|
+
span_limits: span_limits
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
Array(config.processors).each do |proc_cfg|
|
|
27
|
+
processor = build_span_processor(proc_cfg)
|
|
28
|
+
tp.add_span_processor(processor) if processor
|
|
29
|
+
rescue StandardError => e
|
|
30
|
+
OpenTelemetry.logger.warn("Failed to build span processor: #{e.message}")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
tp
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Builds a span processor (simple or batch) from config hash.
|
|
37
|
+
def build_span_processor(proc_cfg)
|
|
38
|
+
raise ArgumentError, 'must not specify multiple span processor type' if proc_cfg.batch && proc_cfg.simple
|
|
39
|
+
|
|
40
|
+
if proc_cfg.batch
|
|
41
|
+
build_batch_span_processor(proc_cfg.batch)
|
|
42
|
+
elsif proc_cfg.simple
|
|
43
|
+
build_simple_span_processor(proc_cfg.simple)
|
|
44
|
+
else
|
|
45
|
+
raise ArgumentError, 'unsupported span processor type, must be one of simple or batch'
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Builds a BatchSpanProcessor with exporter and optional tuning options.
|
|
50
|
+
def build_batch_span_processor(cfg)
|
|
51
|
+
exporter = build_span_exporter(cfg.exporter)
|
|
52
|
+
opts = {
|
|
53
|
+
schedule_delay: cfg.schedule_delay&.to_f,
|
|
54
|
+
exporter_timeout: cfg.export_timeout&.to_f,
|
|
55
|
+
max_queue_size: cfg.max_queue_size&.to_i,
|
|
56
|
+
max_export_batch_size: cfg.max_export_batch_size&.to_i
|
|
57
|
+
}.compact
|
|
58
|
+
|
|
59
|
+
OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new(exporter, **opts)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Builds a SimpleSpanProcessor wrapping the configured exporter.
|
|
63
|
+
def build_simple_span_processor(cfg)
|
|
64
|
+
exporter = build_span_exporter(cfg.exporter)
|
|
65
|
+
OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new(exporter)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Builds a span exporter from config; supports console and otlp_http.
|
|
69
|
+
def build_span_exporter(exp_cfg)
|
|
70
|
+
raise ArgumentError, 'no exporter config' unless exp_cfg
|
|
71
|
+
|
|
72
|
+
configured = 0
|
|
73
|
+
exporter = nil
|
|
74
|
+
|
|
75
|
+
if exp_cfg.console
|
|
76
|
+
configured += 1
|
|
77
|
+
exporter = OpenTelemetry::SDK::Trace::Export::ConsoleSpanExporter.new
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
if exp_cfg.otlp_http
|
|
81
|
+
configured += 1
|
|
82
|
+
exporter = build_otlp_http_span_exporter(exp_cfg.otlp_http)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
raise ArgumentError, 'must not specify multiple exporters' if configured > 1
|
|
86
|
+
raise ArgumentError, 'no valid span exporter' if exporter.nil?
|
|
87
|
+
|
|
88
|
+
exporter
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Builds an OTLP HTTP span exporter from the given endpoint/headers config.
|
|
92
|
+
def build_otlp_http_span_exporter(cfg)
|
|
93
|
+
headers = headers_to_hash(cfg)
|
|
94
|
+
opts = {
|
|
95
|
+
endpoint: cfg.endpoint,
|
|
96
|
+
headers: headers.empty? ? nil : headers,
|
|
97
|
+
compression: cfg.compression,
|
|
98
|
+
timeout: cfg.timeout && (cfg.timeout / 1000.0) # YAML ms → Ruby seconds
|
|
99
|
+
}.compact
|
|
100
|
+
|
|
101
|
+
OpenTelemetry::Exporter::OTLP::Exporter.new(**opts)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Builds a sampler from config; defaults to ParentBased(ALWAYS_ON).
|
|
105
|
+
def build_sampler(sampler_cfg)
|
|
106
|
+
s = OpenTelemetry::SDK::Trace::Samplers
|
|
107
|
+
|
|
108
|
+
# Default: parent-based with always_on root
|
|
109
|
+
return s.parent_based(root: s::ALWAYS_ON) unless sampler_cfg
|
|
110
|
+
|
|
111
|
+
if sampler_cfg.parent_based
|
|
112
|
+
build_parent_based_sampler(sampler_cfg.parent_based)
|
|
113
|
+
elsif sampler_cfg.always_on
|
|
114
|
+
s::ALWAYS_ON
|
|
115
|
+
elsif sampler_cfg.always_off
|
|
116
|
+
s::ALWAYS_OFF
|
|
117
|
+
elsif sampler_cfg.trace_id_ratio_based
|
|
118
|
+
ratio = sampler_cfg.trace_id_ratio_based.ratio || 1.0
|
|
119
|
+
s.trace_id_ratio_based(ratio.to_f)
|
|
120
|
+
else
|
|
121
|
+
s.parent_based(root: s::ALWAYS_ON)
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Builds a ParentBased sampler with configurable root and remote/local delegates.
|
|
126
|
+
def build_parent_based_sampler(cfg)
|
|
127
|
+
s = OpenTelemetry::SDK::Trace::Samplers
|
|
128
|
+
|
|
129
|
+
root = cfg.root ? build_sampler(cfg.root) : s::ALWAYS_ON
|
|
130
|
+
|
|
131
|
+
opts = {
|
|
132
|
+
root: root,
|
|
133
|
+
remote_parent_sampled: cfg.remote_parent_sampled && build_sampler(cfg.remote_parent_sampled),
|
|
134
|
+
remote_parent_not_sampled: cfg.remote_parent_not_sampled && build_sampler(cfg.remote_parent_not_sampled),
|
|
135
|
+
local_parent_sampled: cfg.local_parent_sampled && build_sampler(cfg.local_parent_sampled),
|
|
136
|
+
local_parent_not_sampled: cfg.local_parent_not_sampled && build_sampler(cfg.local_parent_not_sampled)
|
|
137
|
+
}.compact
|
|
138
|
+
|
|
139
|
+
s.parent_based(**opts)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# Builds SpanLimits from config; returns the SDK default when config is nil.
|
|
143
|
+
def build_span_limits(limits_cfg)
|
|
144
|
+
return OpenTelemetry::SDK::Trace::SpanLimits::DEFAULT unless limits_cfg
|
|
145
|
+
|
|
146
|
+
opts = {
|
|
147
|
+
attribute_count_limit: limits_cfg.attribute_count_limit,
|
|
148
|
+
attribute_length_limit: limits_cfg.attribute_value_length_limit,
|
|
149
|
+
event_count_limit: limits_cfg.event_count_limit,
|
|
150
|
+
link_count_limit: limits_cfg.link_count_limit,
|
|
151
|
+
event_attribute_count_limit: limits_cfg.event_attribute_count_limit,
|
|
152
|
+
link_attribute_count_limit: limits_cfg.link_attribute_count_limit
|
|
153
|
+
}.compact
|
|
154
|
+
|
|
155
|
+
OpenTelemetry::SDK::Trace::SpanLimits.new(**opts)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
# Converts the OTLP exporter headers (array of NameStringValuePair structs)
|
|
159
|
+
# into a flat Hash. Falls back to the comma-separated headers_list string.
|
|
160
|
+
def headers_to_hash(cfg)
|
|
161
|
+
headers = {}
|
|
162
|
+
|
|
163
|
+
Array(cfg.headers).each do |pair|
|
|
164
|
+
headers[pair.name] = pair.value if pair&.name
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
if headers.empty? && cfg.headers_list.is_a?(String)
|
|
168
|
+
cfg.headers_list.split(',').each do |entry|
|
|
169
|
+
key, value = entry.strip.split('=', 2)
|
|
170
|
+
headers[key] = value if key && value
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
headers
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
private_constant :Trace
|
|
179
|
+
end
|
|
180
|
+
end
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Copyright The OpenTelemetry Authors
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require 'date'
|
|
7
|
+
require 'yaml'
|
|
8
|
+
|
|
9
|
+
require_relative 'config/propagation'
|
|
10
|
+
require_relative 'config/resource'
|
|
11
|
+
require_relative 'config/constants'
|
|
12
|
+
require_relative 'config/trace'
|
|
13
|
+
|
|
14
|
+
module OpenTelemetry
|
|
15
|
+
# Config module handles declarative configuration of OpenTelemetry components
|
|
16
|
+
# from YAML files.
|
|
17
|
+
module Config
|
|
18
|
+
ENV_CONFIG_FILE = 'OTEL_CONFIG_FILE'
|
|
19
|
+
private_constant :ENV_CONFIG_FILE
|
|
20
|
+
|
|
21
|
+
class << self
|
|
22
|
+
# Parses the file referenced by +OTEL_CONFIG_FILE+, creates the components
|
|
23
|
+
# it describes, and installs them as the global OpenTelemetry state.
|
|
24
|
+
#
|
|
25
|
+
# @return [RubySDK] the installed SDK handle
|
|
26
|
+
def configure
|
|
27
|
+
install(create(parse(ENV.fetch(ENV_CONFIG_FILE, nil))))
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Same as {configure}, but reads the configuration from an explicit path.
|
|
31
|
+
#
|
|
32
|
+
# @param path [String] path to a declarative configuration YAML file
|
|
33
|
+
# @return [RubySDK] the installed SDK handle
|
|
34
|
+
def configure_from_file(path)
|
|
35
|
+
install(create(parse(path)))
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Parses a declarative configuration file into the configuration model.
|
|
39
|
+
#
|
|
40
|
+
# @param path [String, nil] path to a declarative configuration YAML file
|
|
41
|
+
# @return [Model::OpenTelemetryConfiguration, nil] nil when the file is
|
|
42
|
+
# unset, missing, or invalid
|
|
43
|
+
def parse(path)
|
|
44
|
+
if path.to_s.empty?
|
|
45
|
+
OpenTelemetry.logger.info('No OTEL_CONFIG_FILE defined.')
|
|
46
|
+
return nil
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
content = File.read(path)
|
|
50
|
+
OpenTelemetry::Config::Model::OpenTelemetryConfiguration.from_hash(YAML.safe_load(content, permitted_classes: [Date, Time]))
|
|
51
|
+
rescue Errno::ENOENT => e
|
|
52
|
+
OpenTelemetry.logger.error("Config file not found: #{e.message}")
|
|
53
|
+
nil
|
|
54
|
+
rescue Psych::SyntaxError => e
|
|
55
|
+
OpenTelemetry.logger.error("YAML parse error: #{e.message}")
|
|
56
|
+
nil
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Creates the components described by a configuration model without
|
|
60
|
+
# modifying global OpenTelemetry state.
|
|
61
|
+
#
|
|
62
|
+
# @param config [Model::OpenTelemetryConfiguration, nil]
|
|
63
|
+
# @return [RubySDK] {NOOP_SDK} when the configuration is absent, invalid,
|
|
64
|
+
# disabled, or opentelemetry-sdk isn't loaded
|
|
65
|
+
def create(config)
|
|
66
|
+
return NOOP_SDK if config.nil?
|
|
67
|
+
|
|
68
|
+
unless defined?(OpenTelemetry::SDK)
|
|
69
|
+
warn '[opentelemetry-config] opentelemetry-sdk is not loaded. ' \
|
|
70
|
+
'Add `gem "opentelemetry-sdk"` to your Gemfile.'
|
|
71
|
+
return NOOP_SDK
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
if config.disabled
|
|
75
|
+
OpenTelemetry.logger.info('OpenTelemetry SDK disabled by configuration.')
|
|
76
|
+
return NOOP_SDK
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
resource = build_resource(config.resource)
|
|
80
|
+
|
|
81
|
+
# tracer_provider will be noop if opentelemetry-sdk is not installed
|
|
82
|
+
tracer_provider = Trace.build_tracer_provider(config.tracer_provider, resource)
|
|
83
|
+
|
|
84
|
+
propagators = configure_propagation(config.propagator)
|
|
85
|
+
|
|
86
|
+
RubySDK.new(
|
|
87
|
+
tracer_provider: tracer_provider,
|
|
88
|
+
propagator: propagators,
|
|
89
|
+
resource: resource
|
|
90
|
+
)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Assigns the components of a RubySDK to the global OpenTelemetry state.
|
|
94
|
+
# NOOP_SDK will skip installation and leave the global state untouched.
|
|
95
|
+
#
|
|
96
|
+
# @param ruby_sdk [RubySDK]
|
|
97
|
+
# @return [RubySDK] the same SDK handle
|
|
98
|
+
def install(ruby_sdk)
|
|
99
|
+
return ruby_sdk if ruby_sdk.equal?(NOOP_SDK)
|
|
100
|
+
|
|
101
|
+
OpenTelemetry.tracer_provider = ruby_sdk.tracer_provider if ruby_sdk.tracer_provider
|
|
102
|
+
OpenTelemetry.propagation = ruby_sdk.propagator if ruby_sdk.propagator
|
|
103
|
+
ruby_sdk
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: opentelemetry-config
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- OpenTelemetry Authors
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: opentelemetry-api
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: 1.11.0
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: 1.11.0
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: opentelemetry-common
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0.25'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0.25'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: opentelemetry-exporter-otlp
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: 0.34.1
|
|
47
|
+
type: :runtime
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: 0.34.1
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: opentelemetry-sdk
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - "~>"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: 1.13.0
|
|
61
|
+
type: :runtime
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: 1.13.0
|
|
68
|
+
email:
|
|
69
|
+
- cncf-opentelemetry-contributors@lists.cncf.io
|
|
70
|
+
executables: []
|
|
71
|
+
extensions: []
|
|
72
|
+
extra_rdoc_files: []
|
|
73
|
+
files:
|
|
74
|
+
- ".yardopts"
|
|
75
|
+
- CHANGELOG.md
|
|
76
|
+
- LICENSE
|
|
77
|
+
- README.md
|
|
78
|
+
- lib/opentelemetry-config.rb
|
|
79
|
+
- lib/opentelemetry/config.rb
|
|
80
|
+
- lib/opentelemetry/config/constants.rb
|
|
81
|
+
- lib/opentelemetry/config/generated_constants.rb
|
|
82
|
+
- lib/opentelemetry/config/propagation.rb
|
|
83
|
+
- lib/opentelemetry/config/resource.rb
|
|
84
|
+
- lib/opentelemetry/config/trace.rb
|
|
85
|
+
- lib/opentelemetry/config/version.rb
|
|
86
|
+
homepage: https://github.com/open-telemetry/opentelemetry-ruby
|
|
87
|
+
licenses:
|
|
88
|
+
- Apache-2.0
|
|
89
|
+
metadata:
|
|
90
|
+
changelog_uri: https://rubydoc.info/gems/opentelemetry-config/0.1.0/file/CHANGELOG.md
|
|
91
|
+
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/opentelemetry-config/v0.1.0/config
|
|
92
|
+
bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
|
|
93
|
+
documentation_uri: https://rubydoc.info/gems/opentelemetry-config/0.1.0
|
|
94
|
+
rdoc_options: []
|
|
95
|
+
require_paths:
|
|
96
|
+
- lib
|
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
98
|
+
requirements:
|
|
99
|
+
- - ">="
|
|
100
|
+
- !ruby/object:Gem::Version
|
|
101
|
+
version: '3.3'
|
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
|
+
requirements:
|
|
104
|
+
- - ">="
|
|
105
|
+
- !ruby/object:Gem::Version
|
|
106
|
+
version: '0'
|
|
107
|
+
requirements: []
|
|
108
|
+
rubygems_version: 4.0.20
|
|
109
|
+
specification_version: 4
|
|
110
|
+
summary: Declarative Config implementation for OpenTelemetry
|
|
111
|
+
test_files: []
|