opentelemetry-sdk 1.4.1 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 30876b5f639b980b00d48fbae72e4b01850b3c57cafa01aa4dc5ca580be0918d
4
- data.tar.gz: d002cb6584183e04b65a7b770bb75565bee3fe54396ade52714a009a26a5cb92
3
+ metadata.gz: e3ba5bcaae681a8f24969dd8aa7d886e0d1b57b3c26d46ef71bc2724bf5e7fe4
4
+ data.tar.gz: 1d41a63a92487100a7f6a0e5fd74a18c92a7d9adf744ee561cc43e8def5c288b
5
5
  SHA512:
6
- metadata.gz: 940facba296fde53952e694e465b7ab72cbbfabbeaa1e8bec8444476dcd57c6efd5227208021722d7130698eb33f0baf5d332594bac5f79ec946950b3c5231e3
7
- data.tar.gz: 3b2f25a049880af16792a74ec5c35b3531555bff41f049ddf91422da7896f836a295c54419fc8e82abfe076cfd6fe003a0093a2a91319e65c246c00dc280e229
6
+ metadata.gz: d6e3c2646902e1adb9efa33ab7d20b6d0a572c03e077a03b6cc13c1b94d95c2f41bcd1235b60f251384f9cd303fc49c4e3b88c2a6d6654e1de8b2356b3be6212
7
+ data.tar.gz: 6729117a513daecc2d6f2e09de4601ca77777c51d0b110e3d4eea7a4365bcb1dffef201f529acb3479b20299e840154276fa2e50fd87871c575d7c859d36d848
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Release History: opentelemetry-sdk
2
2
 
3
+ ### v1.6.0 / 2024-12-04
4
+
5
+ * ADDED: Add hooks to configure logs
6
+
7
+ ### v1.5.0 / 2024-07-24
8
+
9
+ * ADDED: Add add_link to span api/sdk
10
+ * FIXED: Update `untraced` to suppress logging "Calling finish on an ended Span" warnings
11
+
3
12
  ### v1.4.1 / 2024-03-21
4
13
 
5
14
  * FIXED: ForwardingLogger should forward block param.
data/README.md CHANGED
@@ -12,13 +12,19 @@ OpenTelemetry provides a single set of APIs, libraries, agents, and collector se
12
12
 
13
13
  The `opentelemetry-sdk` gem provides the reference implementation of the OpenTelemetry Ruby interfaces defined in the `opentelemetry-api` gem. That is, it includes the *functionality* needed to collect, analyze, and export telemetry data produced using the API.
14
14
 
15
- Generally, Ruby *applications* should install `opentelemetry-sdk` (or other concrete implementation of the OpenTelemetry API). Using the SDK, an application can configure how it wants telemetry data to be handled, including which data should be persisted, how it should be formatted, and where it should be recorded or exported. However, *libraries* that produce telemetry data should generally depend only on `opentelemetry-api`, deferring the choise of concrete implementation to the application developer.
15
+ Generally, Ruby *applications* should install `opentelemetry-sdk` (or
16
+ other concrete implementation of the OpenTelemetry API). Using the SDK,
17
+ an application can configure how it wants telemetry data to be handled,
18
+ including which data should be persisted, how it should be formatted,
19
+ and where it should be recorded or exported. However, *libraries* that
20
+ produce telemetry data should generally depend only on
21
+ `opentelemetry-api`, deferring the choice of concrete implementation to the application developer.
16
22
 
17
23
  ## How do I get started?
18
24
 
19
25
  Install the gem using:
20
26
 
21
- ```
27
+ ```sh
22
28
  gem install opentelemetry-sdk
23
29
  ```
24
30
 
@@ -53,7 +59,7 @@ OpenTelemetry::SDK.configure
53
59
  # c.use 'OpenTelemetry::Instrumentation::Net::HTTP'
54
60
  # end
55
61
  #
56
- # Note that the SimpleSpanExporter is not recommended for use in production.
62
+ # Note that the SimpleSpanProcessor is not recommended for use in production.
57
63
 
58
64
 
59
65
  # To start a trace you need to get a Tracer from the TracerProvider
@@ -85,7 +91,6 @@ The OpenTelemetry Ruby gems are maintained by the OpenTelemetry-Ruby special int
85
91
 
86
92
  The `opentelemetry-sdk` gem is distributed under the Apache 2.0 license. See [LICENSE][license-github] for more information.
87
93
 
88
-
89
94
  [opentelemetry-home]: https://opentelemetry.io
90
95
  [bundler-home]: https://bundler.io
91
96
  [repo-github]: https://github.com/open-telemetry/opentelemetry-ruby
@@ -90,7 +90,7 @@ module OpenTelemetry
90
90
  )
91
91
  end
92
92
 
93
- # Install an instrumentation with specificied optional +config+.
93
+ # Install an instrumentation with specified optional +config+.
94
94
  # Use can be called multiple times to install multiple instrumentation.
95
95
  # Only +use+ or +use_all+, but not both when installing
96
96
  # instrumentation. A call to +use_all+ after +use+ will result in an
@@ -126,13 +126,20 @@ module OpenTelemetry
126
126
  @span_processors << span_processor
127
127
  end
128
128
 
129
+ # Add a log record processor to the export pipeline
130
+ #
131
+ # @param [#emit, #shutdown, #force_flush] log_record_processor A log_record_processor
132
+ # that satisfies the duck type #emit, #shutdown, #force_flush. See
133
+ # {SimpleLogRecordProcessor} for an example.
134
+ def add_log_record_processor(log_record_processor); end
135
+
129
136
  # @api private
130
137
  # The configure method is where we define the setup process. This allows
131
138
  # us to make certain guarantees about which systems and globals are setup
132
139
  # at each stage. The setup process is:
133
140
  # - setup logging
134
141
  # - setup propagation
135
- # - setup tracer_provider and meter_provider
142
+ # - setup tracer_provider, meter_provider, and logger_provider
136
143
  # - install instrumentation
137
144
  def configure
138
145
  OpenTelemetry.logger = logger
@@ -142,6 +149,7 @@ module OpenTelemetry
142
149
  tracer_provider.id_generator = @id_generator
143
150
  OpenTelemetry.tracer_provider = tracer_provider
144
151
  metrics_configuration_hook
152
+ logs_configuration_hook
145
153
  install_instrumentation
146
154
  end
147
155
 
@@ -149,6 +157,8 @@ module OpenTelemetry
149
157
 
150
158
  def metrics_configuration_hook; end
151
159
 
160
+ def logs_configuration_hook; end
161
+
152
162
  def tracer_provider
153
163
  @tracer_provider ||= Trace::TracerProvider.new(resource: @resource)
154
164
  end
@@ -118,6 +118,37 @@ module OpenTelemetry
118
118
  self
119
119
  end
120
120
 
121
+ # Add a link to a {Span}.
122
+ #
123
+ # Adding links at span creation using the `links` option is preferred
124
+ # to calling add_link later, because head sampling decisions can only
125
+ # consider information present during span creation.
126
+ #
127
+ # Example:
128
+ #
129
+ # span.add_link(OpenTelemetry::Trace::Link.new(span_to_link_from.context))
130
+ #
131
+ # Note that the OpenTelemetry project
132
+ # {https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/data-semantic-conventions.md
133
+ # documents} certain "standard attributes" that have prescribed semantic
134
+ # meanings.
135
+ #
136
+ # @param [OpenTelemetry::Trace::Link] the link object to add on the {Span}.
137
+ #
138
+ # @return [self] returns itself
139
+ def add_link(link)
140
+ @mutex.synchronize do
141
+ if @ended
142
+ OpenTelemetry.logger.warn('Calling add_link on an ended Span.')
143
+ else
144
+ @links ||= []
145
+ @links = trim_links(@links << link, @span_limits.link_count_limit, @span_limits.link_attribute_count_limit)
146
+ @total_recorded_links += 1
147
+ end
148
+ end
149
+ self
150
+ end
151
+
121
152
  # Add an Event to a {Span}.
122
153
  #
123
154
  # Example:
@@ -240,8 +271,12 @@ module OpenTelemetry
240
271
  return self
241
272
  end
242
273
  @end_timestamp = relative_timestamp(end_timestamp)
274
+ @span_processors.each do |processor|
275
+ processor.on_finishing(self) if processor.respond_to?(:on_finishing)
276
+ end
243
277
  @attributes = validated_attributes(@attributes).freeze
244
278
  @events.freeze
279
+ @links.freeze
245
280
  @ended = true
246
281
  end
247
282
  @span_processors.each { |processor| processor.on_finish(self) }
@@ -373,7 +408,7 @@ module OpenTelemetry
373
408
 
374
409
  if links.size <= link_count_limit &&
375
410
  links.all? { |link| link.span_context.valid? && link.attributes.size <= link_attribute_count_limit && Internal.valid_attributes?(name, 'link', link.attributes) }
376
- return links.frozen? ? links : links.clone.freeze
411
+ return links
377
412
  end
378
413
 
379
414
  # Slow path: trim attributes for each Link.
@@ -386,7 +421,7 @@ module OpenTelemetry
386
421
  excess = attrs.size - link_attribute_count_limit
387
422
  excess.times { attrs.shift } if excess.positive?
388
423
  OpenTelemetry::Trace::Link.new(link.span_context, attrs)
389
- end.freeze
424
+ end
390
425
  end
391
426
 
392
427
  def append_event(events, event) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
@@ -41,7 +41,6 @@ module OpenTelemetry
41
41
  event_attribute_count_limit: Integer(OpenTelemetry::Common::Utilities.config_opt('OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT', default: 128)),
42
42
  event_attribute_length_limit: OpenTelemetry::Common::Utilities.config_opt('OTEL_EVENT_ATTRIBUTE_VALUE_LENGTH_LIMIT', 'OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT'),
43
43
  link_attribute_count_limit: Integer(OpenTelemetry::Common::Utilities.config_opt('OTEL_LINK_ATTRIBUTE_COUNT_LIMIT', default: 128)))
44
-
45
44
  raise ArgumentError, 'attribute_count_limit must be positive' unless attribute_count_limit.positive?
46
45
  raise ArgumentError, 'attribute_length_limit must not be less than 32' unless attribute_length_limit.nil? || Integer(attribute_length_limit) >= 32
47
46
  raise ArgumentError, 'event_count_limit must be positive' unless event_count_limit.positive?
@@ -23,6 +23,24 @@ module OpenTelemetry
23
23
  # started span.
24
24
  def on_start(span, parent_context); end
25
25
 
26
+ # The on_finishing method is an experimental feature and may have breaking changes.
27
+ # The OpenTelemetry specification defines it as "On Ending". As `end` is a reserved
28
+ # keyword in Ruby, we are using `on_finishing` instead.
29
+ #
30
+ # Called when a {Span} is ending, after the end timestamp has been set
31
+ # but before span becomes immutable. This allows for updating the span
32
+ # by setting attributes or adding links and events.
33
+ #
34
+ # This method is called synchronously and should not block the current
35
+ # thread nor throw exceptions.
36
+ #
37
+ # This method is optional on the Span Processor interface. It will only
38
+ # get called if it exists within the processor.
39
+ #
40
+ # @param [Span] span the {Span} that just is ending (still mutable).
41
+ # @return [void]
42
+ def on_finishing(span); end
43
+
26
44
  # Called when a {Span} is ended, if the {Span#recording?}
27
45
  # returns true.
28
46
  #
@@ -29,8 +29,6 @@ module OpenTelemetry
29
29
 
30
30
  def start_span(name, with_parent: nil, attributes: nil, links: nil, start_timestamp: nil, kind: nil)
31
31
  with_parent ||= Context.current
32
- return super(name, with_parent: with_parent, attributes: attributes, links: links, start_timestamp: start_timestamp, kind: kind) if Common::Utilities.untraced?(with_parent)
33
-
34
32
  name ||= 'empty'
35
33
  kind ||= :internal
36
34
 
@@ -126,7 +126,7 @@ module OpenTelemetry
126
126
  end
127
127
 
128
128
  # @api private
129
- def internal_start_span(name, kind, attributes, links, start_timestamp, parent_context, instrumentation_scope) # rubocop:disable Metrics/MethodLength
129
+ def internal_start_span(name, kind, attributes, links, start_timestamp, parent_context, instrumentation_scope) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
130
130
  parent_span = OpenTelemetry::Trace.current_span(parent_context)
131
131
  parent_span_context = parent_span.context
132
132
 
@@ -134,8 +134,13 @@ module OpenTelemetry
134
134
  parent_span_id = parent_span_context.span_id
135
135
  trace_id = parent_span_context.trace_id
136
136
  end
137
-
138
137
  trace_id ||= @id_generator.generate_trace_id
138
+
139
+ if OpenTelemetry::Common::Utilities.untraced?(parent_context)
140
+ span_id = parent_span_id || @id_generator.generate_span_id
141
+ return OpenTelemetry::Trace.non_recording_span(OpenTelemetry::Trace::SpanContext.new(trace_id: trace_id, span_id: span_id))
142
+ end
143
+
139
144
  result = @sampler.should_sample?(trace_id: trace_id, parent_context: parent_context, links: links, name: name, kind: kind, attributes: attributes)
140
145
  span_id = @id_generator.generate_span_id
141
146
  if result.recording? && !@stopped
@@ -7,6 +7,6 @@
7
7
  module OpenTelemetry
8
8
  module SDK
9
9
  ## Current OpenTelemetry version
10
- VERSION = '1.4.1'
10
+ VERSION = '1.6.0'
11
11
  end
12
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentelemetry-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenTelemetry Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-26 00:00:00.000000000 Z
11
+ date: 2024-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-api
@@ -184,14 +184,14 @@ dependencies:
184
184
  requirements:
185
185
  - - "~>"
186
186
  - !ruby/object:Gem::Version
187
- version: 1.51.0
187
+ version: '1.65'
188
188
  type: :development
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - "~>"
193
193
  - !ruby/object:Gem::Version
194
- version: 1.51.0
194
+ version: '1.65'
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: simplecov
197
197
  requirement: !ruby/object:Gem::Requirement
@@ -294,10 +294,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby
294
294
  licenses:
295
295
  - Apache-2.0
296
296
  metadata:
297
- changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-sdk/v1.4.1/file.CHANGELOG.html
297
+ changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-sdk/v1.6.0/file.CHANGELOG.html
298
298
  source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/sdk
299
299
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
300
- documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-sdk/v1.4.1
300
+ documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-sdk/v1.6.0
301
301
  post_install_message:
302
302
  rdoc_options: []
303
303
  require_paths: