opentelemetry-sdk 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +2 -2
- data/CHANGELOG.md +9 -0
- data/lib/opentelemetry/sdk/configurator.rb +22 -2
- data/lib/opentelemetry/sdk/trace/export.rb +9 -4
- data/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb +26 -3
- data/lib/opentelemetry/sdk/trace/export/console_span_exporter.rb +3 -6
- data/lib/opentelemetry/sdk/trace/export/in_memory_span_exporter.rb +4 -0
- data/lib/opentelemetry/sdk/trace/export/multi_span_exporter.rb +4 -1
- data/lib/opentelemetry/sdk/trace/export/noop_span_exporter.rb +1 -0
- data/lib/opentelemetry/sdk/trace/export/simple_span_processor.rb +13 -3
- data/lib/opentelemetry/sdk/trace/multi_span_processor.rb +12 -4
- data/lib/opentelemetry/sdk/trace/noop_span_processor.rb +15 -3
- data/lib/opentelemetry/sdk/trace/samplers.rb +9 -9
- data/lib/opentelemetry/sdk/trace/samplers/decision.rb +3 -3
- data/lib/opentelemetry/sdk/trace/samplers/result.rb +3 -3
- data/lib/opentelemetry/sdk/trace/samplers/trace_id_ratio_based.rb +2 -2
- data/lib/opentelemetry/sdk/trace/span.rb +7 -5
- data/lib/opentelemetry/sdk/trace/span_data.rb +0 -1
- data/lib/opentelemetry/sdk/trace/tracer.rb +7 -6
- data/lib/opentelemetry/sdk/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5510dccb3f3f94057ab6f17a625b8c71fbeeb958d2ec2de2eb732bfc59a4225
|
4
|
+
data.tar.gz: 768a8e36a2a5a34458d6872584339a93d14d83b0302ed998626d21d97d4592b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab2eb7f6eec8f1c62812e8a6f53502a2f29d017489078ede3c5fc4b4b9928435e71658c2cb506b73a16098ef681fffd9d088a028fd6938fec3da0d6a30cc3ec8
|
7
|
+
data.tar.gz: a1ee4191297bdb3491988e0bca431274f29685057578781e3911bd9f34e66042826aa1528c5eda9172d65beeaf6aeed269185665eb0f6a2361500de09a311c10
|
data/.yardopts
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# Release History: opentelemetry-sdk
|
2
2
|
|
3
|
+
### v0.7.0 / 2020-10-07
|
4
|
+
|
5
|
+
* ADDED: Add service_name setter to configurator
|
6
|
+
* ADDED: Add service_version setter to configurator
|
7
|
+
* FIXED: Fork safety for batch processor
|
8
|
+
* FIXED: Don't generate a span ID unnecessarily
|
9
|
+
* DOCS: Fix Configurator#add_span_processor
|
10
|
+
* DOCS: Standardize toplevel docs structure and readme
|
11
|
+
|
3
12
|
### v0.6.0 / 2020-09-10
|
4
13
|
|
5
14
|
* BREAKING CHANGE: Rename Resource labels to attributes
|
@@ -44,6 +44,26 @@ module OpenTelemetry
|
|
44
44
|
@resource = new_resource.merge(@resource)
|
45
45
|
end
|
46
46
|
|
47
|
+
# Accepts a string that is merged in as the service.name resource attribute.
|
48
|
+
# The most recent assigned value will be used in the event of repeated
|
49
|
+
# calls to this setter.
|
50
|
+
# @param [String] service_name The value to be used as the service name
|
51
|
+
def service_name=(service_name)
|
52
|
+
@resource = OpenTelemetry::SDK::Resources::Resource.create(
|
53
|
+
OpenTelemetry::SDK::Resources::Constants::SERVICE_RESOURCE[:name] => service_name
|
54
|
+
).merge(@resource)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Accepts a string that is merged in as the service.version resource attribute.
|
58
|
+
# The most recent assigned value will be used in the event of repeated
|
59
|
+
# calls to this setter.
|
60
|
+
# @param [String] service_version The value to be used as the service version
|
61
|
+
def service_version=(service_version)
|
62
|
+
@resource = OpenTelemetry::SDK::Resources::Resource.create(
|
63
|
+
OpenTelemetry::SDK::Resources::Constants::SERVICE_RESOURCE[:version] => service_version
|
64
|
+
).merge(@resource)
|
65
|
+
end
|
66
|
+
|
47
67
|
# Install an instrumentation with specificied optional +config+.
|
48
68
|
# Use can be called multiple times to install multiple instrumentation.
|
49
69
|
# Only +use+ or +use_all+, but not both when installing
|
@@ -73,8 +93,8 @@ module OpenTelemetry
|
|
73
93
|
|
74
94
|
# Add a span processor to the export pipeline
|
75
95
|
#
|
76
|
-
# @param [#on_start, #on_finish, #shutdown] span_processor A span_processor
|
77
|
-
# that satisfies the duck type #on_start, #on_finish, #shutdown. See
|
96
|
+
# @param [#on_start, #on_finish, #shutdown, #force_flush] span_processor A span_processor
|
97
|
+
# that satisfies the duck type #on_start, #on_finish, #shutdown, #force_flush. See
|
78
98
|
# {SimpleSpanProcessor} for an example.
|
79
99
|
def add_span_processor(span_processor)
|
80
100
|
@span_processors << span_processor
|
@@ -7,16 +7,21 @@
|
|
7
7
|
module OpenTelemetry
|
8
8
|
module SDK
|
9
9
|
module Trace
|
10
|
-
# The Export module contains the built-in exporters for the OpenTelemetry
|
10
|
+
# The Export module contains the built-in exporters and span processors for the OpenTelemetry
|
11
11
|
# reference implementation.
|
12
12
|
module Export
|
13
|
-
# Result codes for the SpanExporter#export method.
|
13
|
+
# Result codes for the SpanExporter#export method and the SpanProcessor#force_flush and SpanProcessor#shutdown methods.
|
14
14
|
|
15
|
-
# The
|
15
|
+
# The operation finished successfully.
|
16
16
|
SUCCESS = 0
|
17
17
|
|
18
|
-
# The
|
18
|
+
# The operation finished with an error.
|
19
19
|
FAILURE = 1
|
20
|
+
|
21
|
+
# Additional result code for the SpanProcessor#force_flush and SpanProcessor#shutdown methods.
|
22
|
+
|
23
|
+
# The operation timed out.
|
24
|
+
TIMEOUT = 2
|
20
25
|
end
|
21
26
|
end
|
22
27
|
end
|
@@ -56,11 +56,13 @@ module OpenTelemetry
|
|
56
56
|
@max_queue_size = max_queue_size
|
57
57
|
@batch_size = max_export_batch_size
|
58
58
|
@spans = []
|
59
|
-
@
|
59
|
+
@pid = nil
|
60
|
+
@thread = nil
|
61
|
+
reset_on_fork
|
60
62
|
end
|
61
63
|
|
62
64
|
# does nothing for this processor
|
63
|
-
def on_start(span)
|
65
|
+
def on_start(span, parent_context)
|
64
66
|
# noop
|
65
67
|
end
|
66
68
|
|
@@ -69,6 +71,7 @@ module OpenTelemetry
|
|
69
71
|
return unless span.context.trace_flags.sampled?
|
70
72
|
|
71
73
|
lock do
|
74
|
+
reset_on_fork
|
72
75
|
n = spans.size + 1 - max_queue_size
|
73
76
|
spans.shift(n) if n.positive?
|
74
77
|
spans << span
|
@@ -84,17 +87,27 @@ module OpenTelemetry
|
|
84
87
|
# necessary, such as when using some FaaS providers that may suspend
|
85
88
|
# the process after an invocation, but before the `Processor` exports
|
86
89
|
# the completed spans.
|
90
|
+
#
|
91
|
+
# @return [Integer] SUCCESS if no error occurred, FAILURE if a
|
92
|
+
# non-specific failure occurred, TIMEOUT if a timeout occurred.
|
87
93
|
def force_flush
|
88
|
-
snapshot = lock
|
94
|
+
snapshot = lock do
|
95
|
+
reset_on_fork(restart_thread: false) if @keep_running
|
96
|
+
spans.shift(spans.size)
|
97
|
+
end
|
89
98
|
until snapshot.empty?
|
90
99
|
batch = snapshot.shift(@batch_size).map!(&:to_span_data)
|
91
100
|
result_code = @exporter.export(batch)
|
92
101
|
report_result(result_code, batch)
|
93
102
|
end
|
103
|
+
SUCCESS
|
94
104
|
end
|
95
105
|
|
96
106
|
# shuts the consumer thread down and flushes the current accumulated buffer
|
97
107
|
# will block until the thread is finished
|
108
|
+
#
|
109
|
+
# @return [Integer] SUCCESS if no error occurred, FAILURE if a
|
110
|
+
# non-specific failure occurred, TIMEOUT if a timeout occurred.
|
98
111
|
def shutdown
|
99
112
|
lock do
|
100
113
|
@keep_running = false
|
@@ -113,6 +126,7 @@ module OpenTelemetry
|
|
113
126
|
def work
|
114
127
|
loop do
|
115
128
|
batch = lock do
|
129
|
+
reset_on_fork(restart_thread: false)
|
116
130
|
@condition.wait(@mutex, @delay_seconds) if spans.size < batch_size && @keep_running
|
117
131
|
@condition.wait(@mutex, @delay_seconds) while spans.empty? && @keep_running
|
118
132
|
return unless @keep_running
|
@@ -124,6 +138,15 @@ module OpenTelemetry
|
|
124
138
|
end
|
125
139
|
end
|
126
140
|
|
141
|
+
def reset_on_fork(restart_thread: true)
|
142
|
+
pid = Process.pid
|
143
|
+
return if @pid == pid
|
144
|
+
|
145
|
+
@pid = pid
|
146
|
+
spans.clear
|
147
|
+
@thread = Thread.new { work } if restart_thread
|
148
|
+
end
|
149
|
+
|
127
150
|
def export_batch(batch)
|
128
151
|
result_code = export_with_timeout(batch)
|
129
152
|
report_result(result_code, batch)
|
@@ -14,24 +14,21 @@ module OpenTelemetry
|
|
14
14
|
#
|
15
15
|
# Potentially useful for exploratory purposes.
|
16
16
|
class ConsoleSpanExporter
|
17
|
-
ResultCodes = OpenTelemetry::SDK::Trace::Export
|
18
|
-
|
19
|
-
private_constant(:ResultCodes)
|
20
|
-
|
21
17
|
def initialize
|
22
18
|
@stopped = false
|
23
19
|
end
|
24
20
|
|
25
21
|
def export(spans)
|
26
|
-
return
|
22
|
+
return FAILURE if @stopped
|
27
23
|
|
28
24
|
Array(spans).each { |s| pp s }
|
29
25
|
|
30
|
-
|
26
|
+
SUCCESS
|
31
27
|
end
|
32
28
|
|
33
29
|
def shutdown
|
34
30
|
@stopped = true
|
31
|
+
SUCCESS
|
35
32
|
end
|
36
33
|
end
|
37
34
|
end
|
@@ -73,11 +73,15 @@ module OpenTelemetry
|
|
73
73
|
|
74
74
|
# Called when {TracerProvider#shutdown} is called, if this exporter is
|
75
75
|
# registered to a {TracerProvider} object.
|
76
|
+
#
|
77
|
+
# @return [Integer] SUCCESS if no error occurred, FAILURE if a
|
78
|
+
# non-specific failure occurred, TIMEOUT if a timeout occurred.
|
76
79
|
def shutdown
|
77
80
|
@mutex.synchronize do
|
78
81
|
@finished_spans.clear
|
79
82
|
@stopped = true
|
80
83
|
end
|
84
|
+
SUCCESS
|
81
85
|
end
|
82
86
|
end
|
83
87
|
end
|
@@ -35,8 +35,11 @@ module OpenTelemetry
|
|
35
35
|
|
36
36
|
# Called when {TracerProvider#shutdown} is called, if this exporter is
|
37
37
|
# registered to a {TracerProvider} object.
|
38
|
+
#
|
39
|
+
# @return [Integer] SUCCESS if no error occurred, FAILURE if a
|
40
|
+
# non-specific failure occurred, TIMEOUT if a timeout occurred.
|
38
41
|
def shutdown
|
39
|
-
@span_exporters.
|
42
|
+
@span_exporters.map(&:shutdown).uniq.max
|
40
43
|
end
|
41
44
|
|
42
45
|
private
|
@@ -33,7 +33,9 @@ module OpenTelemetry
|
|
33
33
|
# not throw or block the execution thread.
|
34
34
|
#
|
35
35
|
# @param [Span] span the {Span} that just started.
|
36
|
-
|
36
|
+
# @param [Context] parent_context the parent {Context} of the newly
|
37
|
+
# started span.
|
38
|
+
def on_start(span, parent_context)
|
37
39
|
# Do nothing.
|
38
40
|
end
|
39
41
|
|
@@ -59,11 +61,19 @@ module OpenTelemetry
|
|
59
61
|
# necessary, such as when using some FaaS providers that may suspend
|
60
62
|
# the process after an invocation, but before the `Processor` exports
|
61
63
|
# the completed spans.
|
62
|
-
|
64
|
+
#
|
65
|
+
# @return [Integer] SUCCESS if no error occurred, FAILURE if a
|
66
|
+
# non-specific failure occurred, TIMEOUT if a timeout occurred.
|
67
|
+
def force_flush
|
68
|
+
SUCCESS
|
69
|
+
end
|
63
70
|
|
64
71
|
# Called when {TracerProvider#shutdown} is called.
|
72
|
+
#
|
73
|
+
# @return [Integer] SUCCESS if no error occurred, FAILURE if a
|
74
|
+
# non-specific failure occurred, TIMEOUT if a timeout occurred.
|
65
75
|
def shutdown
|
66
|
-
@span_exporter&.shutdown
|
76
|
+
@span_exporter&.shutdown || SUCCESS
|
67
77
|
end
|
68
78
|
end
|
69
79
|
end
|
@@ -26,8 +26,10 @@ module OpenTelemetry
|
|
26
26
|
# not throw or block the execution thread.
|
27
27
|
#
|
28
28
|
# @param [Span] span the {Span} that just started.
|
29
|
-
|
30
|
-
|
29
|
+
# @param [Context] parent_context the parent {Context} of the newly
|
30
|
+
# started span.
|
31
|
+
def on_start(span, parent_context)
|
32
|
+
@span_processors.each { |processor| processor.on_start(span, parent_context) }
|
31
33
|
end
|
32
34
|
|
33
35
|
# Called when a {Span} is ended, if the {Span#recording?}
|
@@ -48,13 +50,19 @@ module OpenTelemetry
|
|
48
50
|
# necessary, such as when using some FaaS providers that may suspend
|
49
51
|
# the process after an invocation, but before the `Processor` exports
|
50
52
|
# the completed spans.
|
53
|
+
#
|
54
|
+
# @return [Integer] Export::SUCCESS if no error occurred, Export::FAILURE if
|
55
|
+
# a non-specific failure occurred, Export::TIMEOUT if a timeout occurred.
|
51
56
|
def force_flush
|
52
|
-
@span_processors.
|
57
|
+
@span_processors.map(&:force_flush).uniq.max
|
53
58
|
end
|
54
59
|
|
55
60
|
# Called when {TracerProvider#shutdown} is called.
|
61
|
+
#
|
62
|
+
# @return [Integer] Export::SUCCESS if no error occurred, Export::FAILURE if
|
63
|
+
# a non-specific failure occurred, Export::TIMEOUT if a timeout occurred.
|
56
64
|
def shutdown
|
57
|
-
@span_processors.
|
65
|
+
@span_processors.map(&:shutdown).uniq.max
|
58
66
|
end
|
59
67
|
end
|
60
68
|
end
|
@@ -22,7 +22,9 @@ module OpenTelemetry
|
|
22
22
|
# not throw or block the execution thread.
|
23
23
|
#
|
24
24
|
# @param [Span] span the {Span} that just started.
|
25
|
-
|
25
|
+
# @param [Context] parent_context the parent {Context} of the newly
|
26
|
+
# started span.
|
27
|
+
def on_start(span, parent_context); end
|
26
28
|
|
27
29
|
# Called when a {Span} is ended, if the {Span#recording?}
|
28
30
|
# returns true.
|
@@ -40,10 +42,20 @@ module OpenTelemetry
|
|
40
42
|
# necessary, such as when using some FaaS providers that may suspend
|
41
43
|
# the process after an invocation, but before the `Processor` exports
|
42
44
|
# the completed spans.
|
43
|
-
|
45
|
+
#
|
46
|
+
# @return [Integer] Export::SUCCESS if no error occurred, Export::FAILURE if
|
47
|
+
# a non-specific failure occurred, Export::TIMEOUT if a timeout occurred.
|
48
|
+
def force_flush
|
49
|
+
Export::SUCCESS
|
50
|
+
end
|
44
51
|
|
45
52
|
# Called when {TracerProvider#shutdown} is called.
|
46
|
-
|
53
|
+
#
|
54
|
+
# @return [Integer] Export::SUCCESS if no error occurred, Export::FAILURE if
|
55
|
+
# a non-specific failure occurred, Export::TIMEOUT if a timeout occurred.
|
56
|
+
def shutdown
|
57
|
+
Export::SUCCESS
|
58
|
+
end
|
47
59
|
end
|
48
60
|
end
|
49
61
|
end
|
@@ -37,18 +37,18 @@ module OpenTelemetry
|
|
37
37
|
# to the {Span} to be created. Can be nil.
|
38
38
|
# @return [Result] The sampling result.
|
39
39
|
module Samplers
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
SAMPLING_HINTS = [Decision::
|
40
|
+
RECORD_AND_SAMPLE = Result.new(decision: Decision::RECORD_AND_SAMPLE)
|
41
|
+
DROP = Result.new(decision: Decision::DROP)
|
42
|
+
RECORD_ONLY = Result.new(decision: Decision::RECORD_ONLY)
|
43
|
+
SAMPLING_HINTS = [Decision::DROP, Decision::RECORD_ONLY, Decision::RECORD_AND_SAMPLE].freeze
|
44
44
|
|
45
|
-
private_constant(:
|
45
|
+
private_constant(:RECORD_AND_SAMPLE, :DROP, :RECORD_ONLY, :SAMPLING_HINTS)
|
46
46
|
|
47
|
-
# Returns a {Result} with {Decision::
|
48
|
-
ALWAYS_ON = ConstantSampler.new(result:
|
47
|
+
# Returns a {Result} with {Decision::RECORD_AND_SAMPLE}.
|
48
|
+
ALWAYS_ON = ConstantSampler.new(result: RECORD_AND_SAMPLE, description: 'AlwaysOnSampler')
|
49
49
|
|
50
|
-
# Returns a {Result} with {Decision::
|
51
|
-
ALWAYS_OFF = ConstantSampler.new(result:
|
50
|
+
# Returns a {Result} with {Decision::DROP}.
|
51
|
+
ALWAYS_OFF = ConstantSampler.new(result: DROP, description: 'AlwaysOffSampler')
|
52
52
|
|
53
53
|
# Returns a new sampler. It delegates to samplers according to the following rules:
|
54
54
|
#
|
@@ -12,13 +12,13 @@ module OpenTelemetry
|
|
12
12
|
# decision part of a sampling {Result}.
|
13
13
|
module Decision
|
14
14
|
# Decision to not record events and not sample.
|
15
|
-
|
15
|
+
DROP = :__drop__
|
16
16
|
|
17
17
|
# Decision to record events and not sample.
|
18
|
-
|
18
|
+
RECORD_ONLY = :__record_only__
|
19
19
|
|
20
20
|
# Decision to record events and sample.
|
21
|
-
|
21
|
+
RECORD_AND_SAMPLE = :__record_and_sample__
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -14,7 +14,7 @@ module OpenTelemetry
|
|
14
14
|
# root span.
|
15
15
|
class Result
|
16
16
|
EMPTY_HASH = {}.freeze
|
17
|
-
DECISIONS = [Decision::
|
17
|
+
DECISIONS = [Decision::RECORD_ONLY, Decision::DROP, Decision::RECORD_AND_SAMPLE].freeze
|
18
18
|
private_constant(:EMPTY_HASH, :DECISIONS)
|
19
19
|
|
20
20
|
# Returns a frozen hash of attributes to be attached span.
|
@@ -39,14 +39,14 @@ module OpenTelemetry
|
|
39
39
|
#
|
40
40
|
# @return [Boolean] sampling decision
|
41
41
|
def sampled?
|
42
|
-
@decision == Decision::
|
42
|
+
@decision == Decision::RECORD_AND_SAMPLE
|
43
43
|
end
|
44
44
|
|
45
45
|
# Returns true if this span should record events, attributes, status, etc.
|
46
46
|
#
|
47
47
|
# @return [Boolean] recording decision
|
48
48
|
def recording?
|
49
|
-
@decision != Decision::
|
49
|
+
@decision != Decision::DROP
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
@@ -16,6 +16,10 @@ module OpenTelemetry
|
|
16
16
|
#
|
17
17
|
# rubocop:disable Metrics/ClassLength
|
18
18
|
class Span < OpenTelemetry::Trace::Span
|
19
|
+
DEFAULT_STATUS = OpenTelemetry::Trace::Status.new(OpenTelemetry::Trace::Status::UNSET)
|
20
|
+
|
21
|
+
private_constant(:DEFAULT_STATUS)
|
22
|
+
|
19
23
|
# The following readers are intended for the use of SpanProcessors and
|
20
24
|
# should not be considered part of the public interface for instrumentation.
|
21
25
|
attr_reader :name, :status, :kind, :parent_span_id, :start_timestamp, :end_timestamp, :links, :resource, :instrumentation_library
|
@@ -219,7 +223,6 @@ module OpenTelemetry
|
|
219
223
|
@kind,
|
220
224
|
@status,
|
221
225
|
@parent_span_id,
|
222
|
-
@child_count,
|
223
226
|
@total_recorded_attributes,
|
224
227
|
@total_recorded_events,
|
225
228
|
@total_recorded_links,
|
@@ -238,7 +241,7 @@ module OpenTelemetry
|
|
238
241
|
end
|
239
242
|
|
240
243
|
# @api private
|
241
|
-
def initialize(context, name, kind, parent_span_id, trace_config, span_processor, attributes, links, start_timestamp, resource, instrumentation_library) # rubocop:disable Metrics/AbcSize
|
244
|
+
def initialize(context, parent_context, name, kind, parent_span_id, trace_config, span_processor, attributes, links, start_timestamp, resource, instrumentation_library) # rubocop:disable Metrics/AbcSize
|
242
245
|
super(span_context: context)
|
243
246
|
@mutex = Mutex.new
|
244
247
|
@name = name
|
@@ -249,8 +252,7 @@ module OpenTelemetry
|
|
249
252
|
@resource = resource
|
250
253
|
@instrumentation_library = instrumentation_library
|
251
254
|
@ended = false
|
252
|
-
@status =
|
253
|
-
@child_count = 0
|
255
|
+
@status = DEFAULT_STATUS
|
254
256
|
@total_recorded_events = 0
|
255
257
|
@total_recorded_links = links&.size || 0
|
256
258
|
@total_recorded_attributes = attributes&.size || 0
|
@@ -260,7 +262,7 @@ module OpenTelemetry
|
|
260
262
|
trim_span_attributes(@attributes)
|
261
263
|
@events = nil
|
262
264
|
@links = trim_links(links, trace_config.max_links_count, trace_config.max_attributes_per_link)
|
263
|
-
@span_processor.on_start(self)
|
265
|
+
@span_processor.on_start(self, parent_context)
|
264
266
|
end
|
265
267
|
|
266
268
|
# TODO: Java implementation overrides finalize to log if a span isn't finished.
|
@@ -30,33 +30,34 @@ module OpenTelemetry
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def start_root_span(name, attributes: nil, links: nil, start_timestamp: nil, kind: nil)
|
33
|
-
start_span(name,
|
33
|
+
start_span(name, with_parent: Context.empty, attributes: attributes, links: links, start_timestamp: start_timestamp, kind: kind)
|
34
34
|
end
|
35
35
|
|
36
|
-
def start_span(name, with_parent: nil,
|
36
|
+
def start_span(name, with_parent: nil, attributes: nil, links: nil, start_timestamp: nil, kind: nil) # rubocop:disable Metrics/AbcSize
|
37
37
|
name ||= 'empty'
|
38
38
|
|
39
|
-
|
39
|
+
with_parent ||= Context.current
|
40
|
+
parent_span_context = current_span(with_parent).context
|
40
41
|
parent_span_context = nil unless parent_span_context.valid?
|
41
42
|
parent_span_id = parent_span_context&.span_id
|
42
43
|
tracestate = parent_span_context&.tracestate
|
43
44
|
trace_id = parent_span_context&.trace_id
|
44
45
|
trace_id ||= OpenTelemetry::Trace.generate_trace_id
|
45
|
-
span_id = OpenTelemetry::Trace.generate_span_id
|
46
46
|
sampler = tracer_provider.active_trace_config.sampler
|
47
47
|
result = sampler.should_sample?(trace_id: trace_id, parent_context: parent_span_context, links: links, name: name, kind: kind, attributes: attributes)
|
48
|
-
internal_create_span(result, name, kind, trace_id,
|
48
|
+
internal_create_span(result, name, kind, trace_id, parent_span_id, attributes, links, start_timestamp, tracestate, with_parent)
|
49
49
|
end
|
50
50
|
|
51
51
|
private
|
52
52
|
|
53
|
-
def internal_create_span(result, name, kind, trace_id,
|
53
|
+
def internal_create_span(result, name, kind, trace_id, parent_span_id, attributes, links, start_timestamp, tracestate, parent_context) # rubocop:disable Metrics/AbcSize
|
54
54
|
if result.recording? && !tracer_provider.stopped?
|
55
55
|
trace_flags = result.sampled? ? OpenTelemetry::Trace::TraceFlags::SAMPLED : OpenTelemetry::Trace::TraceFlags::DEFAULT
|
56
56
|
context = OpenTelemetry::Trace::SpanContext.new(trace_id: trace_id, trace_flags: trace_flags, tracestate: tracestate)
|
57
57
|
attributes = attributes&.merge(result.attributes) || result.attributes
|
58
58
|
Span.new(
|
59
59
|
context,
|
60
|
+
parent_context,
|
60
61
|
name,
|
61
62
|
kind,
|
62
63
|
parent_span_id,
|
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: 0.
|
4
|
+
version: 0.7.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: 2020-
|
11
|
+
date: 2020-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opentelemetry-api
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.7.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.7.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -201,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
201
201
|
- !ruby/object:Gem::Version
|
202
202
|
version: '0'
|
203
203
|
requirements: []
|
204
|
-
rubygems_version: 3.1.
|
204
|
+
rubygems_version: 3.1.4
|
205
205
|
signing_key:
|
206
206
|
specification_version: 4
|
207
207
|
summary: A stats collection and distributed tracing framework
|