opentelemetry-sdk 0.5.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +2 -2
  3. data/CHANGELOG.md +60 -0
  4. data/README.md +1 -1
  5. data/lib/opentelemetry/sdk.rb +2 -1
  6. data/lib/opentelemetry/sdk/baggage.rb +16 -0
  7. data/lib/opentelemetry/sdk/{correlation_context → baggage}/builder.rb +5 -5
  8. data/lib/opentelemetry/sdk/{correlation_context → baggage}/manager.rb +37 -27
  9. data/lib/opentelemetry/sdk/configurator.rb +41 -20
  10. data/lib/opentelemetry/sdk/resources/constants.rb +0 -4
  11. data/lib/opentelemetry/sdk/resources/resource.rb +33 -22
  12. data/lib/opentelemetry/sdk/trace.rb +1 -0
  13. data/lib/opentelemetry/sdk/trace/config/trace_config.rb +3 -3
  14. data/lib/opentelemetry/sdk/trace/event.rb +48 -0
  15. data/lib/opentelemetry/sdk/trace/export.rb +9 -4
  16. data/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb +84 -36
  17. data/lib/opentelemetry/sdk/trace/export/console_span_exporter.rb +5 -8
  18. data/lib/opentelemetry/sdk/trace/export/in_memory_span_exporter.rb +8 -2
  19. data/lib/opentelemetry/sdk/trace/export/multi_span_exporter.rb +17 -16
  20. data/lib/opentelemetry/sdk/trace/export/noop_span_exporter.rb +6 -2
  21. data/lib/opentelemetry/sdk/trace/export/simple_span_processor.rb +22 -4
  22. data/lib/opentelemetry/sdk/trace/multi_span_processor.rb +30 -6
  23. data/lib/opentelemetry/sdk/trace/noop_span_processor.rb +17 -3
  24. data/lib/opentelemetry/sdk/trace/samplers.rb +46 -45
  25. data/lib/opentelemetry/sdk/trace/samplers/constant_sampler.rb +4 -5
  26. data/lib/opentelemetry/sdk/trace/samplers/decision.rb +3 -3
  27. data/lib/opentelemetry/sdk/trace/samplers/parent_based.rb +54 -0
  28. data/lib/opentelemetry/sdk/trace/samplers/result.rb +16 -5
  29. data/lib/opentelemetry/sdk/trace/samplers/trace_id_ratio_based.rb +44 -0
  30. data/lib/opentelemetry/sdk/trace/span.rb +30 -36
  31. data/lib/opentelemetry/sdk/trace/span_data.rb +16 -3
  32. data/lib/opentelemetry/sdk/trace/tracer.rb +13 -12
  33. data/lib/opentelemetry/sdk/trace/tracer_provider.rb +4 -2
  34. data/lib/opentelemetry/sdk/version.rb +1 -1
  35. metadata +30 -11
  36. data/lib/opentelemetry/sdk/correlation_context.rb +0 -16
  37. data/lib/opentelemetry/sdk/trace/samplers/parent_or_else.rb +0 -43
  38. data/lib/opentelemetry/sdk/trace/samplers/probability_sampler.rb +0 -64
@@ -14,7 +14,6 @@ module OpenTelemetry
14
14
  :kind,
15
15
  :status,
16
16
  :parent_span_id,
17
- :child_count,
18
17
  :total_recorded_attributes,
19
18
  :total_recorded_events,
20
19
  :total_recorded_links,
@@ -23,12 +22,26 @@ module OpenTelemetry
23
22
  :attributes,
24
23
  :links,
25
24
  :events,
26
- :library_resource,
25
+ :resource,
27
26
  :instrumentation_library,
28
27
  :span_id,
29
28
  :trace_id,
30
29
  :trace_flags,
31
- :tracestate)
30
+ :tracestate) do
31
+ # Returns the lowercase [hex encoded](https://tools.ietf.org/html/rfc4648#section-8) span ID.
32
+ #
33
+ # @return [String] A 16-hex-character lowercase string.
34
+ def hex_span_id
35
+ span_id.unpack1('H*')
36
+ end
37
+
38
+ # Returns the lowercase [hex encoded](https://tools.ietf.org/html/rfc4648#section-8) trace ID.
39
+ #
40
+ # @return [String] A 32-hex-character lowercase string.
41
+ def hex_trace_id
42
+ trace_id.unpack1('H*')
43
+ end
44
+ end
32
45
  end
33
46
  end
34
47
  end
@@ -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, with_parent_context: Context.empty, attributes: attributes, links: links, start_timestamp: start_timestamp, kind: kind)
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, with_parent_context: nil, attributes: nil, links: nil, start_timestamp: nil, kind: nil)
36
+ def start_span(name, with_parent: nil, attributes: nil, links: nil, start_timestamp: nil, kind: nil)
37
37
  name ||= 'empty'
38
38
 
39
- parent_span_context = with_parent&.context || active_span_context(with_parent_context)
40
- parent_span_context = nil unless parent_span_context.valid?
41
- parent_span_id = parent_span_context&.span_id
42
- tracestate = parent_span_context&.tracestate
43
- trace_id = parent_span_context&.trace_id
39
+ with_parent ||= Context.current
40
+ parent_span_context = OpenTelemetry::Trace.current_span(with_parent).context
41
+ if parent_span_context.valid?
42
+ parent_span_id = parent_span_context.span_id
43
+ trace_id = parent_span_context.trace_id
44
+ end
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
- 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, span_id, parent_span_id, attributes, links, start_timestamp, tracestate)
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
49
  end
50
50
 
51
51
  private
52
52
 
53
- def internal_create_span(result, name, kind, trace_id, span_id, parent_span_id, attributes, links, start_timestamp, tracestate) # rubocop:disable Metrics/AbcSize
53
+ def internal_create_span(result, name, kind, trace_id, parent_span_id, attributes, links, start_timestamp, 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
- context = OpenTelemetry::Trace::SpanContext.new(trace_id: trace_id, trace_flags: trace_flags, tracestate: tracestate)
56
+ context = OpenTelemetry::Trace::SpanContext.new(trace_id: trace_id, trace_flags: trace_flags, tracestate: result.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,
@@ -49,13 +49,15 @@ module OpenTelemetry
49
49
  # processed and exported.
50
50
  #
51
51
  # After this is called all the newly created {Span}s will be no-op.
52
- def shutdown
52
+ #
53
+ # @param [optional Numeric] timeout An optional timeout in seconds.
54
+ def shutdown(timeout: nil)
53
55
  @mutex.synchronize do
54
56
  if @stopped
55
57
  OpenTelemetry.logger.warn('calling Tracer#shutdown multiple times.')
56
58
  return
57
59
  end
58
- @active_span_processor.shutdown
60
+ @active_span_processor.shutdown(timeout: timeout)
59
61
  @stopped = true
60
62
  end
61
63
  end
@@ -7,6 +7,6 @@
7
7
  module OpenTelemetry
8
8
  module SDK
9
9
  ## Current OpenTelemetry version
10
- VERSION = '0.5.1'
10
+ VERSION = '0.10.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: 0.5.1
4
+ version: 0.10.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-07-21 00:00:00.000000000 Z
11
+ date: 2020-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-api
@@ -16,14 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.5.0
19
+ version: 0.10.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.5.0
26
+ version: 0.10.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: opentelemetry-common
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.10.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.10.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -149,10 +163,10 @@ files:
149
163
  - README.md
150
164
  - lib/opentelemetry-sdk.rb
151
165
  - lib/opentelemetry/sdk.rb
166
+ - lib/opentelemetry/sdk/baggage.rb
167
+ - lib/opentelemetry/sdk/baggage/builder.rb
168
+ - lib/opentelemetry/sdk/baggage/manager.rb
152
169
  - lib/opentelemetry/sdk/configurator.rb
153
- - lib/opentelemetry/sdk/correlation_context.rb
154
- - lib/opentelemetry/sdk/correlation_context/builder.rb
155
- - lib/opentelemetry/sdk/correlation_context/manager.rb
156
170
  - lib/opentelemetry/sdk/instrumentation_library.rb
157
171
  - lib/opentelemetry/sdk/internal.rb
158
172
  - lib/opentelemetry/sdk/resources.rb
@@ -161,6 +175,7 @@ files:
161
175
  - lib/opentelemetry/sdk/trace.rb
162
176
  - lib/opentelemetry/sdk/trace/config.rb
163
177
  - lib/opentelemetry/sdk/trace/config/trace_config.rb
178
+ - lib/opentelemetry/sdk/trace/event.rb
164
179
  - lib/opentelemetry/sdk/trace/export.rb
165
180
  - lib/opentelemetry/sdk/trace/export/batch_span_processor.rb
166
181
  - lib/opentelemetry/sdk/trace/export/console_span_exporter.rb
@@ -173,9 +188,9 @@ files:
173
188
  - lib/opentelemetry/sdk/trace/samplers.rb
174
189
  - lib/opentelemetry/sdk/trace/samplers/constant_sampler.rb
175
190
  - lib/opentelemetry/sdk/trace/samplers/decision.rb
176
- - lib/opentelemetry/sdk/trace/samplers/parent_or_else.rb
177
- - lib/opentelemetry/sdk/trace/samplers/probability_sampler.rb
191
+ - lib/opentelemetry/sdk/trace/samplers/parent_based.rb
178
192
  - lib/opentelemetry/sdk/trace/samplers/result.rb
193
+ - lib/opentelemetry/sdk/trace/samplers/trace_id_ratio_based.rb
179
194
  - lib/opentelemetry/sdk/trace/span.rb
180
195
  - lib/opentelemetry/sdk/trace/span_data.rb
181
196
  - lib/opentelemetry/sdk/trace/tracer.rb
@@ -184,7 +199,11 @@ files:
184
199
  homepage: https://github.com/open-telemetry/opentelemetry-ruby
185
200
  licenses:
186
201
  - Apache-2.0
187
- metadata: {}
202
+ metadata:
203
+ changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-sdk/v0.10.0/file.CHANGELOG.html
204
+ source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/master/sdk
205
+ bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
206
+ documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-sdk/v0.10.0
188
207
  post_install_message:
189
208
  rdoc_options: []
190
209
  require_paths:
@@ -200,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
219
  - !ruby/object:Gem::Version
201
220
  version: '0'
202
221
  requirements: []
203
- rubygems_version: 3.0.3
222
+ rubygems_version: 3.1.4
204
223
  signing_key:
205
224
  specification_version: 4
206
225
  summary: A stats collection and distributed tracing framework
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright 2019 OpenTelemetry Authors
4
- #
5
- # SPDX-License-Identifier: Apache-2.0
6
-
7
- require 'opentelemetry/sdk/correlation_context/builder'
8
- require 'opentelemetry/sdk/correlation_context/manager'
9
-
10
- module OpenTelemetry
11
- module SDK
12
- # Contains operational implementations of the CorrelationContext::Manager
13
- module CorrelationContext
14
- end
15
- end
16
- end
@@ -1,43 +0,0 @@
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
- module Samplers
11
- # @api private
12
- #
13
- # This is a composite sampler. It either respects the parent span's sampling
14
- # decision or delegates to delegate_sampler for root spans.
15
- class ParentOrElse
16
- def initialize(delegate_sampler)
17
- @delegate_sampler = delegate_sampler
18
- end
19
-
20
- # @api private
21
- #
22
- # See {Samplers}.
23
- def description
24
- "ParentOrElse{#{@delegate_sampler.description}}"
25
- end
26
-
27
- # @api private
28
- #
29
- # See {Samplers}.
30
- def should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes:)
31
- if parent_context.nil?
32
- @delegate_sampler.should_sample?(trace_id: trace_id, parent_context: parent_context, links: links, name: name, kind: kind, attributes: attributes)
33
- elsif parent_context.trace_flags.sampled?
34
- RECORD_AND_SAMPLED
35
- else
36
- NOT_RECORD
37
- end
38
- end
39
- end
40
- end
41
- end
42
- end
43
- end
@@ -1,64 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright 2019 OpenTelemetry Authors
4
- #
5
- # SPDX-License-Identifier: Apache-2.0
6
-
7
- module OpenTelemetry
8
- module SDK
9
- module Trace
10
- module Samplers
11
- # @api private
12
- #
13
- # Implements sampling based on a probability.
14
- class ProbabilitySampler
15
- attr_reader :description
16
-
17
- def initialize(probability, ignore_parent:, apply_to_remote_parent:, apply_to_all_spans:)
18
- @probability = probability
19
- @id_upper_bound = (probability * (2**64 - 1)).ceil
20
- @use_parent_sampled_flag = !ignore_parent
21
- @apply_to_remote_parent = apply_to_remote_parent
22
- @apply_to_all_spans = apply_to_all_spans
23
- @description = format('ProbabilitySampler{%.6f}', probability)
24
- end
25
-
26
- # @api private
27
- #
28
- # See {Samplers}.
29
- def should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes:)
30
- # Ignored for sampling decision: links, name, kind, attributes.
31
-
32
- if sample?(trace_id, parent_context)
33
- RECORD_AND_SAMPLED
34
- else
35
- NOT_RECORD
36
- end
37
- end
38
-
39
- private
40
-
41
- def sample?(trace_id, parent_context)
42
- if parent_context.nil?
43
- sample_trace_id?(trace_id)
44
- else
45
- parent_sampled?(parent_context) || sample_trace_id_for_child?(parent_context, trace_id)
46
- end
47
- end
48
-
49
- def parent_sampled?(parent_context)
50
- @use_parent_sampled_flag && parent_context.trace_flags.sampled?
51
- end
52
-
53
- def sample_trace_id_for_child?(parent_context, trace_id)
54
- (@apply_to_all_spans || (@apply_to_remote_parent && parent_context.remote?)) && sample_trace_id?(trace_id)
55
- end
56
-
57
- def sample_trace_id?(trace_id)
58
- @probability == 1.0 || trace_id[8, 8].unpack1('Q>') < @id_upper_bound
59
- end
60
- end
61
- end
62
- end
63
- end
64
- end