opentelemetry-sdk 0.14.0 → 1.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +110 -44
  3. data/README.md +2 -2
  4. data/lib/opentelemetry/sdk.rb +4 -3
  5. data/lib/opentelemetry/sdk/configurator.rb +52 -33
  6. data/lib/opentelemetry/sdk/forwarding_logger.rb +69 -0
  7. data/lib/opentelemetry/sdk/internal.rb +3 -3
  8. data/lib/opentelemetry/sdk/resources/constants.rb +48 -3
  9. data/lib/opentelemetry/sdk/resources/resource.rb +8 -1
  10. data/lib/opentelemetry/sdk/trace.rb +2 -3
  11. data/lib/opentelemetry/sdk/trace/event.rb +7 -36
  12. data/lib/opentelemetry/sdk/trace/export.rb +1 -2
  13. data/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb +10 -5
  14. data/lib/opentelemetry/sdk/trace/export/console_span_exporter.rb +4 -0
  15. data/lib/opentelemetry/sdk/trace/export/in_memory_span_exporter.rb +23 -4
  16. data/lib/opentelemetry/sdk/trace/export/simple_span_processor.rb +4 -2
  17. data/lib/opentelemetry/sdk/trace/export/{noop_span_exporter.rb → span_exporter.rb} +18 -7
  18. data/lib/opentelemetry/sdk/trace/span.rb +83 -39
  19. data/lib/opentelemetry/sdk/trace/span_data.rb +25 -18
  20. data/lib/opentelemetry/sdk/trace/span_limits.rb +60 -0
  21. data/lib/opentelemetry/sdk/trace/{noop_span_processor.rb → span_processor.rb} +5 -8
  22. data/lib/opentelemetry/sdk/trace/tracer.rb +1 -37
  23. data/lib/opentelemetry/sdk/trace/tracer_provider.rb +106 -19
  24. data/lib/opentelemetry/sdk/version.rb +1 -1
  25. metadata +43 -20
  26. data/lib/opentelemetry/sdk/baggage.rb +0 -16
  27. data/lib/opentelemetry/sdk/baggage/builder.rb +0 -40
  28. data/lib/opentelemetry/sdk/baggage/manager.rb +0 -97
  29. data/lib/opentelemetry/sdk/trace/config.rb +0 -18
  30. data/lib/opentelemetry/sdk/trace/config/trace_config.rb +0 -79
  31. data/lib/opentelemetry/sdk/trace/export/multi_span_exporter.rb +0 -59
  32. data/lib/opentelemetry/sdk/trace/multi_span_processor.rb +0 -86
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 86e11789326f901d3c6e768ea1eac43f49826fd762a74e1878adaaf76d398074
4
- data.tar.gz: 9431b37ace4dc00894f8aa81d89522d139120958a680141fe605a5ff73e57a66
3
+ metadata.gz: d43559eaa2be64a3597d078d032c168429702e47bdeaee1ac454dc5e74f9f496
4
+ data.tar.gz: 583f42bb1b6543d6375d3cfc8e4bd2319d5146306f42a73d726ca73f3c01e56d
5
5
  SHA512:
6
- metadata.gz: 6292a201663ec6e5a7cd54560ef25855865bc77b698fd4c80a1ee4bc4109760da9f9f3e2522753c0bcc6edd11728e0222093e3759db4466b12a423544f64358a
7
- data.tar.gz: 602740b9c995cc0b204b45c2923914e57ddeaa5ba809d06e1b6707c2340597a53a33d9311e349ea2ece7b7c45181ecdf4a8b2e33511aab70a08cb081f2d9b30e
6
+ metadata.gz: 14112a30284f0ececabcf75dda91f6634b3748c44ccec52e19c6d42e7fae59979e6ea82ef276d21ea5503d2b4f35821945b62d2b1afc83c5bcb9d4a6a9ce6bf4
7
+ data.tar.gz: 87aaa08db88b9495c86ee1135cdcbfb95827fbbed42edf3280500d86025ff269ee3af95c675e20231267e7b561082cea12df7738db004922468246ad437805fb
data/CHANGELOG.md CHANGED
@@ -1,88 +1,154 @@
1
1
  # Release History: opentelemetry-sdk
2
2
 
3
+ ### v1.0.0.rc2 / 2021-06-23
4
+
5
+ * BREAKING CHANGE: Remove optional parent_context from in_span [729](https://github.com/open-telemetry/opentelemetry-ruby/pull/729)
6
+ * BREAKING CHANGE: Replace Time.now with Process.clock_gettime [717](https://github.com/open-telemetry/opentelemetry-ruby/pull/717)
7
+ * BREAKING CHANGE: Refactor Baggage to remove Noop* [800](https://github.com/open-telemetry/opentelemetry-ruby/pull/800)
8
+ * BREAKING CHANGE: Remove unnecessary readers from SDK Tracer [820](https://github.com/open-telemetry/opentelemetry-ruby/pull/820)
9
+ - Tracer no longer surfaces attribute readers for the name, version, or tracer_provider
10
+ * BREAKING CHANGE: Total order constraint on span.status= [805](https://github.com/open-telemetry/opentelemetry-ruby/pull/805)
11
+
12
+ * ADDED: Add Tracer.non_recording_span to API [799](https://github.com/open-telemetry/opentelemetry-ruby/pull/799)
13
+ * ADDED: Add unnamed tracer warning message [830](https://github.com/open-telemetry/opentelemetry-ruby/pull/830)
14
+ * ADDED: Allow disabling of install messages [831](https://github.com/open-telemetry/opentelemetry-ruby/pull/831)
15
+ * FIXED: Rename cloud.zone to cloud.availability_zone [734](https://github.com/open-telemetry/opentelemetry-ruby/pull/734)
16
+ * FIXED: Improve attribute error messages [742](https://github.com/open-telemetry/opentelemetry-ruby/pull/742)
17
+ * FIXED: Support OTEL_SERVICE_NAME env var [806]https://github.com/open-telemetry/opentelemetry-ruby/pull/806
18
+ * FIXED: Flakey tracer provider test
19
+
20
+ ### v1.0.0.rc1 / 2021-05-21
21
+
22
+ * BREAKING CHANGE: Remove optional parent_context from in_span
23
+ * BREAKING CHANGE: Replace Time.now with Process.clock_gettime
24
+
25
+ * FIXED: Remove optional parent_context from in_span
26
+ * FIXED: Replace Time.now with Process.clock_gettime
27
+ * FIXED: Rename cloud.zone to cloud.availability_zone
28
+ * FIXED: Improve attribute error messages
29
+
30
+ ### v0.17.0 / 2021-04-22
31
+
32
+ * BREAKING CHANGE: Replace TextMapInjector/TextMapExtractor pairs with a TextMapPropagator.
33
+
34
+ [Check the propagator documentation](https://open-telemetry.github.io/opentelemetry-ruby/) for the new usage.
35
+
36
+ * ADDED: Add zipkin exporter
37
+ * ADDED: Processors validate exporters on init.
38
+ * ADDED: Add configurable truncation of span and event attribute values
39
+ * ADDED: Add simple 'recording' attr_accessor to InMemorySpanExporter
40
+ * FIXED: Typo in error message
41
+ * FIXED: Improve configuration error reporting
42
+ * FIXED: Refactor propagators to add #fields
43
+
44
+ ### v0.16.0 / 2021-03-17
45
+
46
+ * BREAKING CHANGE: Update SDK BaggageManager to match API
47
+ * BREAKING CHANGE: Implement Exporter#force_flush
48
+
49
+ * ADDED: Add force_flush to SDK's TracerProvider
50
+ * ADDED: Add k8s node to gcp resource detector
51
+ * ADDED: Add console option for OTEL_TRACES_EXPORTER
52
+ * ADDED: Span#add_attributes
53
+ * ADDED: Implement Exporter#force_flush
54
+ * FIXED: Update SDK BaggageManager to match API
55
+ * DOCS: Replace Gitter with GitHub Discussions
56
+
57
+ ### v0.15.0 / 2021-02-18
58
+
59
+ * BREAKING CHANGE: Streamline processor pipeline
60
+
61
+ * ADDED: Add instrumentation config validation
62
+ * FIXED: Streamline processor pipeline
63
+ * FIXED: OTEL_TRACE -> OTEL_TRACES env vars
64
+ * FIXED: Change limits from 1000 to 128
65
+ * FIXED: OTEL_TRACES_EXPORTER and OTEL_PROPAGATORS
66
+ * FIXED: Add thread error handling to the BSP
67
+ * DOCS: Clarify nil attribute values not allowed
68
+
3
69
  ### v0.14.0 / 2021-02-03
4
70
 
5
- * BREAKING CHANGE: Replace getter and setter callables and remove rack specific propagators
71
+ * BREAKING CHANGE: Replace getter and setter callables and remove rack specific propagators
6
72
 
7
- * ADDED: Replace getter and setter callables and remove rack specific propagators
73
+ * ADDED: Replace getter and setter callables and remove rack specific propagators
8
74
 
9
75
  ### v0.13.1 / 2021-02-01
10
76
 
11
- * FIXED: Leaky test
12
- * FIXED: Allow env var override of service.name
77
+ * FIXED: Leaky test
78
+ * FIXED: Allow env var override of service.name
13
79
 
14
80
  ### v0.13.0 / 2021-01-29
15
81
 
16
- * BREAKING CHANGE: Remove MILLIS from BatchSpanProcessor vars
82
+ * BREAKING CHANGE: Remove MILLIS from BatchSpanProcessor vars
17
83
 
18
- * ADDED: Process.runtime resource
19
- * ADDED: Provide default resource in SDK
20
- * ADDED: Add optional attributes to record_exception
21
- * FIXED: Resource.merge consistency
22
- * FIXED: Remove MILLIS from BatchSpanProcessor vars
84
+ * ADDED: Process.runtime resource
85
+ * ADDED: Provide default resource in SDK
86
+ * ADDED: Add optional attributes to record_exception
87
+ * FIXED: Resource.merge consistency
88
+ * FIXED: Remove MILLIS from BatchSpanProcessor vars
23
89
 
24
90
  ### v0.12.1 / 2021-01-13
25
91
 
26
- * FIXED: Fix several BatchSpanProcessor errors related to fork safety
27
- * FIXED: Define default value for traceid ratio
92
+ * FIXED: Fix several BatchSpanProcessor errors related to fork safety
93
+ * FIXED: Define default value for traceid ratio
28
94
 
29
95
  ### v0.12.0 / 2020-12-24
30
96
 
31
- * ADDED: Structured error handling
32
- * ADDED: Pluggable ID generation
33
- * FIXED: BSP dropped span buffer full reporting
34
- * FIXED: Implement SDK environment variables
35
- * FIXED: Remove incorrect TODO
97
+ * ADDED: Structured error handling
98
+ * ADDED: Pluggable ID generation
99
+ * FIXED: BSP dropped span buffer full reporting
100
+ * FIXED: Implement SDK environment variables
101
+ * FIXED: Remove incorrect TODO
36
102
 
37
103
  ### v0.11.1 / 2020-12-16
38
104
 
39
- * FIXED: BSP dropped span buffer full reporting
105
+ * FIXED: BSP dropped span buffer full reporting
40
106
 
41
107
  ### v0.11.0 / 2020-12-11
42
108
 
43
- * ADDED: Metrics reporting from trace export
44
- * FIXED: Copyright comments to not reference year
109
+ * ADDED: Metrics reporting from trace export
110
+ * FIXED: Copyright comments to not reference year
45
111
 
46
112
  ### v0.10.0 / 2020-12-03
47
113
 
48
- * BREAKING CHANGE: Allow samplers to modify tracestate
114
+ * BREAKING CHANGE: Allow samplers to modify tracestate
49
115
 
50
- * FIXED: Allow samplers to modify tracestate
116
+ * FIXED: Allow samplers to modify tracestate
51
117
 
52
118
  ### v0.9.0 / 2020-11-27
53
119
 
54
- * BREAKING CHANGE: Pass full Context to samplers
55
- * BREAKING CHANGE: Add timeout for force_flush and shutdown
120
+ * BREAKING CHANGE: Pass full Context to samplers
121
+ * BREAKING CHANGE: Add timeout for force_flush and shutdown
56
122
 
57
- * ADDED: Add OTEL_RUBY_BSP_START_THREAD_ON_BOOT env var
58
- * ADDED: Add timeout for force_flush and shutdown
59
- * FIXED: Signal at batch_size
60
- * FIXED: SDK Span.recording? after finish
61
- * FIXED: Pass full Context to samplers
62
- * DOCS: Add documentation on usage scenarios for span processors
123
+ * ADDED: Add OTEL_RUBY_BSP_START_THREAD_ON_BOOT env var
124
+ * ADDED: Add timeout for force_flush and shutdown
125
+ * FIXED: Signal at batch_size
126
+ * FIXED: SDK Span.recording? after finish
127
+ * FIXED: Pass full Context to samplers
128
+ * DOCS: Add documentation on usage scenarios for span processors
63
129
 
64
130
  ### v0.8.0 / 2020-10-27
65
131
 
66
- * BREAKING CHANGE: Move context/span methods to Trace module
67
- * BREAKING CHANGE: Remove 'canonical' from status codes
68
- * BREAKING CHANGE: Assorted SpanContext fixes
132
+ * BREAKING CHANGE: Move context/span methods to Trace module
133
+ * BREAKING CHANGE: Remove 'canonical' from status codes
134
+ * BREAKING CHANGE: Assorted SpanContext fixes
69
135
 
70
- * FIXED: Move context/span methods to Trace module
71
- * FIXED: Remove 'canonical' from status codes
72
- * FIXED: Assorted SpanContext fixes
136
+ * FIXED: Move context/span methods to Trace module
137
+ * FIXED: Remove 'canonical' from status codes
138
+ * FIXED: Assorted SpanContext fixes
73
139
 
74
140
  ### v0.7.0 / 2020-10-07
75
141
 
76
- * ADDED: Add service_name setter to configurator
77
- * ADDED: Add service_version setter to configurator
78
- * FIXED: Fork safety for batch processor
79
- * FIXED: Don't generate a span ID unnecessarily
80
- * DOCS: Fix Configurator#add_span_processor
81
- * DOCS: Standardize toplevel docs structure and readme
142
+ * ADDED: Add service_name setter to configurator
143
+ * ADDED: Add service_version setter to configurator
144
+ * FIXED: Fork safety for batch processor
145
+ * FIXED: Don't generate a span ID unnecessarily
146
+ * DOCS: Fix Configurator#add_span_processor
147
+ * DOCS: Standardize toplevel docs structure and readme
82
148
 
83
149
  ### v0.6.0 / 2020-09-10
84
150
 
85
- * BREAKING CHANGE: Rename Resource labels to attributes
151
+ * BREAKING CHANGE: Rename Resource labels to attributes
86
152
  * BREAKING CHANGE: Export resource from Span/SpanData instead of library_resource
87
153
  * BREAKING CHANGE: Rename CorrelationContext to Baggage
88
154
  * BREAKING CHANGE: Rename Text* to TextMap* (propagators, injectors, extractors)
@@ -92,7 +158,7 @@
92
158
 
93
159
  * ADDED: Add OTLP exporter
94
160
  * ADDED: Add support for OTEL_LOG_LEVEL env var
95
- * FIXED: Rename Resource labels to attributes
161
+ * FIXED: Rename Resource labels to attributes
96
162
  * ADDED: Environment variable resource detection
97
163
  * ADDED: BatchSpanProcessor environment variable support
98
164
  * FIXED: Remove semver prefix
data/README.md CHANGED
@@ -56,7 +56,7 @@ For additional examples, see the [examples on github][examples-github].
56
56
 
57
57
  The `opentelemetry-sdk` gem source is [on github][repo-github], along with related gems including `opentelemetry-api`.
58
58
 
59
- The OpenTelemetry Ruby gems are maintained by the OpenTelemetry-Ruby special interest group (SIG). You can get involved by joining us on our [gitter channel][ruby-gitter] or attending our weekly meeting. See the [meeting calendar][community-meetings] for dates and times. For more information on this and other language SIGs, see the OpenTelemetry [community page][ruby-sig].
59
+ The OpenTelemetry Ruby gems are maintained by the OpenTelemetry-Ruby special interest group (SIG). You can get involved by joining us in [GitHub Discussions][discussions-url] or attending our weekly meeting. See the [meeting calendar][community-meetings] for dates and times. For more information on this and other language SIGs, see the OpenTelemetry [community page][ruby-sig].
60
60
 
61
61
  ## License
62
62
 
@@ -70,4 +70,4 @@ The `opentelemetry-sdk` gem is distributed under the Apache 2.0 license. See [LI
70
70
  [examples-github]: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/examples
71
71
  [ruby-sig]: https://github.com/open-telemetry/community#ruby-sig
72
72
  [community-meetings]: https://github.com/open-telemetry/community#community-meetings
73
- [ruby-gitter]: https://gitter.im/open-telemetry/opentelemetry-ruby
73
+ [discussions-url]: https://github.com/open-telemetry/opentelemetry-ruby/discussions
@@ -6,6 +6,7 @@
6
6
 
7
7
  require 'opentelemetry'
8
8
  require 'opentelemetry/common'
9
+ require 'opentelemetry-instrumentation-base'
9
10
 
10
11
  # OpenTelemetry is an open source observability framework, providing a
11
12
  # general-purpose API, SDK, and related tools required for the instrumentation
@@ -54,7 +55,7 @@ module OpenTelemetry
54
55
  # Configure everything
55
56
  #
56
57
  # OpenTelemetry::SDK.configure do |c|
57
- # c.logger = Logger.new('/dev/null')
58
+ # c.logger = Logger.new(File::NULL)
58
59
  # c.add_span_processor SpanProcessor.new(SomeExporter.new)
59
60
  # c.use_all
60
61
  # end
@@ -66,14 +67,14 @@ module OpenTelemetry
66
67
  begin
67
68
  raise ConfigurationError
68
69
  rescue ConfigurationError => e
69
- OpenTelemetry.handle_error(exception: e, message: 'unexpected configuration error')
70
+ OpenTelemetry.handle_error(exception: e, message: "unexpected configuration error due to #{e.cause}")
70
71
  end
71
72
  end
72
73
  end
73
74
  end
74
75
 
75
76
  require 'opentelemetry/sdk/configurator'
76
- require 'opentelemetry/sdk/baggage'
77
+ require 'opentelemetry/sdk/forwarding_logger'
77
78
  require 'opentelemetry/sdk/internal'
78
79
  require 'opentelemetry/sdk/instrumentation_library'
79
80
  require 'opentelemetry/sdk/resources'
@@ -15,14 +15,12 @@ module OpenTelemetry
15
15
 
16
16
  private_constant :USE_MODE_UNSPECIFIED, :USE_MODE_ONE, :USE_MODE_ALL
17
17
 
18
- attr_writer :logger, :extractors, :injectors, :error_handler,
19
- :id_generator
18
+ attr_writer :propagators, :error_handler, :id_generator
20
19
 
21
20
  def initialize
22
21
  @instrumentation_names = []
23
22
  @instrumentation_config_map = {}
24
- @injectors = nil
25
- @extractors = nil
23
+ @propagators = nil
26
24
  @span_processors = []
27
25
  @use_mode = USE_MODE_UNSPECIFIED
28
26
  @resource = Resources::Resource.default
@@ -33,6 +31,15 @@ module OpenTelemetry
33
31
  @logger ||= OpenTelemetry.logger
34
32
  end
35
33
 
34
+ # Accepts a logger and wraps it in the {ForwardingLogger} which allows
35
+ # for controlling the severity level emitted by the OpenTelemetry.logger
36
+ # independently of the supplied logger.
37
+ #
38
+ # @param [Logger] new_logger The logger for OpenTelemetry to use
39
+ def logger=(new_logger)
40
+ @logger = ForwardingLogger.new(new_logger, level: ENV['OTEL_LOG_LEVEL'] || Logger::INFO)
41
+ end
42
+
36
43
  def error_handler
37
44
  @error_handler ||= OpenTelemetry.error_handler
38
45
  end
@@ -114,7 +121,6 @@ module OpenTelemetry
114
121
  def configure
115
122
  OpenTelemetry.logger = logger
116
123
  OpenTelemetry.error_handler = error_handler
117
- OpenTelemetry.baggage = Baggage::Manager.new
118
124
  configure_propagation
119
125
  configure_span_processors
120
126
  tracer_provider.id_generator = @id_generator
@@ -125,7 +131,7 @@ module OpenTelemetry
125
131
  private
126
132
 
127
133
  def tracer_provider
128
- @tracer_provider ||= Trace::TracerProvider.new(@resource)
134
+ @tracer_provider ||= Trace::TracerProvider.new(resource: @resource)
129
135
  end
130
136
 
131
137
  def check_use_mode!(mode)
@@ -136,48 +142,61 @@ module OpenTelemetry
136
142
  def install_instrumentation
137
143
  case @use_mode
138
144
  when USE_MODE_ONE
139
- OpenTelemetry.instrumentation_registry.install(@instrumentation_names, @instrumentation_config_map)
145
+ OpenTelemetry::Instrumentation.registry.install(@instrumentation_names, @instrumentation_config_map)
140
146
  when USE_MODE_ALL
141
- OpenTelemetry.instrumentation_registry.install_all(@instrumentation_config_map)
147
+ OpenTelemetry::Instrumentation.registry.install_all(@instrumentation_config_map)
142
148
  end
143
149
  end
144
150
 
145
151
  def configure_span_processors
146
- processors = @span_processors.empty? ? [default_span_processor] : @span_processors
152
+ processors = @span_processors.empty? ? [wrapped_exporter_from_env].compact : @span_processors
147
153
  processors.each { |p| tracer_provider.add_span_processor(p) }
148
154
  end
149
155
 
150
- def default_span_processor
151
- Trace::Export::SimpleSpanProcessor.new(
152
- Trace::Export::ConsoleSpanExporter.new
153
- )
154
- end
155
-
156
- def configure_propagation
157
- OpenTelemetry.propagation = create_propagator(@injectors || default_injectors,
158
- @extractors || default_extractors)
156
+ def wrapped_exporter_from_env
157
+ exporter = ENV.fetch('OTEL_TRACES_EXPORTER', 'otlp')
158
+ case exporter
159
+ when 'none' then nil
160
+ when 'otlp' then fetch_exporter(exporter, 'OpenTelemetry::Exporter::OTLP::Exporter')
161
+ when 'jaeger' then fetch_exporter(exporter, 'OpenTelemetry::Exporter::Jaeger::CollectorExporter')
162
+ when 'zipkin' then fetch_exporter(exporter, 'OpenTelemetry::Exporter::Zipkin::Exporter')
163
+ when 'console' then Trace::Export::SimpleSpanProcessor.new(Trace::Export::ConsoleSpanExporter.new)
164
+ else
165
+ OpenTelemetry.logger.warn "The #{exporter} exporter is unknown and cannot be configured, spans will not be exported"
166
+ nil
167
+ end
159
168
  end
160
169
 
161
- def create_propagator(injectors, extractors)
162
- if injectors.size > 1 || extractors.size > 1
163
- Context::Propagation::CompositePropagator.new(injectors, extractors)
164
- else
165
- Context::Propagation::Propagator.new(injectors, extractors)
170
+ def configure_propagation # rubocop:disable Metrics/CyclomaticComplexity
171
+ propagators = ENV.fetch('OTEL_PROPAGATORS', 'tracecontext,baggage').split(',').uniq.collect do |propagator|
172
+ case propagator
173
+ when 'tracecontext' then OpenTelemetry::Trace::Propagation::TraceContext.text_map_propagator
174
+ when 'baggage' then OpenTelemetry::Baggage::Propagation.text_map_propagator
175
+ when 'b3' then fetch_propagator(propagator, 'OpenTelemetry::Propagator::B3::Single')
176
+ when 'b3multi' then fetch_propagator(propagator, 'OpenTelemetry::Propagator::B3::Multi', 'b3')
177
+ when 'jaeger' then fetch_propagator(propagator, 'OpenTelemetry::Propagator::Jaeger')
178
+ when 'xray' then fetch_propagator(propagator, 'OpenTelemetry::Propagator::XRay')
179
+ when 'ottrace' then fetch_propagator(propagator, 'OpenTelemetry::Propagator::OTTrace')
180
+ else
181
+ OpenTelemetry.logger.warn "The #{propagator} propagator is unknown and cannot be configured"
182
+ Context::Propagation::NoopTextMapPropagator.new
183
+ end
166
184
  end
185
+ OpenTelemetry.propagation = Context::Propagation::CompositeTextMapPropagator.compose_propagators((@propagators || propagators).compact)
167
186
  end
168
187
 
169
- def default_injectors
170
- [
171
- OpenTelemetry::Trace::Propagation::TraceContext.text_map_injector,
172
- OpenTelemetry::Baggage::Propagation.text_map_injector
173
- ]
188
+ def fetch_propagator(name, class_name, gem_suffix = name)
189
+ Kernel.const_get(class_name).text_map_propagator
190
+ rescue NameError
191
+ OpenTelemetry.logger.warn "The #{name} propagator cannot be configured - please add opentelemetry-propagator-#{gem_suffix} to your Gemfile"
192
+ nil
174
193
  end
175
194
 
176
- def default_extractors
177
- [
178
- OpenTelemetry::Trace::Propagation::TraceContext.text_map_extractor,
179
- OpenTelemetry::Baggage::Propagation.text_map_extractor
180
- ]
195
+ def fetch_exporter(name, class_name)
196
+ Trace::Export::BatchSpanProcessor.new(Kernel.const_get(class_name).new)
197
+ rescue NameError
198
+ OpenTelemetry.logger.warn "The #{name} exporter cannot be configured - please add opentelemetry-exporter-#{name} to your Gemfile, spans will not be exported"
199
+ nil
181
200
  end
182
201
  end
183
202
  end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'logger'
4
+
5
+ module OpenTelemetry
6
+ module SDK
7
+ # The ForwardingLogger provides a wrapper to control the OpenTelemetry
8
+ # log level, while respecting the configured level of the supplied logger.
9
+ # If the OTEL_LOG_LEVEL is set to debug, and the supplied logger is configured
10
+ # with an ERROR log level, only OpenTelemetry logs at the ERROR level or higher
11
+ # will be emitted.
12
+ class ForwardingLogger
13
+ def initialize(logger, level:) # rubocop:disable Metrics/CyclomaticComplexity
14
+ @logger = logger
15
+
16
+ if level.is_a?(Integer)
17
+ @level = level
18
+ else
19
+ case level.to_s.downcase
20
+ when 'debug'
21
+ @level = Logger::DEBUG
22
+ when 'info'
23
+ @level = Logger::INFO
24
+ when 'warn'
25
+ @level = Logger::WARN
26
+ when 'error'
27
+ @level = Logger::ERROR
28
+ when 'fatal'
29
+ @level = Logger::FATAL
30
+ when 'unknown'
31
+ @level = Logger::UNKNOWN
32
+ else
33
+ raise ArgumentError, "invalid log level: #{level}"
34
+ end
35
+ end
36
+ end
37
+
38
+ def add(severity, message = nil, progname = nil)
39
+ return true if severity < @level
40
+
41
+ @logger.add(severity, message, progname)
42
+ end
43
+
44
+ def debug(progname = nil, &block)
45
+ add(Logger::DEBUG, nil, progname, &block)
46
+ end
47
+
48
+ def info(progname = nil, &block)
49
+ add(Logger::INFO, nil, progname, &block)
50
+ end
51
+
52
+ def warn(progname = nil, &block)
53
+ add(Logger::WARN, nil, progname, &block)
54
+ end
55
+
56
+ def error(progname = nil, &block)
57
+ add(Logger::ERROR, nil, progname, &block)
58
+ end
59
+
60
+ def fatal(progname = nil, &block)
61
+ add(Logger::FATAL, nil, progname, &block)
62
+ end
63
+
64
+ def unknown(progname = nil, &block)
65
+ add(Logger::UNKNOWN, nil, progname, &block)
66
+ end
67
+ end
68
+ end
69
+ end