opentelemetry-sdk 0.17.0 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4be88dba1f3a925ceb97494267f2d27cfb24f5f89e417236d5cca698c0388b9b
4
- data.tar.gz: 8e43a87d87dc739c1323acecaa18e93dac8a911fc28a119c016e5e834ca74615
3
+ metadata.gz: 945d2fc6ef9f85d085850f3060ec9dcf1687d9066aaa1eb9a0209a6ca5aad28d
4
+ data.tar.gz: a5fa5d0cd5eb0de4c8d99ecf87fa8e4ba965dd5ae7817847c454b48c1d18e74e
5
5
  SHA512:
6
- metadata.gz: 672426fc31d0c6cce4f363509085b40bddf66d6c6516048e40ae1661fefaf2a6a3482acfe9a6dcff8db328675fb2e5ec02c9fe89d91486f551bf029bcb390f6b
7
- data.tar.gz: 42b693687ddfdf1221c972d902e9249fcec6a947bb48416b4627fbd805859ac8bc5fcdb18ac44e4fb628bfd56f67bf42d028465f6e34c4c679844a7c1027515d
6
+ metadata.gz: 94ba24237af75d15d0b5aea94c41b01f19392f04a9c7237cfe23388f468e54dcc45a6c0e32c9fd51fbe0d2439dc63d18d1ac6564634fa211110d75bc22069083
7
+ data.tar.gz: 3889a79b962b13be77e54374af5fc0335089eb2b0ee2637547014a74e744f359a03179838584846837e54e5e6f38c80c8b30690f9e9a85dc99657e858b012e6e
data/CHANGELOG.md CHANGED
@@ -1,127 +1,189 @@
1
1
  # Release History: opentelemetry-sdk
2
2
 
3
+ ### v1.0.0 / 2021-09-29
4
+
5
+ * (No significant changes)
6
+
7
+ ### v1.0.0.rc3 / 2021-08-12
8
+
9
+ * BREAKING CHANGE: Remove optional parent_context from in_span
10
+ * BREAKING CHANGE: Replace Time.now with Process.clock_gettime
11
+ * BREAKING CHANGE: Refactor Baggage to remove Noop*
12
+ * BREAKING CHANGE: Remove unnecessary readers from SDK Tracer
13
+ * BREAKING CHANGE: Total order constraint on span.status=
14
+ * BREAKING CHANGE: Use auto-generated resource constants in sdk and resource_detectors
15
+ * BREAKING CHANGE: Span limits env vars
16
+
17
+ * ADDED: Add Tracer.non_recording_span to API
18
+ * ADDED: Add unnamed tracer warning message
19
+ * ADDED: Allow disabling of install messages
20
+ * ADDED: Make API's NoopTextMapPropagator private
21
+ * ADDED: Use auto-generated resource constants in sdk and resource_detectors
22
+ * ADDED: Allow selecting multiple exporter
23
+ * ADDED: Add explicit BSP export error
24
+ * FIXED: Remove optional parent_context from in_span
25
+ * FIXED: Replace Time.now with Process.clock_gettime
26
+ * FIXED: Rename cloud.zone to cloud.availability_zone
27
+ * FIXED: Improve attribute error messages
28
+ * FIXED: Refactor Baggage to remove Noop*
29
+ * FIXED: Support OTEL_SERVICE_NAME env var
30
+ * FIXED: Remove unnecessary readers from SDK Tracer
31
+ * FIXED: Total order constraint on span.status=
32
+ * FIXED: Flakey tracer provider test
33
+ * FIXED: Split lock in TracerProvider
34
+ * FIXED: Span limits env vars
35
+ * FIXED: Prune invalid links
36
+ * DOCS: Update docs to rely more on environment variable configuration
37
+
38
+ ### v1.0.0.rc2 / 2021-06-23
39
+
40
+ * BREAKING CHANGE: Remove optional parent_context from in_span [729](https://github.com/open-telemetry/opentelemetry-ruby/pull/729)
41
+ * BREAKING CHANGE: Replace Time.now with Process.clock_gettime [717](https://github.com/open-telemetry/opentelemetry-ruby/pull/717)
42
+ * BREAKING CHANGE: Refactor Baggage to remove Noop* [800](https://github.com/open-telemetry/opentelemetry-ruby/pull/800)
43
+ * BREAKING CHANGE: Remove unnecessary readers from SDK Tracer [820](https://github.com/open-telemetry/opentelemetry-ruby/pull/820)
44
+ - Tracer no longer surfaces attribute readers for the name, version, or tracer_provider
45
+ * BREAKING CHANGE: Total order constraint on span.status= [805](https://github.com/open-telemetry/opentelemetry-ruby/pull/805)
46
+
47
+ * ADDED: Add Tracer.non_recording_span to API [799](https://github.com/open-telemetry/opentelemetry-ruby/pull/799)
48
+ * ADDED: Add unnamed tracer warning message [830](https://github.com/open-telemetry/opentelemetry-ruby/pull/830)
49
+ * ADDED: Allow disabling of install messages [831](https://github.com/open-telemetry/opentelemetry-ruby/pull/831)
50
+ * FIXED: Rename cloud.zone to cloud.availability_zone [734](https://github.com/open-telemetry/opentelemetry-ruby/pull/734)
51
+ * FIXED: Improve attribute error messages [742](https://github.com/open-telemetry/opentelemetry-ruby/pull/742)
52
+ * FIXED: Support OTEL_SERVICE_NAME env var [806]https://github.com/open-telemetry/opentelemetry-ruby/pull/806
53
+ * FIXED: Flakey tracer provider test
54
+
55
+ ### v1.0.0.rc1 / 2021-05-21
56
+
57
+ * BREAKING CHANGE: Remove optional parent_context from in_span
58
+ * BREAKING CHANGE: Replace Time.now with Process.clock_gettime
59
+
60
+ * FIXED: Remove optional parent_context from in_span
61
+ * FIXED: Replace Time.now with Process.clock_gettime
62
+ * FIXED: Rename cloud.zone to cloud.availability_zone
63
+ * FIXED: Improve attribute error messages
64
+
3
65
  ### v0.17.0 / 2021-04-22
4
66
 
5
67
  * BREAKING CHANGE: Replace TextMapInjector/TextMapExtractor pairs with a TextMapPropagator.
6
68
 
7
69
  [Check the propagator documentation](https://open-telemetry.github.io/opentelemetry-ruby/) for the new usage.
8
70
 
9
- * ADDED: Add zipkin exporter
10
- * ADDED: Processors validate exporters on init.
11
- * ADDED: Add configurable truncation of span and event attribute values
12
- * ADDED: Add simple 'recording' attr_accessor to InMemorySpanExporter
13
- * FIXED: Typo in error message
14
- * FIXED: Improve configuration error reporting
15
- * FIXED: Refactor propagators to add #fields
71
+ * ADDED: Add zipkin exporter
72
+ * ADDED: Processors validate exporters on init.
73
+ * ADDED: Add configurable truncation of span and event attribute values
74
+ * ADDED: Add simple 'recording' attr_accessor to InMemorySpanExporter
75
+ * FIXED: Typo in error message
76
+ * FIXED: Improve configuration error reporting
77
+ * FIXED: Refactor propagators to add #fields
16
78
 
17
79
  ### v0.16.0 / 2021-03-17
18
80
 
19
- * BREAKING CHANGE: Update SDK BaggageManager to match API
20
- * BREAKING CHANGE: Implement Exporter#force_flush
81
+ * BREAKING CHANGE: Update SDK BaggageManager to match API
82
+ * BREAKING CHANGE: Implement Exporter#force_flush
21
83
 
22
- * ADDED: Add force_flush to SDK's TracerProvider
23
- * ADDED: Add k8s node to gcp resource detector
24
- * ADDED: Add console option for OTEL_TRACES_EXPORTER
25
- * ADDED: Span#add_attributes
26
- * ADDED: Implement Exporter#force_flush
27
- * FIXED: Update SDK BaggageManager to match API
28
- * DOCS: Replace Gitter with GitHub Discussions
84
+ * ADDED: Add force_flush to SDK's TracerProvider
85
+ * ADDED: Add k8s node to gcp resource detector
86
+ * ADDED: Add console option for OTEL_TRACES_EXPORTER
87
+ * ADDED: Span#add_attributes
88
+ * ADDED: Implement Exporter#force_flush
89
+ * FIXED: Update SDK BaggageManager to match API
90
+ * DOCS: Replace Gitter with GitHub Discussions
29
91
 
30
92
  ### v0.15.0 / 2021-02-18
31
93
 
32
- * BREAKING CHANGE: Streamline processor pipeline
94
+ * BREAKING CHANGE: Streamline processor pipeline
33
95
 
34
- * ADDED: Add instrumentation config validation
35
- * FIXED: Streamline processor pipeline
36
- * FIXED: OTEL_TRACE -> OTEL_TRACES env vars
37
- * FIXED: Change limits from 1000 to 128
38
- * FIXED: OTEL_TRACES_EXPORTER and OTEL_PROPAGATORS
39
- * FIXED: Add thread error handling to the BSP
40
- * DOCS: Clarify nil attribute values not allowed
96
+ * ADDED: Add instrumentation config validation
97
+ * FIXED: Streamline processor pipeline
98
+ * FIXED: OTEL_TRACE -> OTEL_TRACES env vars
99
+ * FIXED: Change limits from 1000 to 128
100
+ * FIXED: OTEL_TRACES_EXPORTER and OTEL_PROPAGATORS
101
+ * FIXED: Add thread error handling to the BSP
102
+ * DOCS: Clarify nil attribute values not allowed
41
103
 
42
104
  ### v0.14.0 / 2021-02-03
43
105
 
44
- * BREAKING CHANGE: Replace getter and setter callables and remove rack specific propagators
106
+ * BREAKING CHANGE: Replace getter and setter callables and remove rack specific propagators
45
107
 
46
- * ADDED: Replace getter and setter callables and remove rack specific propagators
108
+ * ADDED: Replace getter and setter callables and remove rack specific propagators
47
109
 
48
110
  ### v0.13.1 / 2021-02-01
49
111
 
50
- * FIXED: Leaky test
51
- * FIXED: Allow env var override of service.name
112
+ * FIXED: Leaky test
113
+ * FIXED: Allow env var override of service.name
52
114
 
53
115
  ### v0.13.0 / 2021-01-29
54
116
 
55
- * BREAKING CHANGE: Remove MILLIS from BatchSpanProcessor vars
117
+ * BREAKING CHANGE: Remove MILLIS from BatchSpanProcessor vars
56
118
 
57
- * ADDED: Process.runtime resource
58
- * ADDED: Provide default resource in SDK
59
- * ADDED: Add optional attributes to record_exception
60
- * FIXED: Resource.merge consistency
61
- * FIXED: Remove MILLIS from BatchSpanProcessor vars
119
+ * ADDED: Process.runtime resource
120
+ * ADDED: Provide default resource in SDK
121
+ * ADDED: Add optional attributes to record_exception
122
+ * FIXED: Resource.merge consistency
123
+ * FIXED: Remove MILLIS from BatchSpanProcessor vars
62
124
 
63
125
  ### v0.12.1 / 2021-01-13
64
126
 
65
- * FIXED: Fix several BatchSpanProcessor errors related to fork safety
66
- * FIXED: Define default value for traceid ratio
127
+ * FIXED: Fix several BatchSpanProcessor errors related to fork safety
128
+ * FIXED: Define default value for traceid ratio
67
129
 
68
130
  ### v0.12.0 / 2020-12-24
69
131
 
70
- * ADDED: Structured error handling
71
- * ADDED: Pluggable ID generation
72
- * FIXED: BSP dropped span buffer full reporting
73
- * FIXED: Implement SDK environment variables
74
- * FIXED: Remove incorrect TODO
132
+ * ADDED: Structured error handling
133
+ * ADDED: Pluggable ID generation
134
+ * FIXED: BSP dropped span buffer full reporting
135
+ * FIXED: Implement SDK environment variables
136
+ * FIXED: Remove incorrect TODO
75
137
 
76
138
  ### v0.11.1 / 2020-12-16
77
139
 
78
- * FIXED: BSP dropped span buffer full reporting
140
+ * FIXED: BSP dropped span buffer full reporting
79
141
 
80
142
  ### v0.11.0 / 2020-12-11
81
143
 
82
- * ADDED: Metrics reporting from trace export
83
- * FIXED: Copyright comments to not reference year
144
+ * ADDED: Metrics reporting from trace export
145
+ * FIXED: Copyright comments to not reference year
84
146
 
85
147
  ### v0.10.0 / 2020-12-03
86
148
 
87
- * BREAKING CHANGE: Allow samplers to modify tracestate
149
+ * BREAKING CHANGE: Allow samplers to modify tracestate
88
150
 
89
- * FIXED: Allow samplers to modify tracestate
151
+ * FIXED: Allow samplers to modify tracestate
90
152
 
91
153
  ### v0.9.0 / 2020-11-27
92
154
 
93
- * BREAKING CHANGE: Pass full Context to samplers
94
- * BREAKING CHANGE: Add timeout for force_flush and shutdown
155
+ * BREAKING CHANGE: Pass full Context to samplers
156
+ * BREAKING CHANGE: Add timeout for force_flush and shutdown
95
157
 
96
- * ADDED: Add OTEL_RUBY_BSP_START_THREAD_ON_BOOT env var
97
- * ADDED: Add timeout for force_flush and shutdown
98
- * FIXED: Signal at batch_size
99
- * FIXED: SDK Span.recording? after finish
100
- * FIXED: Pass full Context to samplers
101
- * DOCS: Add documentation on usage scenarios for span processors
158
+ * ADDED: Add OTEL_RUBY_BSP_START_THREAD_ON_BOOT env var
159
+ * ADDED: Add timeout for force_flush and shutdown
160
+ * FIXED: Signal at batch_size
161
+ * FIXED: SDK Span.recording? after finish
162
+ * FIXED: Pass full Context to samplers
163
+ * DOCS: Add documentation on usage scenarios for span processors
102
164
 
103
165
  ### v0.8.0 / 2020-10-27
104
166
 
105
- * BREAKING CHANGE: Move context/span methods to Trace module
106
- * BREAKING CHANGE: Remove 'canonical' from status codes
107
- * BREAKING CHANGE: Assorted SpanContext fixes
167
+ * BREAKING CHANGE: Move context/span methods to Trace module
168
+ * BREAKING CHANGE: Remove 'canonical' from status codes
169
+ * BREAKING CHANGE: Assorted SpanContext fixes
108
170
 
109
- * FIXED: Move context/span methods to Trace module
110
- * FIXED: Remove 'canonical' from status codes
111
- * FIXED: Assorted SpanContext fixes
171
+ * FIXED: Move context/span methods to Trace module
172
+ * FIXED: Remove 'canonical' from status codes
173
+ * FIXED: Assorted SpanContext fixes
112
174
 
113
175
  ### v0.7.0 / 2020-10-07
114
176
 
115
- * ADDED: Add service_name setter to configurator
116
- * ADDED: Add service_version setter to configurator
117
- * FIXED: Fork safety for batch processor
118
- * FIXED: Don't generate a span ID unnecessarily
119
- * DOCS: Fix Configurator#add_span_processor
120
- * DOCS: Standardize toplevel docs structure and readme
177
+ * ADDED: Add service_name setter to configurator
178
+ * ADDED: Add service_version setter to configurator
179
+ * FIXED: Fork safety for batch processor
180
+ * FIXED: Don't generate a span ID unnecessarily
181
+ * DOCS: Fix Configurator#add_span_processor
182
+ * DOCS: Standardize toplevel docs structure and readme
121
183
 
122
184
  ### v0.6.0 / 2020-09-10
123
185
 
124
- * BREAKING CHANGE: Rename Resource labels to attributes
186
+ * BREAKING CHANGE: Rename Resource labels to attributes
125
187
  * BREAKING CHANGE: Export resource from Span/SpanData instead of library_resource
126
188
  * BREAKING CHANGE: Rename CorrelationContext to Baggage
127
189
  * BREAKING CHANGE: Rename Text* to TextMap* (propagators, injectors, extractors)
@@ -131,7 +193,7 @@
131
193
 
132
194
  * ADDED: Add OTLP exporter
133
195
  * ADDED: Add support for OTEL_LOG_LEVEL env var
134
- * FIXED: Rename Resource labels to attributes
196
+ * FIXED: Rename Resource labels to attributes
135
197
  * ADDED: Environment variable resource detection
136
198
  * ADDED: BatchSpanProcessor environment variable support
137
199
  * FIXED: Remove semver prefix
data/README.md CHANGED
@@ -29,10 +29,33 @@ Then, configure the SDK according to your desired handling of telemetry data, an
29
29
  ```ruby
30
30
  require 'opentelemetry/sdk'
31
31
 
32
- # Configure the sdk with default export and context propagation formats
33
- # see SDK#configure for customizing the setup
32
+ # Configure the sdk with default export and context propagation formats.
34
33
  OpenTelemetry::SDK.configure
35
34
 
35
+ # Many configuration options may be set via the environment. To use them,
36
+ # set the appropriate variable before calling configure. For example:
37
+ #
38
+ # ENV['OTEL_TRACES_EXPORTER'] = 'console'
39
+ # ENV['OTEL_PROPAGATORS'] = 'ottrace'
40
+ # OpenTelemetry::SDK.configure
41
+ #
42
+ # You may also configure the SDK programmatically, for advanced usage or to
43
+ # enable auto-instrumentation. For example:
44
+ #
45
+ # OpenTelemetry::SDK.configure do |c|
46
+ # c.service_name = something_calculated_dynamically
47
+ # c.add_span_processor(
48
+ # OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new(
49
+ # OpenTelemetry::SDK::Trace::Export::ConsoleSpanExporter.new
50
+ # )
51
+ # )
52
+ #
53
+ # c.use 'OpenTelemetry::Instrumentation::Net::HTTP'
54
+ # end
55
+ #
56
+ # Note that the SimpleSpanExporter is not recommended for use in production.
57
+
58
+
36
59
  # To start a trace you need to get a Tracer from the TracerProvider
37
60
  tracer = OpenTelemetry.tracer_provider.tracer('my_app_or_gem', '0.1.0')
38
61
 
@@ -9,13 +9,29 @@ module OpenTelemetry
9
9
  # The configurator provides defaults and facilitates configuring the
10
10
  # SDK for use.
11
11
  class Configurator # rubocop:disable Metrics/ClassLength
12
+ # @api private
13
+ class NoopTextMapPropagator
14
+ EMPTY_LIST = [].freeze
15
+ private_constant(:EMPTY_LIST)
16
+
17
+ def inject(carrier, context: Context.current, setter: Context::Propagation.text_map_setter); end
18
+
19
+ def extract(carrier, context: Context.current, getter: Context::Propagation.text_map_getter)
20
+ context
21
+ end
22
+
23
+ def fields
24
+ EMPTY_LIST
25
+ end
26
+ end
27
+
12
28
  USE_MODE_UNSPECIFIED = 0
13
29
  USE_MODE_ONE = 1
14
30
  USE_MODE_ALL = 2
15
31
 
16
32
  private_constant :USE_MODE_UNSPECIFIED, :USE_MODE_ONE, :USE_MODE_ALL
17
33
 
18
- attr_writer :logger, :propagators, :error_handler, :id_generator
34
+ attr_writer :propagators, :error_handler, :id_generator
19
35
 
20
36
  def initialize
21
37
  @instrumentation_names = []
@@ -31,6 +47,15 @@ module OpenTelemetry
31
47
  @logger ||= OpenTelemetry.logger
32
48
  end
33
49
 
50
+ # Accepts a logger and wraps it in the {ForwardingLogger} which allows
51
+ # for controlling the severity level emitted by the OpenTelemetry.logger
52
+ # independently of the supplied logger.
53
+ #
54
+ # @param [Logger] new_logger The logger for OpenTelemetry to use
55
+ def logger=(new_logger)
56
+ @logger = ForwardingLogger.new(new_logger, level: ENV['OTEL_LOG_LEVEL'] || Logger::INFO)
57
+ end
58
+
34
59
  def error_handler
35
60
  @error_handler ||= OpenTelemetry.error_handler
36
61
  end
@@ -51,7 +76,7 @@ module OpenTelemetry
51
76
  # @param [String] service_name The value to be used as the service name
52
77
  def service_name=(service_name)
53
78
  self.resource = OpenTelemetry::SDK::Resources::Resource.create(
54
- OpenTelemetry::SDK::Resources::Constants::SERVICE_RESOURCE[:name] => service_name
79
+ OpenTelemetry::SemanticConventions::Resource::SERVICE_NAME => service_name
55
80
  )
56
81
  end
57
82
 
@@ -61,7 +86,7 @@ module OpenTelemetry
61
86
  # @param [String] service_version The value to be used as the service version
62
87
  def service_version=(service_version)
63
88
  self.resource = OpenTelemetry::SDK::Resources::Resource.create(
64
- OpenTelemetry::SDK::Resources::Constants::SERVICE_RESOURCE[:version] => service_version
89
+ OpenTelemetry::SemanticConventions::Resource::SERVICE_VERSION => service_version
65
90
  )
66
91
  end
67
92
 
@@ -112,7 +137,6 @@ module OpenTelemetry
112
137
  def configure
113
138
  OpenTelemetry.logger = logger
114
139
  OpenTelemetry.error_handler = error_handler
115
- OpenTelemetry.baggage = Baggage::Manager.new
116
140
  configure_propagation
117
141
  configure_span_processors
118
142
  tracer_provider.id_generator = @id_generator
@@ -123,7 +147,7 @@ module OpenTelemetry
123
147
  private
124
148
 
125
149
  def tracer_provider
126
- @tracer_provider ||= Trace::TracerProvider.new(@resource)
150
+ @tracer_provider ||= Trace::TracerProvider.new(resource: @resource)
127
151
  end
128
152
 
129
153
  def check_use_mode!(mode)
@@ -141,21 +165,23 @@ module OpenTelemetry
141
165
  end
142
166
 
143
167
  def configure_span_processors
144
- processors = @span_processors.empty? ? [wrapped_exporter_from_env].compact : @span_processors
168
+ processors = @span_processors.empty? ? wrapped_exporters_from_env.compact : @span_processors
145
169
  processors.each { |p| tracer_provider.add_span_processor(p) }
146
170
  end
147
171
 
148
- def wrapped_exporter_from_env
149
- exporter = ENV.fetch('OTEL_TRACES_EXPORTER', 'otlp')
150
- case exporter
151
- when 'none' then nil
152
- when 'otlp' then fetch_exporter(exporter, 'OpenTelemetry::Exporter::OTLP::Exporter')
153
- when 'jaeger' then fetch_exporter(exporter, 'OpenTelemetry::Exporter::Jaeger::CollectorExporter')
154
- when 'zipkin' then fetch_exporter(exporter, 'OpenTelemetry::Exporter::Zipkin::Exporter')
155
- when 'console' then Trace::Export::SimpleSpanProcessor.new(Trace::Export::ConsoleSpanExporter.new)
156
- else
157
- OpenTelemetry.logger.warn "The #{exporter} exporter is unknown and cannot be configured, spans will not be exported"
158
- nil
172
+ def wrapped_exporters_from_env
173
+ exporters = ENV.fetch('OTEL_TRACES_EXPORTER', 'otlp')
174
+ exporters.split(',').map do |exporter|
175
+ case exporter.strip
176
+ when 'none' then nil
177
+ when 'otlp' then fetch_exporter(exporter, 'OpenTelemetry::Exporter::OTLP::Exporter')
178
+ when 'jaeger' then fetch_exporter(exporter, 'OpenTelemetry::Exporter::Jaeger::CollectorExporter')
179
+ when 'zipkin' then fetch_exporter(exporter, 'OpenTelemetry::Exporter::Zipkin::Exporter')
180
+ when 'console' then Trace::Export::SimpleSpanProcessor.new(Trace::Export::ConsoleSpanExporter.new)
181
+ else
182
+ OpenTelemetry.logger.warn "The #{exporter} exporter is unknown and cannot be configured, spans will not be exported"
183
+ nil
184
+ end
159
185
  end
160
186
  end
161
187
 
@@ -171,7 +197,7 @@ module OpenTelemetry
171
197
  when 'ottrace' then fetch_propagator(propagator, 'OpenTelemetry::Propagator::OTTrace')
172
198
  else
173
199
  OpenTelemetry.logger.warn "The #{propagator} propagator is unknown and cannot be configured"
174
- Context::Propagation::NoopTextMapPropagator.new
200
+ NoopTextMapPropagator.new
175
201
  end
176
202
  end
177
203
  OpenTelemetry.propagation = Context::Propagation::CompositeTextMapPropagator.compose_propagators((@propagators || propagators).compact)
@@ -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
@@ -44,13 +44,13 @@ module OpenTelemetry
44
44
  valid_simple_value?(value) || valid_array_value?(value)
45
45
  end
46
46
 
47
- def valid_attributes?(attrs)
47
+ def valid_attributes?(owner, kind, attrs)
48
48
  attrs.nil? || attrs.all? do |k, v|
49
49
  if !valid_key?(k)
50
- OpenTelemetry.handle_error(message: "invalid attribute key type #{k.class}")
50
+ OpenTelemetry.handle_error(message: "invalid #{kind} attribute key type #{k.class} on span '#{owner}'")
51
51
  false
52
52
  elsif !valid_value?(v)
53
- OpenTelemetry.handle_error(message: "invalid attribute value type #{v.class}")
53
+ OpenTelemetry.handle_error(message: "invalid #{kind} attribute value type #{v.class} for key '#{k}' on span '#{owner}'")
54
54
  false
55
55
  else
56
56
  true
@@ -31,14 +31,14 @@ module OpenTelemetry
31
31
  end
32
32
 
33
33
  def default
34
- @default ||= create(Constants::SERVICE_RESOURCE[:name] => 'unknown_service').merge(process).merge(telemetry_sdk)
34
+ @default ||= create(SemanticConventions::Resource::SERVICE_NAME => 'unknown_service').merge(process).merge(telemetry_sdk).merge(service_name_from_env)
35
35
  end
36
36
 
37
37
  def telemetry_sdk
38
38
  resource_attributes = {
39
- Constants::TELEMETRY_SDK_RESOURCE[:name] => 'opentelemetry',
40
- Constants::TELEMETRY_SDK_RESOURCE[:language] => 'ruby',
41
- Constants::TELEMETRY_SDK_RESOURCE[:version] => OpenTelemetry::SDK::VERSION
39
+ SemanticConventions::Resource::TELEMETRY_SDK_NAME => 'opentelemetry',
40
+ SemanticConventions::Resource::TELEMETRY_SDK_LANGUAGE => 'ruby',
41
+ SemanticConventions::Resource::TELEMETRY_SDK_VERSION => OpenTelemetry::SDK::VERSION
42
42
  }
43
43
 
44
44
  resource_pairs = ENV['OTEL_RESOURCE_ATTRIBUTES']
@@ -55,15 +55,22 @@ module OpenTelemetry
55
55
 
56
56
  def process
57
57
  resource_attributes = {
58
- Constants::PROCESS_RESOURCE[:pid] => Process.pid,
59
- Constants::PROCESS_RESOURCE[:command] => $PROGRAM_NAME,
60
- Constants::PROCESS_RUNTIME_RESOURCE[:name] => RUBY_ENGINE,
61
- Constants::PROCESS_RUNTIME_RESOURCE[:version] => RUBY_VERSION,
62
- Constants::PROCESS_RUNTIME_RESOURCE[:description] => RUBY_DESCRIPTION
58
+ SemanticConventions::Resource::PROCESS_PID => Process.pid,
59
+ SemanticConventions::Resource::PROCESS_COMMAND => $PROGRAM_NAME,
60
+ SemanticConventions::Resource::PROCESS_RUNTIME_NAME => RUBY_ENGINE,
61
+ SemanticConventions::Resource::PROCESS_RUNTIME_VERSION => RUBY_VERSION,
62
+ SemanticConventions::Resource::PROCESS_RUNTIME_DESCRIPTION => RUBY_DESCRIPTION
63
63
  }
64
64
 
65
65
  create(resource_attributes)
66
66
  end
67
+
68
+ private
69
+
70
+ def service_name_from_env
71
+ service_name = ENV['OTEL_SERVICE_NAME']
72
+ create(SemanticConventions::Resource::SERVICE_NAME => service_name) unless service_name.nil?
73
+ end
67
74
  end
68
75
 
69
76
  # @api private
@@ -13,4 +13,3 @@ module OpenTelemetry
13
13
  end
14
14
 
15
15
  require 'opentelemetry/sdk/resources/resource'
16
- require 'opentelemetry/sdk/resources/constants'
@@ -7,42 +7,13 @@
7
7
  module OpenTelemetry
8
8
  module SDK
9
9
  module Trace
10
- # A text annotation with a set of attributes and a timestamp.
11
- class Event
12
- EMPTY_ATTRIBUTES = {}.freeze
13
-
14
- private_constant :EMPTY_ATTRIBUTES
15
-
16
- # Returns the name of this event
17
- #
18
- # @return [String]
19
- attr_reader :name
20
-
21
- # Returns the frozen attributes for this event
22
- #
23
- # @return [Hash{String => String, Numeric, Boolean, Array<String, Numeric, Boolean>}]
24
- attr_reader :attributes
25
-
26
- # Returns the timestamp for this event
27
- #
28
- # @return [Time]
29
- attr_reader :timestamp
30
-
31
- # Returns a new immutable {Event}.
32
- #
33
- # @param [String] name The name of this event
34
- # @param [optional Hash{String => String, Numeric, Boolean, Array<String, Numeric, Boolean>}]
35
- # attributes A hash of attributes for this event. Attributes will be
36
- # frozen during Event initialization.
37
- # @param [optional Time] timestamp The timestamp for this event.
38
- # Defaults to Time.now.
39
- # @return [Event]
40
- def initialize(name:, attributes: nil, timestamp: nil)
41
- @name = name
42
- @attributes = attributes.freeze || EMPTY_ATTRIBUTES
43
- @timestamp = timestamp || Time.now
44
- end
45
- end
10
+ # A text annotation with a set of attributes and a timestamp for export.
11
+ #
12
+ # Field types are as follows:
13
+ # name: String
14
+ # attributes: frozen Hash{String => String, Numeric, Boolean, Array<String, Numeric, Boolean>}
15
+ # timestamp: Integer nanoseconds since Epoch
16
+ Event = Struct.new(:name, :attributes, :timestamp)
46
17
  end
47
18
  end
48
19
  end