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 +4 -4
- data/CHANGELOG.md +130 -68
- data/README.md +25 -2
- data/lib/opentelemetry/sdk/configurator.rb +44 -18
- data/lib/opentelemetry/sdk/forwarding_logger.rb +69 -0
- data/lib/opentelemetry/sdk/internal.rb +3 -3
- data/lib/opentelemetry/sdk/resources/resource.rb +16 -9
- data/lib/opentelemetry/sdk/resources.rb +0 -1
- data/lib/opentelemetry/sdk/trace/event.rb +7 -36
- data/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb +4 -4
- data/lib/opentelemetry/sdk/trace/export/{noop_span_exporter.rb → span_exporter.rb} +8 -7
- data/lib/opentelemetry/sdk/trace/export.rb +3 -2
- data/lib/opentelemetry/sdk/trace/span.rb +49 -42
- data/lib/opentelemetry/sdk/trace/span_data.rb +25 -18
- data/lib/opentelemetry/sdk/trace/span_limits.rb +60 -0
- data/lib/opentelemetry/sdk/trace/{noop_span_processor.rb → span_processor.rb} +5 -8
- data/lib/opentelemetry/sdk/trace/tracer.rb +1 -37
- data/lib/opentelemetry/sdk/trace/tracer_provider.rb +89 -19
- data/lib/opentelemetry/sdk/trace.rb +2 -3
- data/lib/opentelemetry/sdk/version.rb +1 -1
- data/lib/opentelemetry/sdk.rb +3 -1
- metadata +59 -20
- data/lib/opentelemetry/sdk/resources/constants.rb +0 -205
- data/lib/opentelemetry/sdk/trace/config/trace_config.rb +0 -85
- data/lib/opentelemetry/sdk/trace/config.rb +0 -18
- data/lib/opentelemetry/sdk/trace/export/multi_span_exporter.rb +0 -76
- data/lib/opentelemetry/sdk/trace/multi_span_processor.rb +0 -86
@@ -101,7 +101,7 @@ module OpenTelemetry
|
|
101
101
|
# @return [Integer] SUCCESS if no error occurred, FAILURE if a
|
102
102
|
# non-specific failure occurred, TIMEOUT if a timeout occurred.
|
103
103
|
def force_flush(timeout: nil) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength
|
104
|
-
start_time =
|
104
|
+
start_time = OpenTelemetry::Common::Utilities.timeout_timestamp
|
105
105
|
snapshot = lock do
|
106
106
|
reset_on_fork if @keep_running
|
107
107
|
spans.shift(spans.size)
|
@@ -137,7 +137,7 @@ module OpenTelemetry
|
|
137
137
|
# @return [Integer] SUCCESS if no error occurred, FAILURE if a
|
138
138
|
# non-specific failure occurred, TIMEOUT if a timeout occurred.
|
139
139
|
def shutdown(timeout: nil)
|
140
|
-
start_time =
|
140
|
+
start_time = OpenTelemetry::Common::Utilities.timeout_timestamp
|
141
141
|
thread = lock do
|
142
142
|
@keep_running = false
|
143
143
|
@condition.signal
|
@@ -146,9 +146,9 @@ module OpenTelemetry
|
|
146
146
|
|
147
147
|
thread&.join(timeout)
|
148
148
|
force_flush(timeout: OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time))
|
149
|
-
@exporter.shutdown(timeout: OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time))
|
150
149
|
dropped_spans = lock { spans.size }
|
151
150
|
report_dropped_spans(dropped_spans, reason: 'terminating') if dropped_spans.positive?
|
151
|
+
@exporter.shutdown(timeout: OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time))
|
152
152
|
end
|
153
153
|
|
154
154
|
private
|
@@ -194,7 +194,7 @@ module OpenTelemetry
|
|
194
194
|
@metrics_reporter.add_to_counter('otel.bsp.export.success')
|
195
195
|
@metrics_reporter.add_to_counter('otel.bsp.exported_spans', increment: batch.size)
|
196
196
|
else
|
197
|
-
OpenTelemetry.handle_error(
|
197
|
+
OpenTelemetry.handle_error(exception: ExportError.new("Unable to export #{batch.size} spans"))
|
198
198
|
@metrics_reporter.add_to_counter('otel.bsp.export.failure')
|
199
199
|
report_dropped_spans(batch.size, reason: 'export-failure')
|
200
200
|
end
|
@@ -8,24 +8,25 @@ module OpenTelemetry
|
|
8
8
|
module SDK
|
9
9
|
module Trace
|
10
10
|
module Export
|
11
|
-
#
|
12
|
-
#
|
11
|
+
# SpanExporter describes a duck type. It is not required to subclass this
|
12
|
+
# class to provide an implementation of SpanExporter, provided the interface is
|
13
|
+
# satisfied. SpanExporter allows different tracing services to export
|
13
14
|
# recorded data for sampled spans in their own format.
|
14
15
|
#
|
15
16
|
# To export data an exporter MUST be registered to the {TracerProvider} using
|
16
|
-
# a {
|
17
|
-
class
|
17
|
+
# a {SpanProcessor} implementation.
|
18
|
+
class SpanExporter
|
18
19
|
def initialize
|
19
20
|
@stopped = false
|
20
21
|
end
|
21
22
|
|
22
|
-
# Called to export sampled {
|
23
|
+
# Called to export sampled {SpanData}s.
|
23
24
|
#
|
24
|
-
# @param [Enumerable<
|
25
|
+
# @param [Enumerable<SpanData>] span_data the list of sampled {SpanData} to be
|
25
26
|
# exported.
|
26
27
|
# @param [optional Numeric] timeout An optional timeout in seconds.
|
27
28
|
# @return [Integer] the result of the export.
|
28
|
-
def export(
|
29
|
+
def export(span_data, timeout: nil)
|
29
30
|
return SUCCESS unless @stopped
|
30
31
|
|
31
32
|
FAILURE
|
@@ -10,6 +10,8 @@ module OpenTelemetry
|
|
10
10
|
# The Export module contains the built-in exporters and span processors for the OpenTelemetry
|
11
11
|
# reference implementation.
|
12
12
|
module Export
|
13
|
+
ExportError = Class.new(OpenTelemetry::Error)
|
14
|
+
|
13
15
|
# Result codes for the SpanExporter#export method and the SpanProcessor#force_flush and SpanProcessor#shutdown methods.
|
14
16
|
|
15
17
|
# The operation finished successfully.
|
@@ -31,6 +33,5 @@ require 'opentelemetry/sdk/trace/export/batch_span_processor'
|
|
31
33
|
require 'opentelemetry/sdk/trace/export/console_span_exporter'
|
32
34
|
require 'opentelemetry/sdk/trace/export/in_memory_span_exporter'
|
33
35
|
require 'opentelemetry/sdk/trace/export/metrics_reporter'
|
34
|
-
require 'opentelemetry/sdk/trace/export/
|
35
|
-
require 'opentelemetry/sdk/trace/export/noop_span_exporter'
|
36
|
+
require 'opentelemetry/sdk/trace/export/span_exporter'
|
36
37
|
require 'opentelemetry/sdk/trace/export/simple_span_processor'
|
@@ -10,15 +10,16 @@ module OpenTelemetry
|
|
10
10
|
# Implementation of {OpenTelemetry::Trace::Span} that records trace events.
|
11
11
|
#
|
12
12
|
# This implementation includes reader methods intended to allow access to
|
13
|
-
# internal state by
|
13
|
+
# internal state by {SpanProcessor}s.
|
14
14
|
# Instrumentation should use the API provided by {OpenTelemetry::Trace::Span}
|
15
15
|
# and should consider {Span} to be write-only.
|
16
16
|
#
|
17
17
|
# rubocop:disable Metrics/ClassLength
|
18
18
|
class Span < OpenTelemetry::Trace::Span
|
19
|
-
DEFAULT_STATUS = OpenTelemetry::Trace::Status.
|
19
|
+
DEFAULT_STATUS = OpenTelemetry::Trace::Status.unset
|
20
|
+
EMPTY_ATTRIBUTES = {}.freeze
|
20
21
|
|
21
|
-
private_constant
|
22
|
+
private_constant :DEFAULT_STATUS, :EMPTY_ATTRIBUTES
|
22
23
|
|
23
24
|
# The following readers are intended for the use of SpanProcessors and
|
24
25
|
# should not be considered part of the public interface for instrumentation.
|
@@ -70,7 +71,6 @@ module OpenTelemetry
|
|
70
71
|
#
|
71
72
|
# @return [self] returns itself
|
72
73
|
def set_attribute(key, value)
|
73
|
-
super
|
74
74
|
@mutex.synchronize do
|
75
75
|
if @ended
|
76
76
|
OpenTelemetry.logger.warn('Calling set_attribute on an ended Span.')
|
@@ -99,7 +99,6 @@ module OpenTelemetry
|
|
99
99
|
#
|
100
100
|
# @return [self] returns itself
|
101
101
|
def add_attributes(attributes)
|
102
|
-
super
|
103
102
|
@mutex.synchronize do
|
104
103
|
if @ended
|
105
104
|
OpenTelemetry.logger.warn('Calling add_attributes on an ended Span.')
|
@@ -132,8 +131,7 @@ module OpenTelemetry
|
|
132
131
|
#
|
133
132
|
# @return [self] returns itself
|
134
133
|
def add_event(name, attributes: nil, timestamp: nil)
|
135
|
-
|
136
|
-
event = Event.new(name: name, attributes: truncate_attribute_values(attributes), timestamp: timestamp || Time.now)
|
134
|
+
event = Event.new(name, truncate_attribute_values(attributes), wall_clock(timestamp))
|
137
135
|
|
138
136
|
@mutex.synchronize do
|
139
137
|
if @ended
|
@@ -161,7 +159,7 @@ module OpenTelemetry
|
|
161
159
|
event_attributes = {
|
162
160
|
'exception.type' => exception.class.to_s,
|
163
161
|
'exception.message' => exception.message,
|
164
|
-
'exception.stacktrace' => exception.full_message(highlight: false, order: :top)
|
162
|
+
'exception.stacktrace' => exception.full_message(highlight: false, order: :top).encode('UTF-8', invalid: :replace, undef: :replace, replace: '�')
|
165
163
|
}
|
166
164
|
event_attributes.merge!(attributes) unless attributes.nil?
|
167
165
|
add_event('exception', attributes: event_attributes)
|
@@ -169,21 +167,23 @@ module OpenTelemetry
|
|
169
167
|
|
170
168
|
# Sets the Status to the Span
|
171
169
|
#
|
172
|
-
# If used, this will override the default Span status. Default
|
170
|
+
# If used, this will override the default Span status. Default has code = Status::UNSET.
|
173
171
|
#
|
174
|
-
#
|
175
|
-
#
|
172
|
+
# An attempt to set the status with code == Status::UNSET is ignored.
|
173
|
+
# If the status is set with code == Status::OK, any further attempt to set the status
|
174
|
+
# is ignored.
|
176
175
|
#
|
177
176
|
# @param [Status] status The new status, which overrides the default Span
|
178
|
-
# status, which
|
177
|
+
# status, which has code = Status::UNSET.
|
179
178
|
#
|
180
179
|
# @return [void]
|
181
180
|
def status=(status)
|
182
|
-
|
181
|
+
return if status.code == OpenTelemetry::Trace::Status::UNSET
|
182
|
+
|
183
183
|
@mutex.synchronize do
|
184
184
|
if @ended
|
185
185
|
OpenTelemetry.logger.warn('Calling status= on an ended Span.')
|
186
|
-
|
186
|
+
elsif @status.code != OpenTelemetry::Trace::Status::OK
|
187
187
|
@status = status
|
188
188
|
end
|
189
189
|
end
|
@@ -199,7 +199,6 @@ module OpenTelemetry
|
|
199
199
|
#
|
200
200
|
# @return [void]
|
201
201
|
def name=(new_name)
|
202
|
-
super
|
203
202
|
@mutex.synchronize do
|
204
203
|
if @ended
|
205
204
|
OpenTelemetry.logger.warn('Calling name= on an ended Span.')
|
@@ -234,12 +233,12 @@ module OpenTelemetry
|
|
234
233
|
OpenTelemetry.logger.warn('Calling finish on an ended Span.')
|
235
234
|
return self
|
236
235
|
end
|
237
|
-
@end_timestamp = end_timestamp
|
236
|
+
@end_timestamp = wall_clock(end_timestamp)
|
238
237
|
@attributes = validated_attributes(@attributes).freeze
|
239
238
|
@events.freeze
|
240
239
|
@ended = true
|
241
240
|
end
|
242
|
-
@
|
241
|
+
@span_processors.each { |processor| processor.on_finish(self) }
|
243
242
|
self
|
244
243
|
end
|
245
244
|
|
@@ -277,14 +276,14 @@ module OpenTelemetry
|
|
277
276
|
end
|
278
277
|
|
279
278
|
# @api private
|
280
|
-
def initialize(context, parent_context, name, kind, parent_span_id,
|
279
|
+
def initialize(context, parent_context, name, kind, parent_span_id, span_limits, span_processors, attributes, links, start_timestamp, resource, instrumentation_library) # rubocop:disable Metrics/AbcSize
|
281
280
|
super(span_context: context)
|
282
281
|
@mutex = Mutex.new
|
283
282
|
@name = name
|
284
283
|
@kind = kind
|
285
284
|
@parent_span_id = parent_span_id.freeze || OpenTelemetry::Trace::INVALID_SPAN_ID
|
286
|
-
@
|
287
|
-
@
|
285
|
+
@span_limits = span_limits
|
286
|
+
@span_processors = span_processors
|
288
287
|
@resource = resource
|
289
288
|
@instrumentation_library = instrumentation_library
|
290
289
|
@ended = false
|
@@ -292,13 +291,13 @@ module OpenTelemetry
|
|
292
291
|
@total_recorded_events = 0
|
293
292
|
@total_recorded_links = links&.size || 0
|
294
293
|
@total_recorded_attributes = attributes&.size || 0
|
295
|
-
@start_timestamp = start_timestamp
|
294
|
+
@start_timestamp = wall_clock(start_timestamp)
|
296
295
|
@end_timestamp = nil
|
297
296
|
@attributes = attributes.nil? ? nil : Hash[attributes] # We need a mutable copy of attributes.
|
298
297
|
trim_span_attributes(@attributes)
|
299
298
|
@events = nil
|
300
|
-
@links = trim_links(links,
|
301
|
-
@
|
299
|
+
@links = trim_links(links, span_limits.link_count_limit, span_limits.link_attribute_count_limit)
|
300
|
+
@span_processors.each { |processor| processor.on_start(self, parent_context) }
|
302
301
|
end
|
303
302
|
|
304
303
|
# TODO: Java implementation overrides finalize to log if a span isn't finished.
|
@@ -306,7 +305,7 @@ module OpenTelemetry
|
|
306
305
|
private
|
307
306
|
|
308
307
|
def validated_attributes(attrs)
|
309
|
-
return attrs if Internal.valid_attributes?(attrs)
|
308
|
+
return attrs if Internal.valid_attributes?(name, 'span', attrs)
|
310
309
|
|
311
310
|
attrs.keep_if { |key, value| Internal.valid_key?(key) && Internal.valid_value?(value) }
|
312
311
|
end
|
@@ -314,65 +313,73 @@ module OpenTelemetry
|
|
314
313
|
def trim_span_attributes(attrs)
|
315
314
|
return if attrs.nil?
|
316
315
|
|
317
|
-
excess = attrs.size - @
|
316
|
+
excess = attrs.size - @span_limits.attribute_count_limit
|
318
317
|
excess.times { attrs.shift } if excess.positive?
|
319
318
|
truncate_attribute_values(attrs)
|
320
319
|
nil
|
321
320
|
end
|
322
321
|
|
323
322
|
def truncate_attribute_values(attrs)
|
324
|
-
return if attrs.nil?
|
323
|
+
return EMPTY_ATTRIBUTES if attrs.nil?
|
325
324
|
|
326
|
-
|
327
|
-
attrs.each { |key, value| attrs[key] = OpenTelemetry::Common::Utilities.truncate(value,
|
325
|
+
attribute_length_limit = @span_limits.attribute_length_limit
|
326
|
+
attrs.each { |key, value| attrs[key] = OpenTelemetry::Common::Utilities.truncate(value, attribute_length_limit) } if attribute_length_limit
|
328
327
|
attrs
|
329
328
|
end
|
330
329
|
|
331
|
-
def trim_links(links,
|
330
|
+
def trim_links(links, link_count_limit, link_attribute_count_limit) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
332
331
|
# Fast path (likely) common cases.
|
333
332
|
return nil if links.nil?
|
334
333
|
|
335
|
-
if links.size <=
|
336
|
-
links.all? { |link| link.attributes.size <=
|
334
|
+
if links.size <= link_count_limit &&
|
335
|
+
links.all? { |link| link.span_context.valid? && link.attributes.size <= link_attribute_count_limit && Internal.valid_attributes?(name, 'link', link.attributes) }
|
337
336
|
return links.frozen? ? links : links.clone.freeze
|
338
337
|
end
|
339
338
|
|
340
339
|
# Slow path: trim attributes for each Link.
|
341
|
-
links.
|
340
|
+
valid_links = links.select { |link| link.span_context.valid? }
|
341
|
+
excess_link_count = valid_links.size - link_count_limit
|
342
|
+
valid_links.pop(excess_link_count) if excess_link_count.positive?
|
343
|
+
valid_links.map! do |link|
|
342
344
|
attrs = Hash[link.attributes] # link.attributes is frozen, so we need an unfrozen copy to adjust.
|
343
345
|
attrs.keep_if { |key, value| Internal.valid_key?(key) && Internal.valid_value?(value) }
|
344
|
-
excess = attrs.size -
|
346
|
+
excess = attrs.size - link_attribute_count_limit
|
345
347
|
excess.times { attrs.shift } if excess.positive?
|
346
348
|
OpenTelemetry::Trace::Link.new(link.span_context, attrs)
|
347
349
|
end.freeze
|
348
350
|
end
|
349
351
|
|
350
352
|
def append_event(events, event) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
351
|
-
|
352
|
-
|
353
|
-
valid_attributes = Internal.valid_attributes?(event.attributes)
|
353
|
+
event_count_limit = @span_limits.event_count_limit
|
354
|
+
event_attribute_count_limit = @span_limits.event_attribute_count_limit
|
355
|
+
valid_attributes = Internal.valid_attributes?(name, 'event', event.attributes)
|
354
356
|
|
355
357
|
# Fast path (likely) common case.
|
356
|
-
if events.size <
|
357
|
-
event.attributes.size <=
|
358
|
+
if events.size < event_count_limit &&
|
359
|
+
event.attributes.size <= event_attribute_count_limit &&
|
358
360
|
valid_attributes
|
359
361
|
return events << event
|
360
362
|
end
|
361
363
|
|
362
364
|
# Slow path.
|
363
|
-
excess = events.size + 1 -
|
365
|
+
excess = events.size + 1 - event_count_limit
|
364
366
|
events.shift(excess) if excess.positive?
|
365
367
|
|
366
|
-
excess = event.attributes.size -
|
368
|
+
excess = event.attributes.size - event_attribute_count_limit
|
367
369
|
if excess.positive? || !valid_attributes
|
368
370
|
attrs = Hash[event.attributes] # event.attributes is frozen, so we need an unfrozen copy to adjust.
|
369
371
|
attrs.keep_if { |key, value| Internal.valid_key?(key) && Internal.valid_value?(value) }
|
370
|
-
excess = attrs.size -
|
372
|
+
excess = attrs.size - event_attribute_count_limit
|
371
373
|
excess.times { attrs.shift } if excess.positive?
|
372
|
-
event = Event.new(
|
374
|
+
event = Event.new(event.name, attrs.freeze, event.timestamp)
|
373
375
|
end
|
374
376
|
events << event
|
375
377
|
end
|
378
|
+
|
379
|
+
def wall_clock(timestamp)
|
380
|
+
timestamp = (timestamp.to_r * 1_000_000_000).to_i unless timestamp.nil?
|
381
|
+
timestamp || Process.clock_gettime(Process::CLOCK_REALTIME, :nanosecond)
|
382
|
+
end
|
376
383
|
end
|
377
384
|
# rubocop:enable Metrics/ClassLength
|
378
385
|
end
|
@@ -10,24 +10,24 @@ module OpenTelemetry
|
|
10
10
|
# implementation.
|
11
11
|
module Trace
|
12
12
|
# SpanData is a Struct containing {Span} data for export.
|
13
|
-
SpanData = Struct.new(:name,
|
14
|
-
:kind,
|
15
|
-
:status,
|
16
|
-
:parent_span_id,
|
17
|
-
:total_recorded_attributes,
|
18
|
-
:total_recorded_events,
|
19
|
-
:total_recorded_links,
|
20
|
-
:start_timestamp,
|
21
|
-
:end_timestamp,
|
22
|
-
:attributes,
|
23
|
-
:links,
|
24
|
-
:events,
|
25
|
-
:resource,
|
26
|
-
:instrumentation_library,
|
27
|
-
:span_id,
|
28
|
-
:trace_id,
|
29
|
-
:trace_flags,
|
30
|
-
:tracestate) do
|
13
|
+
SpanData = Struct.new(:name, # String
|
14
|
+
:kind, # Symbol: :internal, :producer, :consumer, :client, :server
|
15
|
+
:status, # Status
|
16
|
+
:parent_span_id, # String (8 byte binary), may be OpenTelemetry::Trace::INVALID_SPAN_ID
|
17
|
+
:total_recorded_attributes, # Integer
|
18
|
+
:total_recorded_events, # Integer
|
19
|
+
:total_recorded_links, # Integer
|
20
|
+
:start_timestamp, # Integer nanoseconds since Epoch
|
21
|
+
:end_timestamp, # Integer nanoseconds since Epoch
|
22
|
+
:attributes, # optional Hash{String => String, Numeric, Boolean, Array<String, Numeric, Boolean>}
|
23
|
+
:links, # optional Array[OpenTelemetry::Trace::Link]
|
24
|
+
:events, # optional Array[Event]
|
25
|
+
:resource, # OpenTelemetry::SDK::Resources::Resource
|
26
|
+
:instrumentation_library, # OpenTelemetry::SDK::InstrumentationLibrary
|
27
|
+
:span_id, # String (8 byte binary)
|
28
|
+
:trace_id, # String (16-byte binary)
|
29
|
+
:trace_flags, # Integer (8-bit byte of bit flags)
|
30
|
+
:tracestate) do # OpenTelemetry::Trace::Tracestate
|
31
31
|
# Returns the lowercase [hex encoded](https://tools.ietf.org/html/rfc4648#section-8) span ID.
|
32
32
|
#
|
33
33
|
# @return [String] A 16-hex-character lowercase string.
|
@@ -41,6 +41,13 @@ module OpenTelemetry
|
|
41
41
|
def hex_trace_id
|
42
42
|
trace_id.unpack1('H*')
|
43
43
|
end
|
44
|
+
|
45
|
+
# Returns the lowercase [hex encoded](https://tools.ietf.org/html/rfc4648#section-8) parent span ID.
|
46
|
+
#
|
47
|
+
# @return [String] A 16-hex-character lowercase string.
|
48
|
+
def hex_parent_span_id
|
49
|
+
parent_span_id.unpack1('H*')
|
50
|
+
end
|
44
51
|
end
|
45
52
|
end
|
46
53
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright The OpenTelemetry Authors
|
4
|
+
#
|
5
|
+
# SPDX-License-Identifier: Apache-2.0
|
6
|
+
|
7
|
+
module OpenTelemetry
|
8
|
+
module SDK
|
9
|
+
module Trace
|
10
|
+
# Class that holds global trace parameters.
|
11
|
+
class SpanLimits
|
12
|
+
# The global default max number of attributes per {Span}.
|
13
|
+
attr_reader :attribute_count_limit
|
14
|
+
|
15
|
+
# The global default max length of attribute value per {Span}.
|
16
|
+
attr_reader :attribute_length_limit
|
17
|
+
|
18
|
+
# The global default max number of {OpenTelemetry::SDK::Trace::Event}s per {Span}.
|
19
|
+
attr_reader :event_count_limit
|
20
|
+
|
21
|
+
# The global default max number of {OpenTelemetry::Trace::Link} entries per {Span}.
|
22
|
+
attr_reader :link_count_limit
|
23
|
+
|
24
|
+
# The global default max number of attributes per {OpenTelemetry::SDK::Trace::Event}.
|
25
|
+
attr_reader :event_attribute_count_limit
|
26
|
+
|
27
|
+
# The global default max number of attributes per {OpenTelemetry::Trace::Link}.
|
28
|
+
attr_reader :link_attribute_count_limit
|
29
|
+
|
30
|
+
# Returns a {SpanLimits} with the desired values.
|
31
|
+
#
|
32
|
+
# @return [SpanLimits] with the desired values.
|
33
|
+
# @raise [ArgumentError] if any of the max numbers are not positive.
|
34
|
+
def initialize(attribute_count_limit: Integer(ENV.fetch('OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT', 128)), # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
35
|
+
attribute_length_limit: ENV['OTEL_RUBY_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT'],
|
36
|
+
event_count_limit: Integer(ENV.fetch('OTEL_SPAN_EVENT_COUNT_LIMIT', 128)),
|
37
|
+
link_count_limit: Integer(ENV.fetch('OTEL_SPAN_LINK_COUNT_LIMIT', 128)),
|
38
|
+
event_attribute_count_limit: Integer(ENV.fetch('OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT', 128)),
|
39
|
+
link_attribute_count_limit: Integer(ENV.fetch('OTEL_LINK_ATTRIBUTE_COUNT_LIMIT', 128)))
|
40
|
+
raise ArgumentError, 'attribute_count_limit must be positive' unless attribute_count_limit.positive?
|
41
|
+
raise ArgumentError, 'attribute_length_limit must not be less than 32' unless attribute_length_limit.nil? || Integer(attribute_length_limit) >= 32
|
42
|
+
raise ArgumentError, 'event_count_limit must be positive' unless event_count_limit.positive?
|
43
|
+
raise ArgumentError, 'link_count_limit must be positive' unless link_count_limit.positive?
|
44
|
+
raise ArgumentError, 'event_attribute_count_limit must be positive' unless event_attribute_count_limit.positive?
|
45
|
+
raise ArgumentError, 'link_attribute_count_limit must be positive' unless link_attribute_count_limit.positive?
|
46
|
+
|
47
|
+
@attribute_count_limit = attribute_count_limit
|
48
|
+
@attribute_length_limit = attribute_length_limit.nil? ? nil : Integer(attribute_length_limit)
|
49
|
+
@event_count_limit = event_count_limit
|
50
|
+
@link_count_limit = link_count_limit
|
51
|
+
@event_attribute_count_limit = event_attribute_count_limit
|
52
|
+
@link_attribute_count_limit = link_attribute_count_limit
|
53
|
+
end
|
54
|
+
|
55
|
+
# The default {SpanLimits}.
|
56
|
+
DEFAULT = new
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -4,17 +4,14 @@
|
|
4
4
|
#
|
5
5
|
# SPDX-License-Identifier: Apache-2.0
|
6
6
|
|
7
|
-
require 'singleton'
|
8
|
-
|
9
7
|
module OpenTelemetry
|
10
8
|
module SDK
|
11
9
|
module Trace
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
# SpanProcessor describes a duck type and provides synchronous no-op hooks for when a
|
11
|
+
# {Span} is started or when a {Span} is ended. It is not required to subclass this
|
12
|
+
# class to provide an implementation of SpanProcessor, provided the interface is
|
13
|
+
# satisfied.
|
14
|
+
class SpanProcessor
|
18
15
|
# Called when a {Span} is started, if the {Span#recording?}
|
19
16
|
# returns true.
|
20
17
|
#
|
@@ -9,10 +9,6 @@ module OpenTelemetry
|
|
9
9
|
module Trace
|
10
10
|
# {Tracer} is the SDK implementation of {OpenTelemetry::Trace::Tracer}.
|
11
11
|
class Tracer < OpenTelemetry::Trace::Tracer
|
12
|
-
attr_reader :name
|
13
|
-
attr_reader :version
|
14
|
-
attr_reader :tracer_provider
|
15
|
-
|
16
12
|
# @api private
|
17
13
|
#
|
18
14
|
# Returns a new {Tracer} instance.
|
@@ -23,8 +19,6 @@ module OpenTelemetry
|
|
23
19
|
#
|
24
20
|
# @return [Tracer]
|
25
21
|
def initialize(name, version, tracer_provider)
|
26
|
-
@name = name
|
27
|
-
@version = version
|
28
22
|
@instrumentation_library = InstrumentationLibrary.new(name, version)
|
29
23
|
@tracer_provider = tracer_provider
|
30
24
|
end
|
@@ -42,37 +36,7 @@ module OpenTelemetry
|
|
42
36
|
parent_span_id = parent_span_context.span_id
|
43
37
|
trace_id = parent_span_context.trace_id
|
44
38
|
end
|
45
|
-
trace_id
|
46
|
-
sampler = tracer_provider.active_trace_config.sampler
|
47
|
-
result = sampler.should_sample?(trace_id: trace_id, parent_context: with_parent, links: links, name: name, kind: kind, attributes: attributes)
|
48
|
-
internal_create_span(result, name, kind, trace_id, parent_span_id, attributes, links, start_timestamp, with_parent)
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
|
-
def internal_create_span(result, name, kind, trace_id, parent_span_id, attributes, links, start_timestamp, parent_context) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
54
|
-
span_id = tracer_provider.id_generator.generate_span_id
|
55
|
-
if result.recording? && !tracer_provider.stopped?
|
56
|
-
trace_flags = result.sampled? ? OpenTelemetry::Trace::TraceFlags::SAMPLED : OpenTelemetry::Trace::TraceFlags::DEFAULT
|
57
|
-
context = OpenTelemetry::Trace::SpanContext.new(trace_id: trace_id, span_id: span_id, trace_flags: trace_flags, tracestate: result.tracestate)
|
58
|
-
attributes = attributes&.merge(result.attributes) || result.attributes
|
59
|
-
Span.new(
|
60
|
-
context,
|
61
|
-
parent_context,
|
62
|
-
name,
|
63
|
-
kind,
|
64
|
-
parent_span_id,
|
65
|
-
tracer_provider.active_trace_config,
|
66
|
-
tracer_provider.active_span_processor,
|
67
|
-
attributes,
|
68
|
-
links,
|
69
|
-
start_timestamp || Time.now,
|
70
|
-
tracer_provider.resource,
|
71
|
-
@instrumentation_library
|
72
|
-
)
|
73
|
-
else
|
74
|
-
OpenTelemetry::Trace::Span.new(span_context: OpenTelemetry::Trace::SpanContext.new(trace_id: trace_id, span_id: span_id, tracestate: result.tracestate))
|
75
|
-
end
|
39
|
+
@tracer_provider.internal_create_span(name, kind, trace_id, parent_span_id, attributes, links, start_timestamp, with_parent, @instrumentation_library)
|
76
40
|
end
|
77
41
|
end
|
78
42
|
end
|