opentelemetry-sdk 0.6.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +2 -2
  3. data/CHANGELOG.md +42 -0
  4. data/LICENSE +1 -1
  5. data/lib/opentelemetry-sdk.rb +1 -1
  6. data/lib/opentelemetry/sdk.rb +2 -1
  7. data/lib/opentelemetry/sdk/baggage.rb +1 -1
  8. data/lib/opentelemetry/sdk/baggage/builder.rb +1 -1
  9. data/lib/opentelemetry/sdk/baggage/manager.rb +1 -1
  10. data/lib/opentelemetry/sdk/configurator.rb +23 -3
  11. data/lib/opentelemetry/sdk/instrumentation_library.rb +1 -1
  12. data/lib/opentelemetry/sdk/internal.rb +1 -1
  13. data/lib/opentelemetry/sdk/resources.rb +1 -1
  14. data/lib/opentelemetry/sdk/resources/constants.rb +1 -5
  15. data/lib/opentelemetry/sdk/resources/resource.rb +1 -1
  16. data/lib/opentelemetry/sdk/trace.rb +1 -1
  17. data/lib/opentelemetry/sdk/trace/config.rb +1 -1
  18. data/lib/opentelemetry/sdk/trace/config/trace_config.rb +1 -1
  19. data/lib/opentelemetry/sdk/trace/event.rb +1 -1
  20. data/lib/opentelemetry/sdk/trace/export.rb +11 -5
  21. data/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb +86 -30
  22. data/lib/opentelemetry/sdk/trace/export/console_span_exporter.rb +6 -9
  23. data/lib/opentelemetry/sdk/trace/export/in_memory_span_exporter.rb +9 -3
  24. data/lib/opentelemetry/sdk/trace/export/metrics_reporter.rb +59 -0
  25. data/lib/opentelemetry/sdk/trace/export/multi_span_exporter.rb +18 -17
  26. data/lib/opentelemetry/sdk/trace/export/noop_span_exporter.rb +7 -3
  27. data/lib/opentelemetry/sdk/trace/export/simple_span_processor.rb +23 -5
  28. data/lib/opentelemetry/sdk/trace/multi_span_processor.rb +31 -7
  29. data/lib/opentelemetry/sdk/trace/noop_span_processor.rb +18 -4
  30. data/lib/opentelemetry/sdk/trace/samplers.rb +9 -15
  31. data/lib/opentelemetry/sdk/trace/samplers/constant_sampler.rb +4 -5
  32. data/lib/opentelemetry/sdk/trace/samplers/decision.rb +4 -4
  33. data/lib/opentelemetry/sdk/trace/samplers/parent_based.rb +5 -4
  34. data/lib/opentelemetry/sdk/trace/samplers/result.rb +17 -6
  35. data/lib/opentelemetry/sdk/trace/samplers/trace_id_ratio_based.rb +4 -5
  36. data/lib/opentelemetry/sdk/trace/span.rb +10 -8
  37. data/lib/opentelemetry/sdk/trace/span_data.rb +1 -2
  38. data/lib/opentelemetry/sdk/trace/tracer.rb +14 -13
  39. data/lib/opentelemetry/sdk/trace/tracer_provider.rb +5 -3
  40. data/lib/opentelemetry/sdk/version.rb +2 -2
  41. metadata +25 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a01fcf121db23108ffb47d196f9594993018bb1b945242710620bb87daa8320
4
- data.tar.gz: ef3b3e9cd4e2853a22ffb149e7a18cbd021988412d24c40350192e222b3be58b
3
+ metadata.gz: cb411f30633b54940beb1f9098606f19330f8ebab59e3b98cec8e56ec2e3bbdf
4
+ data.tar.gz: 6f9a05cd0341cf0411c501abbb40648c11dc97d920b65728386dca2c404b8f60
5
5
  SHA512:
6
- metadata.gz: 5da08d0e902ece66efc7afa892f99f2b9fe3bcd5b89b51cd3da1a565a23ab0917eb1c39d6fb44ed6b82a71048624cb357539d9b6305b1a0c8debc594ef2467d3
7
- data.tar.gz: 5fe47387c0d91e8d5436be4d4464839f08a9ae46964e8fe1679ab6ef7e7bf8b7a59ae086472d465e6f12c57b70c712a982064351f287a8ebbb6bbe173c37b45d
6
+ metadata.gz: 44ed1519e66997080314953a11e483e6f00d4bb774b9eecc6effe6623f2e48c68485594717db25ba39bd92c453cd25c926c0ca2dabc19588878067eefba48ece
7
+ data.tar.gz: 3f1dcd7506145ed4c008403926827205ed8661a3ee6c35f524ead8d6fd16984ce556722c4b0917229e2e641c37ffe3c83088beadd990d6dfb6015a1fa083cf6a
data/.yardopts CHANGED
@@ -1,9 +1,9 @@
1
1
  --no-private
2
2
  --title=OpenTelemetry SDK
3
3
  --markup=markdown
4
- --main=OVERVIEW.md
4
+ --main=README.md
5
5
  ./lib/opentelemetry/sdk/**/*.rb
6
6
  ./lib/opentelemetry/sdk.rb
7
7
  -
8
- OVERVIEW.md
8
+ README.md
9
9
  CHANGELOG.md
@@ -1,5 +1,47 @@
1
1
  # Release History: opentelemetry-sdk
2
2
 
3
+ ### v0.11.0 / 2020-12-11
4
+
5
+ * ADDED: Metrics reporting from trace export
6
+ * FIXED: Copyright comments to not reference year
7
+
8
+ ### v0.10.0 / 2020-12-03
9
+
10
+ * BREAKING CHANGE: Allow samplers to modify tracestate
11
+
12
+ * FIXED: Allow samplers to modify tracestate
13
+
14
+ ### v0.9.0 / 2020-11-27
15
+
16
+ * BREAKING CHANGE: Pass full Context to samplers
17
+ * BREAKING CHANGE: Add timeout for force_flush and shutdown
18
+
19
+ * ADDED: Add OTEL_RUBY_BSP_START_THREAD_ON_BOOT env var
20
+ * ADDED: Add timeout for force_flush and shutdown
21
+ * FIXED: Signal at batch_size
22
+ * FIXED: SDK Span.recording? after finish
23
+ * FIXED: Pass full Context to samplers
24
+ * DOCS: Add documentation on usage scenarios for span processors
25
+
26
+ ### v0.8.0 / 2020-10-27
27
+
28
+ * BREAKING CHANGE: Move context/span methods to Trace module
29
+ * BREAKING CHANGE: Remove 'canonical' from status codes
30
+ * BREAKING CHANGE: Assorted SpanContext fixes
31
+
32
+ * FIXED: Move context/span methods to Trace module
33
+ * FIXED: Remove 'canonical' from status codes
34
+ * FIXED: Assorted SpanContext fixes
35
+
36
+ ### v0.7.0 / 2020-10-07
37
+
38
+ * ADDED: Add service_name setter to configurator
39
+ * ADDED: Add service_version setter to configurator
40
+ * FIXED: Fork safety for batch processor
41
+ * FIXED: Don't generate a span ID unnecessarily
42
+ * DOCS: Fix Configurator#add_span_processor
43
+ * DOCS: Standardize toplevel docs structure and readme
44
+
3
45
  ### v0.6.0 / 2020-09-10
4
46
 
5
47
  * BREAKING CHANGE: Rename Resource labels to attributes
data/LICENSE CHANGED
@@ -186,7 +186,7 @@
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
- Copyright 2020 OpenTelemetry Authors
189
+ Copyright The OpenTelemetry Authors
190
190
 
191
191
  Licensed under the Apache License, Version 2.0 (the "License");
192
192
  you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2019 OpenTelemetry Authors
3
+ # Copyright The OpenTelemetry Authors
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2019 OpenTelemetry Authors
3
+ # Copyright The OpenTelemetry Authors
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
7
7
  require 'opentelemetry'
8
+ require 'opentelemetry/common'
8
9
 
9
10
  # OpenTelemetry is an open source observability framework, providing a
10
11
  # general-purpose API, SDK, and related tools required for the instrumentation
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2019 OpenTelemetry Authors
3
+ # Copyright The OpenTelemetry Authors
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2019 OpenTelemetry Authors
3
+ # Copyright The OpenTelemetry Authors
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2019 OpenTelemetry Authors
3
+ # Copyright The OpenTelemetry Authors
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2019 OpenTelemetry Authors
3
+ # Copyright The OpenTelemetry Authors
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
@@ -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
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2019 OpenTelemetry Authors
3
+ # Copyright The OpenTelemetry Authors
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2019 OpenTelemetry Authors
3
+ # Copyright The OpenTelemetry Authors
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2019 OpenTelemetry Authors
3
+ # Copyright The OpenTelemetry Authors
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2020 OpenTelemetry Authors
3
+ # Copyright The OpenTelemetry Authors
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
@@ -79,10 +79,6 @@ module OpenTelemetry
79
79
 
80
80
  # Attributes defining a computing instance (e.g. host).
81
81
  HOST_RESOURCE = {
82
- # Hostname of the host. It contains what the hostname command returns on the
83
- # host machine.
84
- hostname: 'host.hostname',
85
-
86
82
  # Unique host id. For Cloud this must be the instance_id assigned by the
87
83
  # cloud provider
88
84
  id: 'host.id',
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2019 OpenTelemetry Authors
3
+ # Copyright The OpenTelemetry Authors
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2019 OpenTelemetry Authors
3
+ # Copyright The OpenTelemetry Authors
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2019 OpenTelemetry Authors
3
+ # Copyright The OpenTelemetry Authors
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2019 OpenTelemetry Authors
3
+ # Copyright The OpenTelemetry Authors
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2019 OpenTelemetry Authors
3
+ # Copyright The OpenTelemetry Authors
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
@@ -1,22 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2019 OpenTelemetry Authors
3
+ # Copyright The OpenTelemetry Authors
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
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 export operation finished successfully.
15
+ # The operation finished successfully.
16
16
  SUCCESS = 0
17
17
 
18
- # The export operation finished with an error.
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
@@ -25,6 +30,7 @@ end
25
30
  require 'opentelemetry/sdk/trace/export/batch_span_processor'
26
31
  require 'opentelemetry/sdk/trace/export/console_span_exporter'
27
32
  require 'opentelemetry/sdk/trace/export/in_memory_span_exporter'
33
+ require 'opentelemetry/sdk/trace/export/metrics_reporter'
28
34
  require 'opentelemetry/sdk/trace/export/multi_span_exporter'
29
35
  require 'opentelemetry/sdk/trace/export/noop_span_exporter'
30
36
  require 'opentelemetry/sdk/trace/export/simple_span_processor'
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright 2019 OpenTelemetry Authors
3
+ # Copyright The OpenTelemetry Authors
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
@@ -13,6 +13,9 @@ module OpenTelemetry
13
13
  # Implementation of the duck type SpanProcessor that batches spans
14
14
  # exported by the SDK then pushes them to the exporter pipeline.
15
15
  #
16
+ # Typically, the BatchSpanProcessor will be more suitable for
17
+ # production environments than the SimpleSpanProcessor.
18
+ #
16
19
  # All spans reported by the SDK implementation are first added to a
17
20
  # synchronized queue (with a {max_queue_size} maximum size, after the
18
21
  # size is reached spans are dropped) and exported every
@@ -22,7 +25,7 @@ module OpenTelemetry
22
25
  # If the queue gets half full a preemptive notification is sent to the
23
26
  # worker thread that exports the spans to wake up and start a new
24
27
  # export cycle.
25
- class BatchSpanProcessor
28
+ class BatchSpanProcessor # rubocop:disable Metrics/ClassLength
26
29
  # Returns a new instance of the {BatchSpanProcessor}.
27
30
  #
28
31
  # @param [SpanExporter] exporter
@@ -44,39 +47,44 @@ module OpenTelemetry
44
47
  exporter_timeout_millis: Float(ENV.fetch('OTEL_BSP_EXPORT_TIMEOUT_MILLIS', 30_000)),
45
48
  schedule_delay_millis: Float(ENV.fetch('OTEL_BSP_SCHEDULE_DELAY_MILLIS', 5_000)),
46
49
  max_queue_size: Integer(ENV.fetch('OTEL_BSP_MAX_QUEUE_SIZE', 2048)),
47
- max_export_batch_size: Integer(ENV.fetch('OTEL_BSP_MAX_EXPORT_BATCH_SIZE', 512)))
50
+ max_export_batch_size: Integer(ENV.fetch('OTEL_BSP_MAX_EXPORT_BATCH_SIZE', 512)),
51
+ start_thread_on_boot: String(ENV['OTEL_RUBY_BSP_START_THREAD_ON_BOOT']) !~ /false/i,
52
+ metrics_reporter: nil)
48
53
  raise ArgumentError if max_export_batch_size > max_queue_size
49
54
 
50
55
  @exporter = exporter
51
56
  @exporter_timeout_seconds = exporter_timeout_millis / 1000.0
52
57
  @mutex = Mutex.new
58
+ @export_mutex = Mutex.new
53
59
  @condition = ConditionVariable.new
54
60
  @keep_running = true
55
61
  @delay_seconds = schedule_delay_millis / 1000.0
56
62
  @max_queue_size = max_queue_size
57
63
  @batch_size = max_export_batch_size
64
+ @metrics_reporter = metrics_reporter || OpenTelemetry::SDK::Trace::Export::MetricsReporter
58
65
  @spans = []
59
- @thread = Thread.new { work }
66
+ @pid = nil
67
+ @thread = nil
68
+ reset_on_fork(restart_thread: start_thread_on_boot)
60
69
  end
61
70
 
62
- # does nothing for this processor
63
- def on_start(span)
64
- # noop
65
- end
71
+ # Does nothing for this processor
72
+ def on_start(_span, _parent_context); end
66
73
 
67
- # adds a span to the batcher, threadsafe may block on lock
74
+ # Adds a span to the batch. Thread-safe; may block on lock.
68
75
  def on_finish(span) # rubocop:disable Metrics/AbcSize
69
76
  return unless span.context.trace_flags.sampled?
70
77
 
71
78
  lock do
79
+ reset_on_fork
72
80
  n = spans.size + 1 - max_queue_size
73
81
  spans.shift(n) if n.positive?
82
+ report_dropped_spans(n, reason: 'buffer-full')
74
83
  spans << span
75
- @condition.signal if spans.size > max_queue_size / 2
84
+ @condition.signal if spans.size > batch_size
76
85
  end
77
86
  end
78
87
 
79
- # TODO: test this explicitly.
80
88
  # Export all ended spans to the configured `Exporter` that have not yet
81
89
  # been exported.
82
90
  #
@@ -84,35 +92,66 @@ module OpenTelemetry
84
92
  # necessary, such as when using some FaaS providers that may suspend
85
93
  # the process after an invocation, but before the `Processor` exports
86
94
  # the completed spans.
87
- def force_flush
88
- snapshot = lock { spans.shift(spans.size) }
95
+ #
96
+ # @param [optional Numeric] timeout An optional timeout in seconds.
97
+ # @return [Integer] SUCCESS if no error occurred, FAILURE if a
98
+ # non-specific failure occurred, TIMEOUT if a timeout occurred.
99
+ def force_flush(timeout: nil) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
100
+ start_time = Time.now
101
+ snapshot = lock do
102
+ reset_on_fork(restart_thread: false) if @keep_running
103
+ spans.shift(spans.size)
104
+ end
89
105
  until snapshot.empty?
106
+ remaining_timeout = OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time)
107
+ return TIMEOUT if remaining_timeout&.zero?
108
+
90
109
  batch = snapshot.shift(@batch_size).map!(&:to_span_data)
91
- result_code = @exporter.export(batch)
92
- report_result(result_code, batch)
110
+ result_code = export_batch(batch, timeout: remaining_timeout)
111
+ return result_code unless result_code == SUCCESS
112
+ end
113
+
114
+ SUCCESS
115
+ ensure
116
+ # Unshift the remaining spans if we timed out. We drop excess spans from
117
+ # the snapshot because they're older than any spans in the spans buffer.
118
+ lock do
119
+ n = spans.size + snapshot.size - max_queue_size
120
+ snapshot.shift(n) if n.positive?
121
+ report_dropped_spans(n, reason: 'buffer-full')
122
+ spans.unshift(snapshot) unless snapshot.empty?
123
+ @condition.signal if spans.size > max_queue_size / 2
93
124
  end
94
125
  end
95
126
 
96
- # shuts the consumer thread down and flushes the current accumulated buffer
97
- # will block until the thread is finished
98
- def shutdown
127
+ # Shuts the consumer thread down and flushes the current accumulated buffer
128
+ # will block until the thread is finished.
129
+ #
130
+ # @param [optional Numeric] timeout An optional timeout in seconds.
131
+ # @return [Integer] SUCCESS if no error occurred, FAILURE if a
132
+ # non-specific failure occurred, TIMEOUT if a timeout occurred.
133
+ def shutdown(timeout: nil)
134
+ start_time = Time.now
99
135
  lock do
100
136
  @keep_running = false
101
137
  @condition.signal
102
138
  end
103
139
 
104
- @thread.join
105
- force_flush
106
- @exporter.shutdown
140
+ @thread.join(timeout)
141
+ force_flush(timeout: OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time))
142
+ @exporter.shutdown(timeout: OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time))
143
+ dropped_spans = lock { spans.size }
144
+ report_dropped_spans(dropped_spans, reason: 'terminating') if dropped_spans.positive?
107
145
  end
108
146
 
109
147
  private
110
148
 
111
149
  attr_reader :spans, :max_queue_size, :batch_size
112
150
 
113
- def work
151
+ def work # rubocop:disable Metrics/AbcSize
114
152
  loop do
115
153
  batch = lock do
154
+ reset_on_fork(restart_thread: false)
116
155
  @condition.wait(@mutex, @delay_seconds) if spans.size < batch_size && @keep_running
117
156
  @condition.wait(@mutex, @delay_seconds) while spans.empty? && @keep_running
118
157
  return unless @keep_running
@@ -120,23 +159,40 @@ module OpenTelemetry
120
159
  fetch_batch
121
160
  end
122
161
 
162
+ @metrics_reporter.observe_value('otel.bsp.buffer_utilization', value: spans.size / max_queue_size.to_f)
163
+
123
164
  export_batch(batch)
124
165
  end
125
166
  end
126
167
 
127
- def export_batch(batch)
128
- result_code = export_with_timeout(batch)
129
- report_result(result_code, batch)
168
+ def reset_on_fork(restart_thread: true)
169
+ pid = Process.pid
170
+ return if @pid == pid
171
+
172
+ @pid = pid
173
+ spans.clear
174
+ @thread = Thread.new { work } if restart_thread
130
175
  end
131
176
 
132
- def export_with_timeout(batch)
133
- Timeout.timeout(@exporter_timeout_seconds) { @exporter.export(batch) }
134
- rescue Timeout::Error
135
- FAILURE
177
+ def export_batch(batch, timeout: @exporter_timeout_seconds)
178
+ result_code = @export_mutex.synchronize { @exporter.export(batch, timeout: timeout) }
179
+ report_result(result_code, batch)
180
+ result_code
136
181
  end
137
182
 
138
183
  def report_result(result_code, batch)
139
- OpenTelemetry.logger.error("Unable to export #{batch.size} spans") unless result_code == SUCCESS
184
+ if result_code == SUCCESS
185
+ @metrics_reporter.add_to_counter('otel.bsp.export.success')
186
+ @metrics_reporter.add_to_counter('otel.bsp.exported_spans', increment: batch.size)
187
+ else
188
+ OpenTelemetry.logger.error("Unable to export #{batch.size} spans")
189
+ @metrics_reporter.add_to_counter('otel.bsp.export.failure')
190
+ report_dropped_spans(batch.size, reason: 'export-failure')
191
+ end
192
+ end
193
+
194
+ def report_dropped_spans(count, reason:)
195
+ @metrics_reporter.add_to_counter('otel.bsp.dropped_spans', increment: count, labels: { 'reason' => reason })
140
196
  end
141
197
 
142
198
  def fetch_batch