opentelemetry-metrics-sdk 0.16.0 → 0.17.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.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/lib/opentelemetry/sdk/metrics/aggregation/aggregation_temporality.rb +2 -0
  4. data/lib/opentelemetry/sdk/metrics/aggregation/drop.rb +3 -0
  5. data/lib/opentelemetry/sdk/metrics/aggregation/explicit_bucket_histogram.rb +5 -1
  6. data/lib/opentelemetry/sdk/metrics/aggregation/exponential_bucket_histogram.rb +1 -0
  7. data/lib/opentelemetry/sdk/metrics/aggregation/exponential_histogram/buckets.rb +7 -0
  8. data/lib/opentelemetry/sdk/metrics/aggregation/exponential_histogram/exponent_mapping.rb +2 -0
  9. data/lib/opentelemetry/sdk/metrics/aggregation/exponential_histogram/ieee_754.rb +2 -0
  10. data/lib/opentelemetry/sdk/metrics/aggregation/exponential_histogram/logarithm_mapping.rb +1 -0
  11. data/lib/opentelemetry/sdk/metrics/aggregation/histogram_data_point.rb +1 -0
  12. data/lib/opentelemetry/sdk/metrics/aggregation/last_value.rb +3 -0
  13. data/lib/opentelemetry/sdk/metrics/aggregation/number_data_point.rb +1 -0
  14. data/lib/opentelemetry/sdk/metrics/aggregation/sum.rb +5 -0
  15. data/lib/opentelemetry/sdk/metrics/configurator_patch.rb +1 -0
  16. data/lib/opentelemetry/sdk/metrics/exemplar/aligned_histogram_bucket_exemplar_reservoir.rb +1 -0
  17. data/lib/opentelemetry/sdk/metrics/exemplar/always_off_exemplar_filter.rb +1 -0
  18. data/lib/opentelemetry/sdk/metrics/exemplar/always_on_exemplar_filter.rb +1 -0
  19. data/lib/opentelemetry/sdk/metrics/exemplar/noop_exemplar_reservoir.rb +3 -0
  20. data/lib/opentelemetry/sdk/metrics/exemplar/simple_fixed_size_exemplar_reservoir.rb +2 -0
  21. data/lib/opentelemetry/sdk/metrics/exemplar/trace_based_exemplar_filter.rb +1 -0
  22. data/lib/opentelemetry/sdk/metrics/export/console_metric_pull_exporter.rb +4 -0
  23. data/lib/opentelemetry/sdk/metrics/export/in_memory_metric_pull_exporter.rb +4 -0
  24. data/lib/opentelemetry/sdk/metrics/export/metric_reader.rb +3 -0
  25. data/lib/opentelemetry/sdk/metrics/export/periodic_metric_reader.rb +1 -0
  26. data/lib/opentelemetry/sdk/metrics/fork_hooks.rb +3 -0
  27. data/lib/opentelemetry/sdk/metrics/instrument/asynchronous_instrument.rb +3 -0
  28. data/lib/opentelemetry/sdk/metrics/meter.rb +3 -0
  29. data/lib/opentelemetry/sdk/metrics/meter_provider.rb +1 -0
  30. data/lib/opentelemetry/sdk/metrics/state/asynchronous_metric_stream.rb +1 -0
  31. data/lib/opentelemetry/sdk/metrics/state/metric_store.rb +2 -0
  32. data/lib/opentelemetry/sdk/metrics/state/metric_stream.rb +7 -0
  33. data/lib/opentelemetry/sdk/metrics/version.rb +1 -1
  34. data/lib/opentelemetry/sdk/metrics/view/registered_view.rb +3 -0
  35. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f72c4249d5329efc05eafffbe85f1475d2ae238b63c1af22a71eca6925def1bb
4
- data.tar.gz: 85a822d11b3e73032c44355dd83c64af8512b50a2a69146ff777246b7f4d5ed6
3
+ metadata.gz: 19efd834eb63674a6e6769fc893179b31bf4eed29698e91f29a85d7df1d53bf8
4
+ data.tar.gz: e027637325d0a920d55ee9e0a99f6ed9b1e532d87cc433d9af6385a6341c8b51
5
5
  SHA512:
6
- metadata.gz: d320ce1c51b00a0ca50b8bc18ec4d466e24ecbf3f5ca5aff63e27e001cfd7a467a4f7c71f57b2fcc048ff466c27dd9bd0333607cfaabda1469513288517d3cc6
7
- data.tar.gz: d33515584f7c941b780019a0998a31a2cc3b30fd66438aa167d0f68ad7d1f747bd15216aec353a5cacdc0e61451a2eec64c9c8ce7bef436783f3ef8ba46a1c11
6
+ metadata.gz: 98626a904390ea3ced74266657db022bd11ac546556f9592834206adf8f1f5efa7e53274157e819915d68a78440daaf2d27354258eca9edd8c83d5f350433f89
7
+ data.tar.gz: c7a873d868f87602727955163b1214af900a9662eddbc8a5fe0b7b41ac8416b3cb97d1cbb3d02dcc32334449ad483dadb7d8bd24e566ce8ebedb135a93370fd4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Release History: opentelemetry-metrics-sdk
2
2
 
3
+ ### v0.17.0 / 2026-09-01
4
+
5
+ * ADDED: Add flags to metrics data model (#2302)
6
+
3
7
  ### v0.16.0 / 2026-08-04
4
8
 
5
9
  * ADDED: Add attributes to Meter InstrumentationScope (#2273)
@@ -67,10 +67,12 @@ module OpenTelemetry
67
67
  @temporality = temporality
68
68
  end
69
69
 
70
+ # Returns whether this instance's temporality is DELTA.
70
71
  def delta?
71
72
  @temporality == :delta
72
73
  end
73
74
 
75
+ # Returns whether this instance's temporality is CUMULATIVE.
74
76
  def cumulative?
75
77
  @temporality == :cumulative
76
78
  end
@@ -18,16 +18,19 @@ module OpenTelemetry
18
18
  @exemplar_reservoir = DEFAULT_RESERVOIR
19
19
  end
20
20
 
21
+ # Returns the collected data points, discarding them from further collection.
21
22
  def collect(start_time, end_time, data_points)
22
23
  data_points.values.map!(&:dup)
23
24
  end
24
25
 
26
+ # No-op: discards the recorded value instead of aggregating it.
25
27
  def update(increment, attributes, data_points, cardinality_limit, exemplar_offer: false)
26
28
  data_points[attributes] = NumberDataPoint.new(
27
29
  {},
28
30
  0,
29
31
  0,
30
32
  0,
33
+ 0,
31
34
  []
32
35
  )
33
36
  nil
@@ -10,7 +10,7 @@ module OpenTelemetry
10
10
  module Aggregation
11
11
  # Contains the implementation of the ExplicitBucketHistogram aggregation
12
12
  # https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#explicit-bucket-histogram-aggregation
13
- class ExplicitBucketHistogram
13
+ class ExplicitBucketHistogram # rubocop:disable Metrics/ClassLength
14
14
  OVERFLOW_ATTRIBUTE_SET = { 'otel.metric.overflow' => true }.freeze
15
15
  attr_reader :exemplar_reservoir
16
16
 
@@ -34,6 +34,7 @@ module OpenTelemetry
34
34
  @exemplar_reservoir_storage = {}
35
35
  end
36
36
 
37
+ # Returns the current histogram data points, clearing them for delta temporality.
37
38
  def collect(start_time, end_time, data_points)
38
39
  if @aggregation_temporality.delta?
39
40
  # Set timestamps and 'move' data point values to result.
@@ -60,6 +61,7 @@ module OpenTelemetry
60
61
  end
61
62
  end
62
63
 
64
+ # Records amount into the histogram bucket for the given attributes.
63
65
  def update(amount, attributes, data_points, cardinality_limit, exemplar_offer: false)
64
66
  hdp = if data_points.key?(attributes)
65
67
  data_points[attributes]
@@ -73,6 +75,7 @@ module OpenTelemetry
73
75
  nil
74
76
  end
75
77
 
78
+ # Returns the configured aggregation temporality (:delta or :cumulative).
76
79
  def aggregation_temporality
77
80
  @aggregation_temporality.temporality
78
81
  end
@@ -93,6 +96,7 @@ module OpenTelemetry
93
96
  0, # :sum
94
97
  empty_bucket_counts, # :bucket_counts
95
98
  @boundaries, # :explicit_bounds
99
+ 0, # :flags
96
100
  nil, # :exemplars
97
101
  min, # :min
98
102
  max # :max
@@ -234,6 +234,7 @@ module OpenTelemetry
234
234
  nil
235
235
  end
236
236
 
237
+ # Returns the configured aggregation temporality (:delta or :cumulative).
237
238
  def aggregation_temporality
238
239
  @aggregation_temporality.temporality
239
240
  end
@@ -35,16 +35,19 @@ module OpenTelemetry
35
35
  @counts = tmp
36
36
  end
37
37
 
38
+ # Returns the lower index bound of the populated buckets.
38
39
  def offset
39
40
  @index_start
40
41
  end
41
42
 
43
+ # Returns the bucket counts, rotated so index 0 aligns with #offset.
42
44
  def offset_counts
43
45
  bias = @index_base - @index_start
44
46
  @counts[-bias..] + @counts[0...-bias]
45
47
  end
46
48
  alias counts offset_counts
47
49
 
50
+ # Returns the number of populated buckets, from index_start to index_end.
48
51
  def length
49
52
  return 0 if @counts.empty?
50
53
  return 0 if @index_end == @index_start && counts[0] == 0
@@ -52,6 +55,7 @@ module OpenTelemetry
52
55
  @index_end - @index_start + 1
53
56
  end
54
57
 
58
+ # Returns the count stored at the given absolute bucket index.
55
59
  def get_bucket(key)
56
60
  bias = @index_base - @index_start
57
61
 
@@ -61,6 +65,7 @@ module OpenTelemetry
61
65
  @counts[key]
62
66
  end
63
67
 
68
+ # Halves the bucket resolution amount times, merging adjacent buckets.
64
69
  def downscale(amount)
65
70
  bias = @index_base - @index_start
66
71
 
@@ -101,10 +106,12 @@ module OpenTelemetry
101
106
  @index_base = @index_start
102
107
  end
103
108
 
109
+ # Increments the count at bucket_index by increment.
104
110
  def increment_bucket(bucket_index, increment = 1)
105
111
  @counts[bucket_index] += increment
106
112
  end
107
113
 
114
+ # Returns a copy of these buckets with all counts reset to zero.
108
115
  def copy_empty
109
116
  new_buckets = self.class.new
110
117
  new_buckets.instance_variable_set(:@counts, Array.new(@counts.size, 0))
@@ -19,6 +19,7 @@ module OpenTelemetry
19
19
  @max_normal_lower_boundary_index = IEEE754::MAX_NORMAL_EXPONENT >> -@scale
20
20
  end
21
21
 
22
+ # Returns the bucket index for the given value.
22
23
  def map_to_index(value)
23
24
  return @min_normal_lower_boundary_index if value < IEEE754::MIN_NORMAL_VALUE
24
25
 
@@ -27,6 +28,7 @@ module OpenTelemetry
27
28
  (exponent + correction) >> -@scale
28
29
  end
29
30
 
31
+ # Returns the lowest valid bucket index for this scale.
30
32
  def calculate_min_normal_lower_boundary_index(scale)
31
33
  inds = IEEE754::MIN_NORMAL_EXPONENT >> -scale
32
34
  inds -= 1 if -scale < 2
@@ -25,11 +25,13 @@ module OpenTelemetry
25
25
  MIN_NORMAL_VALUE = Float::MIN
26
26
  MAX_NORMAL_VALUE = Float::MAX
27
27
 
28
+ # Returns the unbiased IEEE 754 exponent of value.
28
29
  def self.get_ieee_754_exponent(value)
29
30
  bits = [value].pack('d').unpack1('Q')
30
31
  ((bits & EXPONENT_MASK) >> MANTISSA_WIDTH) - EXPONENT_BIAS
31
32
  end
32
33
 
34
+ # Returns the IEEE 754 mantissa bits of value.
33
35
  def self.get_ieee_754_mantissa(value)
34
36
  bits = [value].pack('d').unpack1('Q')
35
37
  bits & MANTISSA_MASK
@@ -20,6 +20,7 @@ module OpenTelemetry
20
20
  @max_normal_lower_boundary_index = ((IEEE754::MAX_NORMAL_EXPONENT + 1) << @scale) - 1
21
21
  end
22
22
 
23
+ # Returns the bucket index for the given value.
23
24
  def map_to_index(value)
24
25
  return @min_normal_lower_boundary_index - 1 if value <= IEEE754::MIN_NORMAL_VALUE
25
26
 
@@ -17,6 +17,7 @@ module OpenTelemetry
17
17
  :sum, # Float sum of the values in the population. If count is zero then this field must be zero.
18
18
  :bucket_counts, # optional Array[Integer] field contains the count values of histogram for each bucket.
19
19
  :explicit_bounds, # Array[Float] specifies buckets with explicitly defined bounds for values.
20
+ :flags, # optional Integer flags associated with the data point
20
21
  :exemplars, # optional List of exemplars collected from measurements that were used to form the data point
21
22
  :min, # optional Float min is the minimum value over (start_time, end_time].
22
23
  :max) # optional Float max is the maximum value over (start_time, end_time].
@@ -22,6 +22,7 @@ module OpenTelemetry
22
22
  @exemplar_reservoir_storage = {}
23
23
  end
24
24
 
25
+ # Returns the current data points, clearing them for delta temporality.
25
26
  def collect(start_time, end_time, data_points)
26
27
  ndps = data_points.values.map! do |ndp|
27
28
  ndp.start_time_unix_nano = start_time
@@ -34,6 +35,7 @@ module OpenTelemetry
34
35
  ndps
35
36
  end
36
37
 
38
+ # Replaces the last recorded value for the given attributes.
37
39
  def update(increment, attributes, data_points, cardinality_limit, exemplar_offer: false)
38
40
  # Check if we already have this attribute set
39
41
  ndp = if data_points.key?(attributes)
@@ -56,6 +58,7 @@ module OpenTelemetry
56
58
  nil,
57
59
  nil,
58
60
  0,
61
+ 0,
59
62
  nil
60
63
  )
61
64
  end
@@ -12,6 +12,7 @@ module OpenTelemetry
12
12
  :start_time_unix_nano, # Integer nanoseconds since Epoch
13
13
  :time_unix_nano, # Integer nanoseconds since Epoch
14
14
  :value, # Numeric
15
+ :flags, # optional Integer flags associated with the data point
15
16
  :exemplars) # optional List of exemplars collected from measurements that were used to form the data point
16
17
  end
17
18
  end
@@ -27,6 +27,7 @@ module OpenTelemetry
27
27
  @exemplar_reservoir_storage = {}
28
28
  end
29
29
 
30
+ # Returns the current sum data points, clearing them for delta temporality.
30
31
  def collect(start_time, end_time, data_points)
31
32
  if @aggregation_temporality.delta?
32
33
  # Set timestamps and 'move' data point values to result.
@@ -51,6 +52,7 @@ module OpenTelemetry
51
52
  end
52
53
  end
53
54
 
55
+ # Adds increment to the sum for the given attributes.
54
56
  def update(increment, attributes, data_points, cardinality_limit, exemplar_offer: false)
55
57
  return if @monotonic && increment < 0
56
58
 
@@ -67,10 +69,12 @@ module OpenTelemetry
67
69
  nil
68
70
  end
69
71
 
72
+ # Returns whether the sum is required to be non-decreasing.
70
73
  def monotonic?
71
74
  @monotonic
72
75
  end
73
76
 
77
+ # Returns the configured aggregation temporality (:delta or :cumulative).
74
78
  def aggregation_temporality
75
79
  @aggregation_temporality.temporality
76
80
  end
@@ -83,6 +87,7 @@ module OpenTelemetry
83
87
  nil,
84
88
  nil,
85
89
  0,
90
+ 0,
86
91
  nil
87
92
  )
88
93
  end
@@ -10,6 +10,7 @@ module OpenTelemetry
10
10
  # The ConfiguratorPatch implements a hook to configure the metrics
11
11
  # portion of the SDK.
12
12
  module ConfiguratorPatch
13
+ # Registers a metric reader with the configured meter provider.
13
14
  def add_metric_reader(metric_reader)
14
15
  @metric_readers << metric_reader
15
16
  end
@@ -49,6 +49,7 @@ module OpenTelemetry
49
49
  exemplars
50
50
  end
51
51
 
52
+ # Clears all sampled exemplars from the reservoir.
52
53
  def reset
53
54
  @exemplar_buckets = Array.new(@boundaries.size + 1) { ExemplarBucket.new }
54
55
  end
@@ -11,6 +11,7 @@ module OpenTelemetry
11
11
  # AlwaysOffExemplarFilter makes no measurements eligible for being an Exemplar.
12
12
  # Using this ExemplarFilter is as good as disabling Exemplar feature.
13
13
  class AlwaysOffExemplarFilter < ExemplarFilter
14
+ # Always returns false; no measurement is eligible to become an exemplar.
14
15
  def self.should_sample?(value, timestamp, attributes, context)
15
16
  false
16
17
  end
@@ -10,6 +10,7 @@ module OpenTelemetry
10
10
  module Exemplar
11
11
  # AlwaysOnExemplarFilter makes all measurements eligible for being an Exemplar.
12
12
  class AlwaysOnExemplarFilter < ExemplarFilter
13
+ # Always returns true; every measurement is eligible to become an exemplar.
13
14
  def self.should_sample?(value, timestamp, attributes, context)
14
15
  true
15
16
  end
@@ -10,12 +10,15 @@ module OpenTelemetry
10
10
  module Exemplar
11
11
  # NoopExemplarReservoir
12
12
  class NoopExemplarReservoir < ExemplarReservoir
13
+ # No-op: discards the offered measurement.
13
14
  def offer(value: nil, timestamp: nil, attributes: nil, context: nil); end
14
15
 
16
+ # Always returns an empty exemplar list.
15
17
  def collect(attributes: nil, aggregation_temporality: :delta)
16
18
  []
17
19
  end
18
20
 
21
+ # Returns true; this reservoir never stores exemplars.
19
22
  def noop?
20
23
  true
21
24
  end
@@ -41,11 +41,13 @@ module OpenTelemetry
41
41
  exemplars
42
42
  end
43
43
 
44
+ # Clears all sampled exemplars and the measurement counter.
44
45
  def reset
45
46
  @exemplar_buckets = Array.new(@max_size) { ExemplarBucket.new }
46
47
  @num_measurements_seen = 0
47
48
  end
48
49
 
50
+ # Returns the bucket index to sample into for the current measurement.
49
51
  def find_histogram_bucket
50
52
  @num_measurements_seen < @max_size ? @num_measurements_seen : rand(0..(@num_measurements_seen - 1))
51
53
  end
@@ -11,6 +11,7 @@ module OpenTelemetry
11
11
  # TraceBasedExemplarFilter is an ExemplarFilter which makes measurements recorded
12
12
  # in the context of a sampled parent span eligible for being an Exemplar
13
13
  class TraceBasedExemplarFilter < ExemplarFilter
14
+ # Returns whether the measurement's context has a sampled parent span.
14
15
  def self.should_sample?(value, timestamp, attributes, context)
15
16
  current_span = ::OpenTelemetry::Trace.current_span(context)
16
17
  span_content = current_span.context
@@ -17,10 +17,12 @@ module OpenTelemetry
17
17
  @stopped = false
18
18
  end
19
19
 
20
+ # Collects and exports the current metrics to the console.
20
21
  def pull
21
22
  export(collect)
22
23
  end
23
24
 
25
+ # Prints each collected metric to stdout.
24
26
  def export(metrics, timeout: nil)
25
27
  return FAILURE if @stopped
26
28
 
@@ -29,10 +31,12 @@ module OpenTelemetry
29
31
  SUCCESS
30
32
  end
31
33
 
34
+ # No-op: there is nothing to flush for this exporter.
32
35
  def force_flush(timeout: nil)
33
36
  SUCCESS
34
37
  end
35
38
 
39
+ # Marks this exporter as stopped so subsequent exports fail.
36
40
  def shutdown(timeout: nil)
37
41
  @stopped = true
38
42
  SUCCESS
@@ -19,10 +19,12 @@ module OpenTelemetry
19
19
  @mutex = Mutex.new
20
20
  end
21
21
 
22
+ # Collects and exports the current metrics into #metric_snapshots.
22
23
  def pull
23
24
  export(collect)
24
25
  end
25
26
 
27
+ # Appends the given metrics to #metric_snapshots.
26
28
  def export(metrics, timeout: nil)
27
29
  @mutex.synchronize do
28
30
  @metric_snapshots.concat(Array(metrics))
@@ -30,12 +32,14 @@ module OpenTelemetry
30
32
  SUCCESS
31
33
  end
32
34
 
35
+ # Clears #metric_snapshots.
33
36
  def reset
34
37
  @mutex.synchronize do
35
38
  @metric_snapshots.clear
36
39
  end
37
40
  end
38
41
 
42
+ # No-op: there is nothing to shut down for this exporter.
39
43
  def shutdown
40
44
  SUCCESS
41
45
  end
@@ -18,14 +18,17 @@ module OpenTelemetry
18
18
  @metric_store = OpenTelemetry::SDK::Metrics::State::MetricStore.new(cardinality_limit: aggregation_cardinality_limit)
19
19
  end
20
20
 
21
+ # Collects and returns the current metrics from the metric store.
21
22
  def collect
22
23
  @metric_store.collect
23
24
  end
24
25
 
26
+ # No-op: subclasses should override to release resources.
25
27
  def shutdown(timeout: nil)
26
28
  Export::SUCCESS
27
29
  end
28
30
 
31
+ # No-op: subclasses should override to force an export.
29
32
  def force_flush(timeout: nil)
30
33
  Export::SUCCESS
31
34
  end
@@ -79,6 +79,7 @@ module OpenTelemetry
79
79
  Export::FAILURE
80
80
  end
81
81
 
82
+ # Restarts the periodic export thread after a process fork.
82
83
  def after_fork
83
84
  @exporter.reset if @exporter.respond_to?(:reset)
84
85
  collect # move past previously reported metrics from parent process
@@ -10,6 +10,7 @@ module OpenTelemetry
10
10
  # ForkHooks implements methods to run callbacks before and after forking a Process by overriding Process::_fork
11
11
  # This is used to ensure that the PeriodicMetricReader is restarted after forking
12
12
  module ForkHooks
13
+ # Installs the fork hook on Process, idempotently.
13
14
  def self.attach!
14
15
  return if @fork_hooks_attached
15
16
 
@@ -17,12 +18,14 @@ module OpenTelemetry
17
18
  @fork_hooks_attached = true
18
19
  end
19
20
 
21
+ # Notifies metric readers that a fork just occurred.
20
22
  def self.after_fork
21
23
  ::OpenTelemetry.meter_provider.metric_readers.each do |reader|
22
24
  reader.after_fork if reader.respond_to?(:after_fork)
23
25
  end
24
26
  end
25
27
 
28
+ # Wraps Process._fork to trigger #after_fork in the child process.
26
29
  def _fork
27
30
  parent_pid = Process.pid
28
31
  super.tap do
@@ -73,14 +73,17 @@ module OpenTelemetry
73
73
  end
74
74
  end
75
75
 
76
+ # Removes a previously registered callback.
76
77
  def unregister(callback)
77
78
  @callbacks.delete(callback)
78
79
  end
79
80
 
81
+ # Sets the timeout, in seconds, for invoking callbacks.
80
82
  def timeout(timeout)
81
83
  @timeout = timeout
82
84
  end
83
85
 
86
+ # Merges attributes into those reported alongside observed values.
84
87
  def add_attributes(attributes)
85
88
  @attributes.merge!(attributes) if attributes.instance_of?(Hash)
86
89
  end
@@ -48,6 +48,7 @@ module OpenTelemetry
48
48
  end
49
49
  end
50
50
 
51
+ # Removes callback from the given instruments.
51
52
  def unregister(instruments, callback)
52
53
  instruments.each do |instrument|
53
54
  instrument.unregister(callback)
@@ -61,6 +62,7 @@ module OpenTelemetry
61
62
  end
62
63
  end
63
64
 
65
+ # Validates the given instrument options and creates the instrument of the given kind.
64
66
  def create_instrument(kind, name, unit, description, callback, exemplar_filter, exemplar_reservoir)
65
67
  raise InstrumentNameError if name.nil?
66
68
  raise InstrumentNameError if name.empty?
@@ -81,6 +83,7 @@ module OpenTelemetry
81
83
  end
82
84
  end
83
85
 
86
+ # Returns whether string is valid UTF-8 with no 4-byte (utf8mb4) characters.
84
87
  def utf8mb3_encoding?(string)
85
88
  string.force_encoding('UTF-8').valid_encoding? &&
86
89
  string.each_char { |c| return false if c.bytesize >= 4 }
@@ -136,6 +136,7 @@ module OpenTelemetry
136
136
  end
137
137
  alias register_asynchronous_instrument register_synchronous_instrument
138
138
 
139
+ # Selects the exemplar filter class based on the OTEL_METRICS_EXEMPLAR_FILTER env var.
139
140
  def exemplar_filter_setup
140
141
  case ENV.fetch('OTEL_METRICS_EXEMPLAR_FILTER', nil)
141
142
  when 'always_on'
@@ -49,6 +49,7 @@ module OpenTelemetry
49
49
  super
50
50
  end
51
51
 
52
+ # Invokes each registered callback and records its observed value(s).
52
53
  def invoke_callback(timeout, attributes)
53
54
  if @registered_views.empty?
54
55
 
@@ -21,6 +21,7 @@ module OpenTelemetry
21
21
  @cardinality_limit = cardinality_limit
22
22
  end
23
23
 
24
+ # Collects a snapshot of metric data from all registered metric streams.
24
25
  def collect
25
26
  @mutex.synchronize do
26
27
  @epoch_end_time = OpenTelemetry::Common::Utilities.time_in_nanoseconds
@@ -31,6 +32,7 @@ module OpenTelemetry
31
32
  end
32
33
  end
33
34
 
35
+ # Registers a metric stream so it is included in future collections.
34
36
  def add_metric_stream(metric_stream)
35
37
  @mutex.synchronize do
36
38
  metric_stream.cardinality_limit = @cardinality_limit
@@ -47,6 +47,7 @@ module OpenTelemetry
47
47
  @mutex = Mutex.new
48
48
  end
49
49
 
50
+ # Returns a snapshot of this stream's aggregated metric data.
50
51
  def collect(start_time, end_time)
51
52
  @mutex.synchronize do
52
53
  metric_data = []
@@ -99,6 +100,7 @@ module OpenTelemetry
99
100
  end
100
101
  end
101
102
 
103
+ # Builds a {MetricData} snapshot from the given aggregation and data points.
102
104
  def aggregate_metric_data(start_time, end_time, aggregation: nil, data_points: nil)
103
105
  aggregator = aggregation || @default_aggregation
104
106
  is_monotonic = aggregator.respond_to?(:monotonic?) ? aggregator.monotonic? : nil
@@ -120,12 +122,14 @@ module OpenTelemetry
120
122
  )
121
123
  end
122
124
 
125
+ # Finds and caches views from the meter provider that match this instrument.
123
126
  def find_registered_view
124
127
  return if @meter_provider.nil?
125
128
 
126
129
  @meter_provider.registered_views.each { |view| @registered_views[view] = {} if view.match_instrument?(self) }
127
130
  end
128
131
 
132
+ # Returns whether this stream has no data points to export.
129
133
  def empty_data_point?
130
134
  if @registered_views.empty?
131
135
  @data_points.empty?
@@ -136,11 +140,13 @@ module OpenTelemetry
136
140
  end
137
141
  end
138
142
 
143
+ # Returns the non-negative cardinality limit to use for the given view.
139
144
  def resolve_cardinality_limit(view)
140
145
  cardinality_limit = view&.aggregation_cardinality_limit || @cardinality_limit || DEFAULT_CARDINALITY_LIMIT
141
146
  [cardinality_limit, 0].max # if cardinality_limit is negative, then give it 0
142
147
  end
143
148
 
149
+ # Returns whether the exemplar filter accepts this measurement.
144
150
  def should_offer_exemplar?(value, attributes)
145
151
  return false if @exemplar_reservoir&.noop?
146
152
 
@@ -149,6 +155,7 @@ module OpenTelemetry
149
155
  @exemplar_filter&.should_sample?(value, time, attributes, context)
150
156
  end
151
157
 
158
+ # Returns a human-readable summary of this stream's data points.
152
159
  def to_s
153
160
  instrument_info = +''
154
161
  instrument_info << "name=#{@name}"
@@ -8,7 +8,7 @@ module OpenTelemetry
8
8
  module SDK
9
9
  module Metrics
10
10
  # Current OpenTelemetry metrics sdk version
11
- VERSION = '0.16.0'
11
+ VERSION = '0.17.0'
12
12
  end
13
13
  end
14
14
  end
@@ -22,6 +22,7 @@ module OpenTelemetry
22
22
  generate_regex_pattern(name)
23
23
  end
24
24
 
25
+ # Returns whether this view applies to the given metric stream.
25
26
  def match_instrument?(metric_stream)
26
27
  return false if @name && !name_match(metric_stream.name)
27
28
  return false if @options[:type] && @options[:type] != metric_stream.instrument_kind
@@ -32,10 +33,12 @@ module OpenTelemetry
32
33
  true
33
34
  end
34
35
 
36
+ # Returns whether stream_name matches this view's name pattern.
35
37
  def name_match(stream_name) # rubocop:disable Naming/PredicateMethod
36
38
  !!@regex&.match(stream_name)
37
39
  end
38
40
 
41
+ # Returns whether this view's aggregation is an SDK Aggregation instance.
39
42
  def valid_aggregation?
40
43
  @aggregation.class.name.rpartition('::')[0] == 'OpenTelemetry::SDK::Metrics::Aggregation'
41
44
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentelemetry-metrics-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenTelemetry Authors
@@ -121,10 +121,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby
121
121
  licenses:
122
122
  - Apache-2.0
123
123
  metadata:
124
- changelog_uri: https://rubydoc.info/gems/opentelemetry-metrics-sdk/0.16.0/file/CHANGELOG.md
125
- source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/opentelemetry-metrics-sdk/v0.16.0/metrics_sdk
124
+ changelog_uri: https://rubydoc.info/gems/opentelemetry-metrics-sdk/0.17.0/file/CHANGELOG.md
125
+ source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/opentelemetry-metrics-sdk/v0.17.0/metrics_sdk
126
126
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
127
- documentation_uri: https://rubydoc.info/gems/opentelemetry-metrics-sdk/0.16.0
127
+ documentation_uri: https://rubydoc.info/gems/opentelemetry-metrics-sdk/0.17.0
128
128
  rdoc_options: []
129
129
  require_paths:
130
130
  - lib