opentelemetry-metrics-sdk 0.18.0 → 0.22.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 +23 -0
- data/lib/opentelemetry/sdk/metrics/aggregation/explicit_bucket_histogram.rb +13 -11
- data/lib/opentelemetry/sdk/metrics/aggregation/exponential_bucket_histogram.rb +89 -79
- data/lib/opentelemetry/sdk/metrics/aggregation/last_value.rb +12 -8
- data/lib/opentelemetry/sdk/metrics/aggregation/stream_scoped_storage.rb +26 -0
- data/lib/opentelemetry/sdk/metrics/aggregation/sum.rb +15 -11
- data/lib/opentelemetry/sdk/metrics/aggregation.rb +1 -0
- data/lib/opentelemetry/sdk/metrics/configurator_patch.rb +8 -8
- data/lib/opentelemetry/sdk/metrics/export/console_metric_pull_exporter.rb +1 -1
- data/lib/opentelemetry/sdk/metrics/export/in_memory_metric_pull_exporter.rb +1 -1
- data/lib/opentelemetry/sdk/metrics/export/metric_reader.rb +38 -1
- data/lib/opentelemetry/sdk/metrics/export/periodic_metric_reader.rb +3 -1
- data/lib/opentelemetry/sdk/metrics/fork_hooks.rb +1 -1
- data/lib/opentelemetry/sdk/metrics/instrument/asynchronous_instrument.rb +8 -3
- data/lib/opentelemetry/sdk/metrics/instrument/counter.rb +0 -6
- data/lib/opentelemetry/sdk/metrics/instrument/gauge.rb +0 -6
- data/lib/opentelemetry/sdk/metrics/instrument/histogram.rb +0 -8
- data/lib/opentelemetry/sdk/metrics/instrument/observable_counter.rb +0 -6
- data/lib/opentelemetry/sdk/metrics/instrument/observable_gauge.rb +0 -6
- data/lib/opentelemetry/sdk/metrics/instrument/observable_up_down_counter.rb +0 -6
- data/lib/opentelemetry/sdk/metrics/instrument/synchronous_instrument.rb +5 -2
- data/lib/opentelemetry/sdk/metrics/instrument/up_down_counter.rb +0 -6
- data/lib/opentelemetry/sdk/metrics/meter.rb +88 -23
- data/lib/opentelemetry/sdk/metrics/meter_provider.rb +27 -1
- data/lib/opentelemetry/sdk/metrics/state/asynchronous_metric_stream.rb +4 -2
- data/lib/opentelemetry/sdk/metrics/state/metric_stream.rb +28 -2
- data/lib/opentelemetry/sdk/metrics/version.rb +1 -1
- data/lib/opentelemetry/sdk/metrics.rb +1 -0
- metadata +8 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6eb7640bb97e64464de8e6496fe67028f989313651d9112544f9caa17bd1e3d2
|
|
4
|
+
data.tar.gz: 07ec1f7b6a9af36e6972a6f6a8a8b6561f791318e34b3164dc44e8e4f38206a4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 110b7d06b87b6b6d83267241dd77c835bcdbbe136e97ef7aaa08c43048fa538fea034475ef8cdad5dc99394dc6f086f397338a13592bb23afa58f7fdcafeb417
|
|
7
|
+
data.tar.gz: 8ca110b0164d1cf116e22013a1ebab15c5ad786e7947cdbcca372c9d3a9cb485ae8a4bd98c0d323e377ce2653d06c38cd07d416ce2936939b50d83450e92fc55
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# Release History: opentelemetry-metrics-sdk
|
|
2
2
|
|
|
3
|
+
### v0.22.0 / 2026-10-20
|
|
4
|
+
|
|
5
|
+
* ADDED: Support OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION env var (#2389)
|
|
6
|
+
|
|
7
|
+
### v0.21.0 / 2026-10-13
|
|
8
|
+
|
|
9
|
+
* ADDED: Fix duplicate instrument registration warning (#2417)
|
|
10
|
+
|
|
11
|
+
### v0.20.0 / 2026-10-05
|
|
12
|
+
|
|
13
|
+
* BREAKING CHANGE: Move the global meter provider behind an opt-in require (#2416)
|
|
14
|
+
* ADDED: Move the global meter provider behind an opt-in require (#2416)
|
|
15
|
+
|
|
16
|
+
### v0.19.0 / 2026-09-29
|
|
17
|
+
|
|
18
|
+
* BREAKING CHANGE: Update api for spec compliance (#2309)
|
|
19
|
+
* ADDED: Update api for spec compliance (#2309)
|
|
20
|
+
* ADDED: Move otlp exporter uri builder to common (#2240)
|
|
21
|
+
* FIXED: Scope shared aggregation state to the owning stream (#2300) (#2314)
|
|
22
|
+
* FIXED: Size exponential histogram exemplars (#2392)
|
|
23
|
+
* FIXED: Accept arbitrary instrument metadata (#2395)
|
|
24
|
+
* FIXED: Prevent readers spanning providers (#2393)
|
|
25
|
+
|
|
3
26
|
### v0.18.0 / 2026-09-09
|
|
4
27
|
|
|
5
28
|
* BREAKING CHANGE: Align with the spec for metrics sdk and metrics otlp exporter (#2301)
|
|
@@ -11,6 +11,8 @@ module OpenTelemetry
|
|
|
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
13
|
class ExplicitBucketHistogram # rubocop:disable Metrics/ClassLength
|
|
14
|
+
include StreamScopedStorage
|
|
15
|
+
|
|
14
16
|
OVERFLOW_ATTRIBUTE_SET = { 'otel.metric.overflow' => true }.freeze
|
|
15
17
|
attr_reader :exemplar_reservoir
|
|
16
18
|
|
|
@@ -31,7 +33,7 @@ module OpenTelemetry
|
|
|
31
33
|
@boundaries = boundaries && !boundaries.empty? ? boundaries.sort : nil
|
|
32
34
|
@record_min_max = record_min_max
|
|
33
35
|
@exemplar_reservoir = exemplar_reservoir || Metrics::Exemplar::AlignedHistogramBucketExemplarReservoir.new(boundaries: @boundaries)
|
|
34
|
-
@exemplar_reservoir_storage =
|
|
36
|
+
@exemplar_reservoir_storage = new_stream_storage
|
|
35
37
|
end
|
|
36
38
|
|
|
37
39
|
# Returns the current histogram data points, clearing them for delta temporality.
|
|
@@ -41,8 +43,8 @@ module OpenTelemetry
|
|
|
41
43
|
hdps = data_points.values.map! do |hdp|
|
|
42
44
|
hdp.start_time_unix_nano = start_time
|
|
43
45
|
hdp.time_unix_nano = end_time
|
|
44
|
-
reservoir = @exemplar_reservoir_storage[hdp.attributes]
|
|
45
|
-
hdp.exemplars = reservoir&.collect(attributes: hdp.attributes, aggregation_temporality: @aggregation_temporality)
|
|
46
|
+
reservoir = @exemplar_reservoir_storage[data_points][hdp.attributes]
|
|
47
|
+
hdp.exemplars = reservoir&.collect(attributes: hdp.attributes, aggregation_temporality: @aggregation_temporality.temporality)
|
|
46
48
|
hdp
|
|
47
49
|
end
|
|
48
50
|
data_points.clear
|
|
@@ -52,8 +54,8 @@ module OpenTelemetry
|
|
|
52
54
|
data_points.values.map! do |hdp|
|
|
53
55
|
hdp.start_time_unix_nano ||= start_time # Start time of a data point is from the first observation.
|
|
54
56
|
hdp.time_unix_nano = end_time
|
|
55
|
-
reservoir = @exemplar_reservoir_storage[hdp.attributes]
|
|
56
|
-
hdp.exemplars = reservoir&.collect(attributes: hdp.attributes, aggregation_temporality: @aggregation_temporality)
|
|
57
|
+
reservoir = @exemplar_reservoir_storage[data_points][hdp.attributes]
|
|
58
|
+
hdp.exemplars = reservoir&.collect(attributes: hdp.attributes, aggregation_temporality: @aggregation_temporality.temporality)
|
|
57
59
|
hdp = hdp.dup
|
|
58
60
|
hdp.bucket_counts = hdp.bucket_counts.dup
|
|
59
61
|
hdp
|
|
@@ -71,7 +73,7 @@ module OpenTelemetry
|
|
|
71
73
|
create_new_data_point(attributes, data_points)
|
|
72
74
|
end
|
|
73
75
|
|
|
74
|
-
update_histogram_data_point(hdp, amount, exemplar_offer: exemplar_offer)
|
|
76
|
+
update_histogram_data_point(hdp, amount, data_points, exemplar_offer: exemplar_offer)
|
|
75
77
|
nil
|
|
76
78
|
end
|
|
77
79
|
|
|
@@ -103,8 +105,8 @@ module OpenTelemetry
|
|
|
103
105
|
)
|
|
104
106
|
end
|
|
105
107
|
|
|
106
|
-
def update_histogram_data_point(hdp, amount, exemplar_offer: false)
|
|
107
|
-
reservior_update(hdp.attributes, amount, exemplar_offer)
|
|
108
|
+
def update_histogram_data_point(hdp, amount, stream_key, exemplar_offer: false)
|
|
109
|
+
reservior_update(hdp.attributes, amount, exemplar_offer, stream_key)
|
|
108
110
|
|
|
109
111
|
if @record_min_max
|
|
110
112
|
hdp.max = amount if amount > hdp.max
|
|
@@ -119,12 +121,12 @@ module OpenTelemetry
|
|
|
119
121
|
hdp.bucket_counts[bucket_index] += 1
|
|
120
122
|
end
|
|
121
123
|
|
|
122
|
-
def reservior_update(attributes, amount, exemplar_offer)
|
|
123
|
-
reservoir = @exemplar_reservoir_storage[attributes]
|
|
124
|
+
def reservior_update(attributes, amount, exemplar_offer, stream_key)
|
|
125
|
+
reservoir = @exemplar_reservoir_storage[stream_key][attributes]
|
|
124
126
|
unless reservoir
|
|
125
127
|
reservoir = @exemplar_reservoir.dup
|
|
126
128
|
reservoir.reset
|
|
127
|
-
@exemplar_reservoir_storage[attributes] = reservoir
|
|
129
|
+
@exemplar_reservoir_storage[stream_key][attributes] = reservoir
|
|
128
130
|
end
|
|
129
131
|
|
|
130
132
|
return unless exemplar_offer
|
|
@@ -17,6 +17,8 @@ module OpenTelemetry
|
|
|
17
17
|
module Aggregation
|
|
18
18
|
# Contains the implementation of the {https://opentelemetry.io/docs/specs/otel/metrics/data-model/#exponentialhistogram ExponentialBucketHistogram} aggregation
|
|
19
19
|
class ExponentialBucketHistogram # rubocop:disable Metrics/ClassLength
|
|
20
|
+
include StreamScopedStorage
|
|
21
|
+
|
|
20
22
|
OVERFLOW_ATTRIBUTE_SET = { 'otel.metric.overflow' => true }.freeze
|
|
21
23
|
|
|
22
24
|
# relate to min max scale: https://opentelemetry.io/docs/specs/otel/metrics/sdk/#support-a-minimum-and-maximum-scale
|
|
@@ -29,10 +31,6 @@ module OpenTelemetry
|
|
|
29
31
|
|
|
30
32
|
attr_reader :exemplar_reservoir
|
|
31
33
|
|
|
32
|
-
# if no reservoir pass from instrument, then use this empty reservoir to avoid no method found error
|
|
33
|
-
DEFAULT_RESERVOIR = Metrics::Exemplar::SimpleFixedSizeExemplarReservoir.new
|
|
34
|
-
private_constant :DEFAULT_RESERVOIR
|
|
35
|
-
|
|
36
34
|
# The default boundaries are calculated based on default max_size and max_scale values
|
|
37
35
|
def initialize(
|
|
38
36
|
aggregation_temporality: ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', :delta),
|
|
@@ -53,46 +51,58 @@ module OpenTelemetry
|
|
|
53
51
|
@size = validate_size(max_size)
|
|
54
52
|
@scale = validate_scale(max_scale)
|
|
55
53
|
|
|
56
|
-
@exemplar_reservoir = exemplar_reservoir ||
|
|
57
|
-
@exemplar_reservoir_storage =
|
|
54
|
+
@exemplar_reservoir = exemplar_reservoir || Metrics::Exemplar::SimpleFixedSizeExemplarReservoir.new(max_size: [20, @size].min)
|
|
55
|
+
@exemplar_reservoir_storage = new_stream_storage
|
|
58
56
|
|
|
59
57
|
@mapping = new_mapping(@scale)
|
|
60
58
|
|
|
61
59
|
# Previous state for cumulative aggregation
|
|
62
|
-
@previous_positive =
|
|
63
|
-
@previous_negative =
|
|
64
|
-
@previous_min =
|
|
65
|
-
@previous_max =
|
|
66
|
-
@previous_sum =
|
|
67
|
-
@previous_count =
|
|
68
|
-
@previous_zero_count =
|
|
69
|
-
@previous_scale =
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
@
|
|
73
|
-
@previous_mappings = {}
|
|
60
|
+
@previous_positive = new_stream_storage # nil
|
|
61
|
+
@previous_negative = new_stream_storage # nil
|
|
62
|
+
@previous_min = new_stream_storage # Float::INFINITY
|
|
63
|
+
@previous_max = new_stream_storage # -Float::INFINITY
|
|
64
|
+
@previous_sum = new_stream_storage # 0
|
|
65
|
+
@previous_count = new_stream_storage # 0
|
|
66
|
+
@previous_zero_count = new_stream_storage # 0
|
|
67
|
+
@previous_scale = new_stream_storage # nil
|
|
68
|
+
|
|
69
|
+
@mappings = new_stream_storage
|
|
70
|
+
@previous_mappings = new_stream_storage
|
|
74
71
|
end
|
|
75
72
|
|
|
76
73
|
# when aggregation temporality is cumulative, merge and downscale will happen.
|
|
77
74
|
# rubocop:disable-next Metrics/MethodLength
|
|
78
75
|
def collect(start_time, end_time, data_points)
|
|
76
|
+
stream_key = data_points
|
|
77
|
+
stream_exemplar_reservoir_storage = @exemplar_reservoir_storage[stream_key]
|
|
78
|
+
|
|
79
79
|
if @aggregation_temporality.delta?
|
|
80
80
|
# Set timestamps and 'move' data point values to result.
|
|
81
81
|
hdps = data_points.values.map! do |hdp|
|
|
82
82
|
hdp.start_time_unix_nano = start_time
|
|
83
83
|
hdp.time_unix_nano = end_time
|
|
84
|
-
reservoir =
|
|
85
|
-
hdp.exemplars = reservoir&.collect(attributes: hdp.attributes, aggregation_temporality: @aggregation_temporality)
|
|
84
|
+
reservoir = stream_exemplar_reservoir_storage[hdp.attributes]
|
|
85
|
+
hdp.exemplars = reservoir&.collect(attributes: hdp.attributes, aggregation_temporality: @aggregation_temporality.temporality)
|
|
86
86
|
hdp
|
|
87
87
|
end
|
|
88
88
|
data_points.clear
|
|
89
|
-
@mappings.
|
|
89
|
+
@mappings.delete(stream_key)
|
|
90
90
|
hdps
|
|
91
91
|
else
|
|
92
92
|
# CUMULATIVE temporality - merge current data_points to previous data_points
|
|
93
93
|
# and only keep the merged data_points in @previous_*
|
|
94
94
|
|
|
95
95
|
merged_data_points = {}
|
|
96
|
+
stream_previous_positive = @previous_positive[stream_key]
|
|
97
|
+
stream_previous_negative = @previous_negative[stream_key]
|
|
98
|
+
stream_previous_min = @previous_min[stream_key]
|
|
99
|
+
stream_previous_max = @previous_max[stream_key]
|
|
100
|
+
stream_previous_sum = @previous_sum[stream_key]
|
|
101
|
+
stream_previous_count = @previous_count[stream_key]
|
|
102
|
+
stream_previous_zero_count = @previous_zero_count[stream_key]
|
|
103
|
+
stream_previous_scale = @previous_scale[stream_key]
|
|
104
|
+
stream_mappings = @mappings[stream_key]
|
|
105
|
+
stream_previous_mappings = @previous_mappings[stream_key]
|
|
96
106
|
|
|
97
107
|
# this will slow down the operation especially if large amount of data_points present
|
|
98
108
|
# but it should be fine since with cumulative, the data_points are merged into previous_* and not kept in data_points
|
|
@@ -108,25 +118,25 @@ module OpenTelemetry
|
|
|
108
118
|
current_scale = hdp.scale
|
|
109
119
|
|
|
110
120
|
# Setup previous positive, negative bucket and scale based on three different cases
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
121
|
+
stream_previous_positive[attributes] = current_positive.copy_empty if stream_previous_positive[attributes].nil?
|
|
122
|
+
stream_previous_negative[attributes] = current_negative.copy_empty if stream_previous_negative[attributes].nil?
|
|
123
|
+
stream_previous_scale[attributes] = current_scale if stream_previous_scale[attributes].nil?
|
|
114
124
|
|
|
115
125
|
# Determine minimum scale for merging
|
|
116
|
-
min_scale = [
|
|
126
|
+
min_scale = [stream_previous_scale[attributes], current_scale].min
|
|
117
127
|
|
|
118
128
|
# Calculate ranges for positive and negative buckets
|
|
119
129
|
low_positive, high_positive = get_low_high_previous_current(
|
|
120
|
-
|
|
130
|
+
stream_previous_positive[attributes],
|
|
121
131
|
current_positive,
|
|
122
|
-
|
|
132
|
+
stream_previous_scale[attributes],
|
|
123
133
|
current_scale,
|
|
124
134
|
min_scale
|
|
125
135
|
)
|
|
126
136
|
low_negative, high_negative = get_low_high_previous_current(
|
|
127
|
-
|
|
137
|
+
stream_previous_negative[attributes],
|
|
128
138
|
current_negative,
|
|
129
|
-
|
|
139
|
+
stream_previous_scale[attributes],
|
|
130
140
|
current_scale,
|
|
131
141
|
min_scale
|
|
132
142
|
)
|
|
@@ -138,79 +148,79 @@ module OpenTelemetry
|
|
|
138
148
|
].min
|
|
139
149
|
|
|
140
150
|
# Downscale previous buckets if necessary
|
|
141
|
-
downscale_change =
|
|
142
|
-
downscale(downscale_change,
|
|
151
|
+
downscale_change = stream_previous_scale[attributes] - min_scale
|
|
152
|
+
downscale(downscale_change, stream_previous_positive[attributes], stream_previous_negative[attributes])
|
|
143
153
|
|
|
144
154
|
# Merge current buckets into previous buckets (kind like update); it's always :cumulative
|
|
145
|
-
merge_buckets(
|
|
146
|
-
merge_buckets(
|
|
155
|
+
merge_buckets(stream_previous_positive[attributes], current_positive, current_scale, min_scale, @aggregation_temporality)
|
|
156
|
+
merge_buckets(stream_previous_negative[attributes], current_negative, current_scale, min_scale, @aggregation_temporality)
|
|
147
157
|
|
|
148
158
|
# initialize min, max, sum, count, zero_count for first time
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
159
|
+
stream_previous_min[attributes] = Float::INFINITY if stream_previous_min[attributes].nil?
|
|
160
|
+
stream_previous_max[attributes] = -Float::INFINITY if stream_previous_max[attributes].nil?
|
|
161
|
+
stream_previous_sum[attributes] = 0 if stream_previous_sum[attributes].nil?
|
|
162
|
+
stream_previous_count[attributes] = 0 if stream_previous_count[attributes].nil?
|
|
163
|
+
stream_previous_zero_count[attributes] = 0 if stream_previous_zero_count[attributes].nil?
|
|
154
164
|
|
|
155
165
|
# Update aggregated values
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
166
|
+
stream_previous_min[attributes] = [stream_previous_min[attributes], current_min].min
|
|
167
|
+
stream_previous_max[attributes] = [stream_previous_max[attributes], current_max].max
|
|
168
|
+
stream_previous_sum[attributes] += current_sum
|
|
169
|
+
stream_previous_count[attributes] += current_count
|
|
170
|
+
stream_previous_zero_count[attributes] += current_zero_count
|
|
171
|
+
stream_previous_scale[attributes] = min_scale
|
|
162
172
|
|
|
163
173
|
# Create merged data point
|
|
164
|
-
reservoir =
|
|
174
|
+
reservoir = stream_exemplar_reservoir_storage[attributes]
|
|
165
175
|
merged_hdp = ExponentialHistogramDataPoint.new(
|
|
166
176
|
attributes,
|
|
167
177
|
start_time,
|
|
168
178
|
end_time,
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
179
|
+
stream_previous_count[attributes],
|
|
180
|
+
stream_previous_sum[attributes],
|
|
181
|
+
stream_previous_scale[attributes],
|
|
182
|
+
stream_previous_zero_count[attributes],
|
|
183
|
+
stream_previous_positive[attributes].dup,
|
|
184
|
+
stream_previous_negative[attributes].dup,
|
|
175
185
|
0, # flags
|
|
176
|
-
reservoir&.collect(attributes: attributes, aggregation_temporality: @aggregation_temporality), # exemplars
|
|
177
|
-
|
|
178
|
-
|
|
186
|
+
reservoir&.collect(attributes: attributes, aggregation_temporality: @aggregation_temporality.temporality), # exemplars
|
|
187
|
+
stream_previous_min[attributes],
|
|
188
|
+
stream_previous_max[attributes],
|
|
179
189
|
@zero_threshold
|
|
180
190
|
)
|
|
181
191
|
|
|
182
192
|
merged_data_points[attributes] = merged_hdp
|
|
183
|
-
|
|
193
|
+
stream_previous_mappings[attributes] = stream_mappings[attributes] if stream_mappings[attributes] # Preserve mapping for next collection
|
|
184
194
|
end
|
|
185
195
|
|
|
186
196
|
# when you have no local_data_points, the loop from cumulative aggregation will not run
|
|
187
197
|
# so return last merged data points if exists
|
|
188
|
-
if data_points.empty? &&
|
|
189
|
-
|
|
190
|
-
reservoir =
|
|
198
|
+
if data_points.empty? && !stream_previous_positive.empty?
|
|
199
|
+
stream_previous_positive.each_key do |attributes|
|
|
200
|
+
reservoir = stream_exemplar_reservoir_storage[attributes]
|
|
191
201
|
merged_hdp = ExponentialHistogramDataPoint.new(
|
|
192
202
|
attributes,
|
|
193
203
|
start_time,
|
|
194
204
|
end_time,
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
205
|
+
stream_previous_count[attributes],
|
|
206
|
+
stream_previous_sum[attributes],
|
|
207
|
+
stream_previous_scale[attributes],
|
|
208
|
+
stream_previous_zero_count[attributes],
|
|
209
|
+
stream_previous_positive[attributes].dup,
|
|
210
|
+
stream_previous_negative[attributes].dup,
|
|
201
211
|
0, # flags
|
|
202
|
-
reservoir&.collect(attributes: attributes, aggregation_temporality: @aggregation_temporality), # exemplars
|
|
203
|
-
|
|
204
|
-
|
|
212
|
+
reservoir&.collect(attributes: attributes, aggregation_temporality: @aggregation_temporality.temporality), # exemplars
|
|
213
|
+
stream_previous_min[attributes],
|
|
214
|
+
stream_previous_max[attributes],
|
|
205
215
|
@zero_threshold
|
|
206
216
|
)
|
|
207
217
|
merged_data_points[attributes] = merged_hdp
|
|
208
218
|
end
|
|
209
219
|
end
|
|
210
220
|
|
|
211
|
-
# Swap current with previous mappings for next cycle
|
|
212
|
-
@mappings =
|
|
213
|
-
@previous_mappings = {}
|
|
221
|
+
# Swap current with previous mappings for next cycle, for this stream only
|
|
222
|
+
@mappings[stream_key] = stream_previous_mappings
|
|
223
|
+
@previous_mappings[stream_key] = {}
|
|
214
224
|
|
|
215
225
|
# clear data_points since the data is merged into previous_* already;
|
|
216
226
|
# otherwise we will have duplicated data_points in the next collect
|
|
@@ -229,7 +239,7 @@ module OpenTelemetry
|
|
|
229
239
|
create_new_data_point(attributes, data_points)
|
|
230
240
|
end
|
|
231
241
|
|
|
232
|
-
update_histogram_data_point(hdp, attributes, amount, exemplar_offer: exemplar_offer)
|
|
242
|
+
update_histogram_data_point(hdp, attributes, amount, data_points, exemplar_offer: exemplar_offer)
|
|
233
243
|
nil
|
|
234
244
|
end
|
|
235
245
|
|
|
@@ -265,8 +275,8 @@ module OpenTelemetry
|
|
|
265
275
|
end
|
|
266
276
|
|
|
267
277
|
# rubocop:disable-next Metrics/CyclomaticComplexity,Metrics/MethodLength
|
|
268
|
-
def update_histogram_data_point(hdp, attributes, amount, exemplar_offer: false)
|
|
269
|
-
reservior_update(attributes, amount, exemplar_offer)
|
|
278
|
+
def update_histogram_data_point(hdp, attributes, amount, stream_key, exemplar_offer: false)
|
|
279
|
+
reservior_update(attributes, amount, exemplar_offer, stream_key)
|
|
270
280
|
|
|
271
281
|
if @record_min_max
|
|
272
282
|
hdp.max = amount if amount > hdp.max
|
|
@@ -289,11 +299,11 @@ module OpenTelemetry
|
|
|
289
299
|
# Reset scale to max_scale if transitioning from all-zeros to first non-zero value
|
|
290
300
|
if buckets.counts == [0] && hdp.scale == 0 && hdp.count > hdp.zero_count
|
|
291
301
|
hdp.scale = @scale
|
|
292
|
-
@mappings.delete(attributes) # Clear any cached mapping
|
|
302
|
+
@mappings[stream_key].delete(attributes) # Clear any cached mapping
|
|
293
303
|
end
|
|
294
304
|
|
|
295
305
|
# Get or create mapping for this attribute set
|
|
296
|
-
mapping = @mappings[attributes] ||= new_mapping(hdp.scale)
|
|
306
|
+
mapping = @mappings[stream_key][attributes] ||= new_mapping(hdp.scale)
|
|
297
307
|
bucket_index = mapping.map_to_index(amount)
|
|
298
308
|
|
|
299
309
|
rescaling_needed = false
|
|
@@ -320,7 +330,7 @@ module OpenTelemetry
|
|
|
320
330
|
downscale(scale_change, hdp.positive, hdp.negative)
|
|
321
331
|
new_scale = mapping.scale - scale_change
|
|
322
332
|
mapping = new_mapping(new_scale)
|
|
323
|
-
@mappings[attributes] = mapping # Update cache
|
|
333
|
+
@mappings[stream_key][attributes] = mapping # Update cache
|
|
324
334
|
bucket_index = mapping.map_to_index(amount)
|
|
325
335
|
|
|
326
336
|
OpenTelemetry.logger.debug "Rescaled with new scale #{new_scale} from #{low} and #{high}; bucket_index is updated to #{bucket_index}"
|
|
@@ -352,12 +362,12 @@ module OpenTelemetry
|
|
|
352
362
|
buckets.grow(span + 1, @size)
|
|
353
363
|
end
|
|
354
364
|
|
|
355
|
-
def reservior_update(attributes, amount, exemplar_offer)
|
|
356
|
-
reservoir = @exemplar_reservoir_storage[attributes]
|
|
365
|
+
def reservior_update(attributes, amount, exemplar_offer, stream_key)
|
|
366
|
+
reservoir = @exemplar_reservoir_storage[stream_key][attributes]
|
|
357
367
|
unless reservoir
|
|
358
368
|
reservoir = @exemplar_reservoir.dup
|
|
359
369
|
reservoir.reset
|
|
360
|
-
@exemplar_reservoir_storage[attributes] = reservoir
|
|
370
|
+
@exemplar_reservoir_storage[stream_key][attributes] = reservoir
|
|
361
371
|
end
|
|
362
372
|
|
|
363
373
|
return unless exemplar_offer
|
|
@@ -10,6 +10,8 @@ module OpenTelemetry
|
|
|
10
10
|
module Aggregation
|
|
11
11
|
# Contains the implementation of the LastValue aggregation
|
|
12
12
|
class LastValue
|
|
13
|
+
include StreamScopedStorage
|
|
14
|
+
|
|
13
15
|
OVERFLOW_ATTRIBUTE_SET = { 'otel.metric.overflow' => true }.freeze
|
|
14
16
|
attr_reader :exemplar_reservoir
|
|
15
17
|
|
|
@@ -19,15 +21,17 @@ module OpenTelemetry
|
|
|
19
21
|
|
|
20
22
|
def initialize(exemplar_reservoir: nil)
|
|
21
23
|
@exemplar_reservoir = exemplar_reservoir || DEFAULT_RESERVOIR
|
|
22
|
-
@exemplar_reservoir_storage =
|
|
24
|
+
@exemplar_reservoir_storage = new_stream_storage
|
|
23
25
|
end
|
|
24
26
|
|
|
25
27
|
# Returns the current data points, clearing them for delta temporality.
|
|
26
28
|
def collect(start_time, end_time, data_points)
|
|
29
|
+
stream_exemplar_reservoir_storage = @exemplar_reservoir_storage[data_points]
|
|
30
|
+
|
|
27
31
|
ndps = data_points.values.map! do |ndp|
|
|
28
32
|
ndp.start_time_unix_nano = start_time
|
|
29
33
|
ndp.time_unix_nano = end_time
|
|
30
|
-
reservoir =
|
|
34
|
+
reservoir = stream_exemplar_reservoir_storage[ndp.attributes]
|
|
31
35
|
ndp.exemplars = reservoir&.collect(attributes: ndp.attributes, aggregation_temporality: :delta)
|
|
32
36
|
ndp
|
|
33
37
|
end
|
|
@@ -46,7 +50,7 @@ module OpenTelemetry
|
|
|
46
50
|
create_new_data_point(attributes, data_points)
|
|
47
51
|
end
|
|
48
52
|
|
|
49
|
-
update_number_data_point(ndp, increment, exemplar_offer: exemplar_offer)
|
|
53
|
+
update_number_data_point(ndp, increment, data_points, exemplar_offer: exemplar_offer)
|
|
50
54
|
nil
|
|
51
55
|
end
|
|
52
56
|
|
|
@@ -63,17 +67,17 @@ module OpenTelemetry
|
|
|
63
67
|
)
|
|
64
68
|
end
|
|
65
69
|
|
|
66
|
-
def update_number_data_point(ndp, increment, exemplar_offer: false)
|
|
70
|
+
def update_number_data_point(ndp, increment, stream_key, exemplar_offer: false)
|
|
67
71
|
ndp.value = increment
|
|
68
|
-
reservior_update(ndp.attributes, increment, exemplar_offer)
|
|
72
|
+
reservior_update(ndp.attributes, increment, exemplar_offer, stream_key)
|
|
69
73
|
end
|
|
70
74
|
|
|
71
|
-
def reservior_update(attributes, increment, exemplar_offer)
|
|
72
|
-
reservoir = @exemplar_reservoir_storage[attributes]
|
|
75
|
+
def reservior_update(attributes, increment, exemplar_offer, stream_key)
|
|
76
|
+
reservoir = @exemplar_reservoir_storage[stream_key][attributes]
|
|
73
77
|
unless reservoir
|
|
74
78
|
reservoir = @exemplar_reservoir.dup
|
|
75
79
|
reservoir.reset
|
|
76
|
-
@exemplar_reservoir_storage[attributes] = reservoir
|
|
80
|
+
@exemplar_reservoir_storage[stream_key][attributes] = reservoir
|
|
77
81
|
end
|
|
78
82
|
|
|
79
83
|
return unless exemplar_offer
|
|
@@ -0,0 +1,26 @@
|
|
|
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 Metrics
|
|
10
|
+
module Aggregation
|
|
11
|
+
# Builds the nested storage aggregations use to keep per-stream state
|
|
12
|
+
# apart, since a wildcard or regex view shares one aggregation instance
|
|
13
|
+
# across every stream it matches.
|
|
14
|
+
module StreamScopedStorage
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
# Streams are keyed by their +data_points+ hash, which is mutable, so
|
|
18
|
+
# the outer hash must compare by identity rather than by value.
|
|
19
|
+
def new_stream_storage
|
|
20
|
+
Hash.new { |h, k| h[k] = {} }.compare_by_identity
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -10,6 +10,8 @@ module OpenTelemetry
|
|
|
10
10
|
module Aggregation
|
|
11
11
|
# Contains the implementation of the Sum aggregation
|
|
12
12
|
class Sum
|
|
13
|
+
include StreamScopedStorage
|
|
14
|
+
|
|
13
15
|
OVERFLOW_ATTRIBUTE_SET = { 'otel.metric.overflow' => true }.freeze
|
|
14
16
|
attr_reader :exemplar_reservoir
|
|
15
17
|
|
|
@@ -24,18 +26,20 @@ module OpenTelemetry
|
|
|
24
26
|
@aggregation_temporality = AggregationTemporality.determine_temporality(aggregation_temporality: aggregation_temporality, instrument_kind: instrument_kind, default: :cumulative)
|
|
25
27
|
@monotonic = monotonic
|
|
26
28
|
@exemplar_reservoir = exemplar_reservoir || DEFAULT_RESERVOIR
|
|
27
|
-
@exemplar_reservoir_storage =
|
|
29
|
+
@exemplar_reservoir_storage = new_stream_storage
|
|
28
30
|
end
|
|
29
31
|
|
|
30
32
|
# Returns the current sum data points, clearing them for delta temporality.
|
|
31
33
|
def collect(start_time, end_time, data_points)
|
|
34
|
+
stream_exemplar_reservoir_storage = @exemplar_reservoir_storage[data_points]
|
|
35
|
+
|
|
32
36
|
if @aggregation_temporality.delta?
|
|
33
37
|
# Set timestamps and 'move' data point values to result.
|
|
34
38
|
ndps = data_points.values.map! do |ndp|
|
|
35
39
|
ndp.start_time_unix_nano = start_time
|
|
36
40
|
ndp.time_unix_nano = end_time
|
|
37
|
-
reservoir =
|
|
38
|
-
ndp.exemplars = reservoir&.collect(attributes: ndp.attributes, aggregation_temporality: @aggregation_temporality)
|
|
41
|
+
reservoir = stream_exemplar_reservoir_storage[ndp.attributes]
|
|
42
|
+
ndp.exemplars = reservoir&.collect(attributes: ndp.attributes, aggregation_temporality: @aggregation_temporality.temporality)
|
|
39
43
|
ndp
|
|
40
44
|
end
|
|
41
45
|
data_points.clear
|
|
@@ -45,8 +49,8 @@ module OpenTelemetry
|
|
|
45
49
|
data_points.values.map! do |ndp|
|
|
46
50
|
ndp.start_time_unix_nano ||= start_time # Start time of a data point is from the first observation.
|
|
47
51
|
ndp.time_unix_nano = end_time
|
|
48
|
-
reservoir =
|
|
49
|
-
ndp.exemplars = reservoir&.collect(attributes: ndp.attributes, aggregation_temporality: @aggregation_temporality)
|
|
52
|
+
reservoir = stream_exemplar_reservoir_storage[ndp.attributes]
|
|
53
|
+
ndp.exemplars = reservoir&.collect(attributes: ndp.attributes, aggregation_temporality: @aggregation_temporality.temporality)
|
|
50
54
|
ndp.dup
|
|
51
55
|
end
|
|
52
56
|
end
|
|
@@ -65,7 +69,7 @@ module OpenTelemetry
|
|
|
65
69
|
create_new_data_point(attributes, data_points)
|
|
66
70
|
end
|
|
67
71
|
|
|
68
|
-
update_number_data_point(ndp, increment, exemplar_offer: exemplar_offer)
|
|
72
|
+
update_number_data_point(ndp, increment, data_points, exemplar_offer: exemplar_offer)
|
|
69
73
|
nil
|
|
70
74
|
end
|
|
71
75
|
|
|
@@ -92,17 +96,17 @@ module OpenTelemetry
|
|
|
92
96
|
)
|
|
93
97
|
end
|
|
94
98
|
|
|
95
|
-
def update_number_data_point(ndp, increment, exemplar_offer: false)
|
|
96
|
-
reservior_update(ndp.attributes, increment, exemplar_offer)
|
|
99
|
+
def update_number_data_point(ndp, increment, stream_key, exemplar_offer: false)
|
|
100
|
+
reservior_update(ndp.attributes, increment, exemplar_offer, stream_key)
|
|
97
101
|
ndp.value += increment
|
|
98
102
|
end
|
|
99
103
|
|
|
100
|
-
def reservior_update(attributes, increment, exemplar_offer)
|
|
101
|
-
reservoir = @exemplar_reservoir_storage[attributes]
|
|
104
|
+
def reservior_update(attributes, increment, exemplar_offer, stream_key)
|
|
105
|
+
reservoir = @exemplar_reservoir_storage[stream_key][attributes]
|
|
102
106
|
unless reservoir
|
|
103
107
|
reservoir = @exemplar_reservoir.dup
|
|
104
108
|
reservoir.reset
|
|
105
|
-
@exemplar_reservoir_storage[attributes] = reservoir
|
|
109
|
+
@exemplar_reservoir_storage[stream_key][attributes] = reservoir
|
|
106
110
|
end
|
|
107
111
|
|
|
108
112
|
return unless exemplar_offer
|
|
@@ -16,6 +16,7 @@ module OpenTelemetry
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
require 'opentelemetry/sdk/metrics/aggregation/aggregation_temporality'
|
|
19
|
+
require 'opentelemetry/sdk/metrics/aggregation/stream_scoped_storage'
|
|
19
20
|
require 'opentelemetry/sdk/metrics/aggregation/number_data_point'
|
|
20
21
|
require 'opentelemetry/sdk/metrics/aggregation/histogram_data_point'
|
|
21
22
|
require 'opentelemetry/sdk/metrics/aggregation/explicit_bucket_histogram'
|
|
@@ -24,14 +24,14 @@ module OpenTelemetry
|
|
|
24
24
|
|
|
25
25
|
# The metrics_configuration_hook method is where we define the setup process for the metrics SDK.
|
|
26
26
|
def metrics_configuration_hook
|
|
27
|
-
OpenTelemetry.meter_provider = Metrics::MeterProvider.new(resource: @resource)
|
|
27
|
+
OpenTelemetry::Internal.meter_provider = Metrics::MeterProvider.new(resource: @resource)
|
|
28
28
|
configure_metric_readers
|
|
29
29
|
attach_fork_hooks!
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def configure_metric_readers
|
|
33
33
|
readers = @metric_readers.empty? ? wrapped_metric_exporters_from_env.compact : @metric_readers
|
|
34
|
-
readers.each { |r| OpenTelemetry.meter_provider.add_metric_reader(r) }
|
|
34
|
+
readers.each { |r| OpenTelemetry::Internal.meter_provider.add_metric_reader(r) }
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
def wrapped_metric_exporters_from_env
|
|
@@ -41,14 +41,14 @@ module OpenTelemetry
|
|
|
41
41
|
when 'none' then nil
|
|
42
42
|
when 'console'
|
|
43
43
|
default_console_interval = ENV['OTEL_METRIC_EXPORT_INTERVAL'] || 10_000
|
|
44
|
-
OpenTelemetry.meter_provider.add_metric_reader(Metrics::Export::PeriodicMetricReader.new(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
when 'in-memory' then OpenTelemetry.meter_provider.add_metric_reader(Metrics::Export::InMemoryMetricPullExporter.new)
|
|
44
|
+
OpenTelemetry::Internal.meter_provider.add_metric_reader(Metrics::Export::PeriodicMetricReader.new(
|
|
45
|
+
export_interval_millis: Float(default_console_interval),
|
|
46
|
+
exporter: Metrics::Export::ConsoleMetricPullExporter.new
|
|
47
|
+
))
|
|
48
|
+
when 'in-memory' then OpenTelemetry::Internal.meter_provider.add_metric_reader(Metrics::Export::InMemoryMetricPullExporter.new)
|
|
49
49
|
when 'otlp'
|
|
50
50
|
begin
|
|
51
|
-
OpenTelemetry.meter_provider.add_metric_reader(Metrics::Export::PeriodicMetricReader.new(exporter: OpenTelemetry::Exporter::OTLP::Metrics::MetricsExporter.new))
|
|
51
|
+
OpenTelemetry::Internal.meter_provider.add_metric_reader(Metrics::Export::PeriodicMetricReader.new(exporter: OpenTelemetry::Exporter::OTLP::Metrics::MetricsExporter.new))
|
|
52
52
|
rescue NameError
|
|
53
53
|
OpenTelemetry.logger.warn 'The otlp metrics exporter cannot be configured - please add opentelemetry-exporter-otlp-metrics to your Gemfile, metrics will not be exported'
|
|
54
54
|
nil
|
|
@@ -12,7 +12,7 @@ module OpenTelemetry
|
|
|
12
12
|
#
|
|
13
13
|
# Potentially useful for exploratory purposes.
|
|
14
14
|
class ConsoleMetricPullExporter < MetricReader
|
|
15
|
-
def initialize(aggregation_cardinality_limit: nil)
|
|
15
|
+
def initialize(aggregation_cardinality_limit: nil, default_aggregation: nil)
|
|
16
16
|
super
|
|
17
17
|
@stopped = false
|
|
18
18
|
end
|
|
@@ -13,7 +13,7 @@ module OpenTelemetry
|
|
|
13
13
|
class InMemoryMetricPullExporter < MetricReader
|
|
14
14
|
attr_reader :metric_snapshots
|
|
15
15
|
|
|
16
|
-
def initialize(aggregation_cardinality_limit: nil)
|
|
16
|
+
def initialize(aggregation_cardinality_limit: nil, default_aggregation: nil)
|
|
17
17
|
super
|
|
18
18
|
@metric_snapshots = []
|
|
19
19
|
@mutex = Mutex.new
|
|
@@ -12,12 +12,49 @@ module OpenTelemetry
|
|
|
12
12
|
# It is not required to subclass this class to provide an implementation
|
|
13
13
|
# of MetricReader, provided the interface is satisfied.
|
|
14
14
|
class MetricReader
|
|
15
|
+
# Raised when a reader is registered with a second MeterProvider.
|
|
16
|
+
SINGLE_PROVIDER_ERROR = 'MetricReader cannot be registered with more than one MeterProvider'
|
|
17
|
+
|
|
18
|
+
private_constant :SINGLE_PROVIDER_ERROR
|
|
19
|
+
|
|
20
|
+
# The default aggregation for each instrument kind, as defined by the
|
|
21
|
+
# metrics SDK specification.
|
|
22
|
+
# https://opentelemetry.io/docs/specs/otel/metrics/sdk/#default-aggregation
|
|
23
|
+
DEFAULT_AGGREGATION = {
|
|
24
|
+
counter: OpenTelemetry::SDK::Metrics::Aggregation::Sum,
|
|
25
|
+
up_down_counter: OpenTelemetry::SDK::Metrics::Aggregation::Sum,
|
|
26
|
+
observable_counter: OpenTelemetry::SDK::Metrics::Aggregation::Sum,
|
|
27
|
+
observable_up_down_counter: OpenTelemetry::SDK::Metrics::Aggregation::Sum,
|
|
28
|
+
gauge: OpenTelemetry::SDK::Metrics::Aggregation::LastValue,
|
|
29
|
+
observable_gauge: OpenTelemetry::SDK::Metrics::Aggregation::LastValue,
|
|
30
|
+
histogram: OpenTelemetry::SDK::Metrics::Aggregation::ExplicitBucketHistogram
|
|
31
|
+
}.freeze
|
|
32
|
+
|
|
15
33
|
attr_reader :metric_store
|
|
16
34
|
|
|
17
|
-
|
|
35
|
+
# @return [Hash{Symbol => Class}] the aggregation class to use for each
|
|
36
|
+
# instrument kind, resolved once at construction.
|
|
37
|
+
attr_reader :default_aggregation
|
|
38
|
+
|
|
39
|
+
# @param [optional Integer] aggregation_cardinality_limit the maximum number of
|
|
40
|
+
# data points to keep per metric stream.
|
|
41
|
+
# @param [optional Hash{Symbol => Class}] default_aggregation aggregation classes
|
|
42
|
+
# keyed by instrument kind, applied on top of {DEFAULT_AGGREGATION}.
|
|
43
|
+
def initialize(aggregation_cardinality_limit: nil, default_aggregation: nil)
|
|
44
|
+
@mutex = Mutex.new
|
|
45
|
+
@default_aggregation = DEFAULT_AGGREGATION.merge(default_aggregation || {})
|
|
18
46
|
@metric_store = OpenTelemetry::SDK::Metrics::State::MetricStore.new(cardinality_limit: aggregation_cardinality_limit)
|
|
19
47
|
end
|
|
20
48
|
|
|
49
|
+
# Registers this reader with a MeterProvider.
|
|
50
|
+
def register_meter_provider(meter_provider)
|
|
51
|
+
@mutex.synchronize do
|
|
52
|
+
raise ArgumentError, SINGLE_PROVIDER_ERROR if @meter_provider && !@meter_provider.equal?(meter_provider)
|
|
53
|
+
|
|
54
|
+
@meter_provider = meter_provider
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
21
58
|
# Collects and returns the current metrics from the metric store.
|
|
22
59
|
def collect
|
|
23
60
|
@metric_store.collect
|
|
@@ -26,7 +26,9 @@ module OpenTelemetry
|
|
|
26
26
|
export_timeout_millis: Float(ENV.fetch('OTEL_METRIC_EXPORT_TIMEOUT', 30_000)),
|
|
27
27
|
exporter: nil,
|
|
28
28
|
aggregation_cardinality_limit: nil)
|
|
29
|
-
|
|
29
|
+
# The exporter knows what the destination prefers, so this reader defers to it.
|
|
30
|
+
super(aggregation_cardinality_limit: aggregation_cardinality_limit,
|
|
31
|
+
default_aggregation: (exporter.default_aggregation if exporter.respond_to?(:default_aggregation)))
|
|
30
32
|
|
|
31
33
|
@export_interval = export_interval_millis / 1000.0
|
|
32
34
|
@export_timeout = export_timeout_millis / 1000.0
|
|
@@ -20,7 +20,7 @@ module OpenTelemetry
|
|
|
20
20
|
|
|
21
21
|
# Notifies metric readers that a fork just occurred.
|
|
22
22
|
def self.after_fork
|
|
23
|
-
::OpenTelemetry.meter_provider.metric_readers.each do |reader|
|
|
23
|
+
::OpenTelemetry::Internal.meter_provider.metric_readers.each do |reader|
|
|
24
24
|
reader.after_fork if reader.respond_to?(:after_fork)
|
|
25
25
|
end
|
|
26
26
|
end
|
|
@@ -13,6 +13,8 @@ module OpenTelemetry
|
|
|
13
13
|
class AsynchronousInstrument
|
|
14
14
|
NOOP_EXEMPLAR_RESERVOIR = Exemplar::NoopExemplarReservoir.new
|
|
15
15
|
|
|
16
|
+
attr_reader :exemplar_reservoir
|
|
17
|
+
|
|
16
18
|
def initialize(name, unit, description, callback, instrumentation_scope, meter_provider, exemplar_filter, exemplar_reservoir)
|
|
17
19
|
@name = name
|
|
18
20
|
@unit = unit
|
|
@@ -31,7 +33,7 @@ module OpenTelemetry
|
|
|
31
33
|
end
|
|
32
34
|
|
|
33
35
|
# @api private
|
|
34
|
-
def register_with_new_metric_store(metric_store, aggregation: default_aggregation)
|
|
36
|
+
def register_with_new_metric_store(metric_store, aggregation: nil, default_aggregation: nil)
|
|
35
37
|
ms = OpenTelemetry::SDK::Metrics::State::AsynchronousMetricStream.new(
|
|
36
38
|
@name,
|
|
37
39
|
@description,
|
|
@@ -44,7 +46,8 @@ module OpenTelemetry
|
|
|
44
46
|
@timeout,
|
|
45
47
|
@attributes,
|
|
46
48
|
@exemplar_filter,
|
|
47
|
-
@exemplar_reservoir
|
|
49
|
+
@exemplar_reservoir,
|
|
50
|
+
default_aggregation: default_aggregation
|
|
48
51
|
)
|
|
49
52
|
@metric_streams << ms
|
|
50
53
|
metric_store.add_metric_stream(ms)
|
|
@@ -53,7 +56,9 @@ module OpenTelemetry
|
|
|
53
56
|
# The API MUST support creation of asynchronous instruments by passing zero or more callback functions
|
|
54
57
|
# to be permanently registered to the newly created instrument.
|
|
55
58
|
def init_callback(callback)
|
|
56
|
-
if callback.
|
|
59
|
+
if callback.nil?
|
|
60
|
+
nil # zero callbacks permanently registered at creation is permitted
|
|
61
|
+
elsif callback.instance_of?(Proc)
|
|
57
62
|
@callbacks << callback
|
|
58
63
|
elsif callback.instance_of?(Array)
|
|
59
64
|
callback.each { |cb| @callbacks << cb if cb.instance_of?(Proc) }
|
|
@@ -38,12 +38,6 @@ module OpenTelemetry
|
|
|
38
38
|
OpenTelemetry.handle_error(exception: e)
|
|
39
39
|
nil
|
|
40
40
|
end
|
|
41
|
-
|
|
42
|
-
private
|
|
43
|
-
|
|
44
|
-
def default_aggregation
|
|
45
|
-
OpenTelemetry::SDK::Metrics::Aggregation::Sum.new(exemplar_reservoir: @exemplar_reservoir, monotonic: true)
|
|
46
|
-
end
|
|
47
41
|
end
|
|
48
42
|
end
|
|
49
43
|
end
|
|
@@ -31,14 +31,6 @@ module OpenTelemetry
|
|
|
31
31
|
OpenTelemetry.handle_error(exception: e)
|
|
32
32
|
nil
|
|
33
33
|
end
|
|
34
|
-
|
|
35
|
-
private
|
|
36
|
-
|
|
37
|
-
def default_aggregation
|
|
38
|
-
# TODO: at this point, histogram always take the default DEFAULT_BOUNDARIES. In future, the histogram should be able to
|
|
39
|
-
# define the custom boundaries so for exemplar_reservoir can also takes the bounaries as parameter
|
|
40
|
-
OpenTelemetry::SDK::Metrics::Aggregation::ExplicitBucketHistogram.new(exemplar_reservoir: @exemplar_reservoir)
|
|
41
|
-
end
|
|
42
34
|
end
|
|
43
35
|
end
|
|
44
36
|
end
|
|
@@ -28,12 +28,6 @@ module OpenTelemetry
|
|
|
28
28
|
def observe(timeout: nil, attributes: {})
|
|
29
29
|
update(timeout, attributes)
|
|
30
30
|
end
|
|
31
|
-
|
|
32
|
-
private
|
|
33
|
-
|
|
34
|
-
def default_aggregation
|
|
35
|
-
OpenTelemetry::SDK::Metrics::Aggregation::Sum.new(exemplar_reservoir: @exemplar_reservoir, monotonic: true, instrument_kind: instrument_kind)
|
|
36
|
-
end
|
|
37
31
|
end
|
|
38
32
|
end
|
|
39
33
|
end
|
|
@@ -28,12 +28,6 @@ module OpenTelemetry
|
|
|
28
28
|
def observe(timeout: nil, attributes: {})
|
|
29
29
|
update(timeout, attributes)
|
|
30
30
|
end
|
|
31
|
-
|
|
32
|
-
private
|
|
33
|
-
|
|
34
|
-
def default_aggregation
|
|
35
|
-
OpenTelemetry::SDK::Metrics::Aggregation::LastValue.new(exemplar_reservoir: @exemplar_reservoir)
|
|
36
|
-
end
|
|
37
31
|
end
|
|
38
32
|
end
|
|
39
33
|
end
|
|
@@ -28,12 +28,6 @@ module OpenTelemetry
|
|
|
28
28
|
def observe(timeout: nil, attributes: {})
|
|
29
29
|
update(timeout, attributes)
|
|
30
30
|
end
|
|
31
|
-
|
|
32
|
-
private
|
|
33
|
-
|
|
34
|
-
def default_aggregation
|
|
35
|
-
OpenTelemetry::SDK::Metrics::Aggregation::Sum.new(aggregation_temporality: :cumulative, exemplar_reservoir: @exemplar_reservoir, monotonic: false)
|
|
36
|
-
end
|
|
37
31
|
end
|
|
38
32
|
end
|
|
39
33
|
end
|
|
@@ -11,6 +11,8 @@ module OpenTelemetry
|
|
|
11
11
|
# {SynchronousInstrument} contains the common functionality shared across
|
|
12
12
|
# the synchronous instruments SDK instruments.
|
|
13
13
|
class SynchronousInstrument
|
|
14
|
+
attr_reader :exemplar_reservoir
|
|
15
|
+
|
|
14
16
|
def initialize(name, unit, description, instrumentation_scope, meter_provider, exemplar_filter, exemplar_reservoir)
|
|
15
17
|
@name = name
|
|
16
18
|
@unit = unit
|
|
@@ -25,7 +27,7 @@ module OpenTelemetry
|
|
|
25
27
|
end
|
|
26
28
|
|
|
27
29
|
# @api private
|
|
28
|
-
def register_with_new_metric_store(metric_store, aggregation: default_aggregation)
|
|
30
|
+
def register_with_new_metric_store(metric_store, aggregation: nil, default_aggregation: nil)
|
|
29
31
|
ms = OpenTelemetry::SDK::Metrics::State::MetricStream.new(
|
|
30
32
|
@name,
|
|
31
33
|
@description,
|
|
@@ -35,7 +37,8 @@ module OpenTelemetry
|
|
|
35
37
|
@instrumentation_scope,
|
|
36
38
|
aggregation,
|
|
37
39
|
@exemplar_filter,
|
|
38
|
-
@exemplar_reservoir
|
|
40
|
+
@exemplar_reservoir,
|
|
41
|
+
default_aggregation: default_aggregation
|
|
39
42
|
)
|
|
40
43
|
@metric_streams << ms
|
|
41
44
|
metric_store.add_metric_stream(ms)
|
|
@@ -31,12 +31,6 @@ module OpenTelemetry
|
|
|
31
31
|
OpenTelemetry.handle_error(exception: e)
|
|
32
32
|
nil
|
|
33
33
|
end
|
|
34
|
-
|
|
35
|
-
private
|
|
36
|
-
|
|
37
|
-
def default_aggregation
|
|
38
|
-
OpenTelemetry::SDK::Metrics::Aggregation::Sum.new(aggregation_temporality: :cumulative, exemplar_reservoir: @exemplar_reservoir, monotonic: false)
|
|
39
|
-
end
|
|
40
34
|
end
|
|
41
35
|
end
|
|
42
36
|
end
|
|
@@ -13,6 +13,10 @@ module OpenTelemetry
|
|
|
13
13
|
class Meter < OpenTelemetry::Metrics::Meter
|
|
14
14
|
NAME_REGEX = %r{\A[a-zA-Z][-./\w]{0,254}\z}
|
|
15
15
|
|
|
16
|
+
# Identifying fields of a created instrument, used to detect duplicate registrations.
|
|
17
|
+
InstrumentDescriptor = Struct.new(:name, :kind, :unit, :description, :instrument)
|
|
18
|
+
private_constant(:InstrumentDescriptor)
|
|
19
|
+
|
|
16
20
|
# @api private
|
|
17
21
|
#
|
|
18
22
|
# Returns a new {Meter} instance.
|
|
@@ -25,7 +29,8 @@ module OpenTelemetry
|
|
|
25
29
|
# @return [Meter]
|
|
26
30
|
def initialize(name, version, meter_provider, attributes: nil)
|
|
27
31
|
@mutex = Mutex.new
|
|
28
|
-
|
|
32
|
+
# Every built instrument, including conflicting duplicates, keyed by downcased name.
|
|
33
|
+
@instrument_descriptors = {}
|
|
29
34
|
@instrumentation_scope = InstrumentationScope.new(name, version, attributes || {}.freeze)
|
|
30
35
|
@meter_provider = meter_provider
|
|
31
36
|
end
|
|
@@ -56,37 +61,97 @@ module OpenTelemetry
|
|
|
56
61
|
end
|
|
57
62
|
|
|
58
63
|
# @api private
|
|
64
|
+
#
|
|
65
|
+
# Not synchronized on @mutex: create_instrument holds it while waiting on the
|
|
66
|
+
# meter provider's mutex, which the caller of this method already holds.
|
|
67
|
+
# Iterates a snapshot so a concurrent registration cannot mutate the hash mid-iteration.
|
|
59
68
|
def add_metric_reader(metric_reader)
|
|
60
|
-
@
|
|
61
|
-
instrument.register_with_new_metric_store(metric_reader.metric_store
|
|
69
|
+
@instrument_descriptors.values.flatten.each do |descriptor|
|
|
70
|
+
descriptor.instrument.register_with_new_metric_store(metric_reader.metric_store,
|
|
71
|
+
default_aggregation: MeterProvider.reader_config(metric_reader))
|
|
62
72
|
end
|
|
63
73
|
end
|
|
64
74
|
|
|
65
75
|
# Validates the given instrument options and creates the instrument of the given kind.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
raise InstrumentNameError if name
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
# TODO: advisory parameters are accepted but not yet applied to stream configuration.
|
|
77
|
+
def create_instrument(kind, name, unit, description, callback, exemplar_filter, exemplar_reservoir, advisory)
|
|
78
|
+
raise InstrumentNameError if invalid_name?(name)
|
|
79
|
+
|
|
80
|
+
unit ||= ''
|
|
81
|
+
description ||= ''
|
|
82
|
+
|
|
83
|
+
@mutex.synchronize do
|
|
84
|
+
# Read without inserting; the key is only added once an instrument is built.
|
|
85
|
+
descriptors = @instrument_descriptors.fetch(name.downcase, [])
|
|
86
|
+
|
|
87
|
+
# Instrument names are case-insensitive, so use the first-seen casing.
|
|
88
|
+
# if first_seen is count, name is Count, then name become count
|
|
89
|
+
first_seen = descriptors.first&.name
|
|
90
|
+
if first_seen && first_seen != name
|
|
91
|
+
OpenTelemetry.logger.warn("case-insensitive duplicate instrument registration occurred:'#{name}' first seen as '#{first_seen}'")
|
|
92
|
+
name = first_seen
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
identical = descriptors.find { |descriptor| identical?(descriptor, kind, unit, description) }
|
|
96
|
+
|
|
97
|
+
if identical
|
|
98
|
+
OpenTelemetry.logger.warn("repeated observable instrument creation with callbacks for instrument name '#{name}'. Ignoring new callbacks. Use Meter#register_callback to add callbacks.") unless Array(callback).empty?
|
|
99
|
+
identical.instrument
|
|
100
|
+
else
|
|
101
|
+
# Found the first conflicting instrument with the same name but different attributes (kind, unit, description).
|
|
102
|
+
unless descriptors.empty?
|
|
103
|
+
# TODO: implement the function that can determine if the duplicate registration can be resolved by a view
|
|
104
|
+
# (current View can't rename the instrument name and description)
|
|
105
|
+
OpenTelemetry.logger.warn("duplicate instrument registration occurred for instrument name '#{name}'")
|
|
106
|
+
warn_conflicting_fields(descriptors.first, kind, unit, description)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Build and register a new instrument since (still build the instrument even though a conflicting one exists) it has different attributes.
|
|
110
|
+
instrument = build_instrument(kind, name, unit, description, callback, exemplar_filter, exemplar_reservoir)
|
|
111
|
+
# Replace rather than append so arrays already snapshotted by add_metric_reader are never mutated.
|
|
112
|
+
descriptors << InstrumentDescriptor.new(name, kind, unit, description, instrument)
|
|
113
|
+
@instrument_descriptors[name.downcase] = descriptors
|
|
114
|
+
instrument
|
|
82
115
|
end
|
|
83
116
|
end
|
|
84
117
|
end
|
|
85
118
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
119
|
+
private
|
|
120
|
+
|
|
121
|
+
# Return true if name is nil/empty or not match NAME_REGEX
|
|
122
|
+
def invalid_name?(name)
|
|
123
|
+
name.to_s.empty? || !NAME_REGEX.match?(name)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Returns a new SDK instrument of the given kind.
|
|
127
|
+
def build_instrument(kind, name, unit, description, callback, exemplar_filter, exemplar_reservoir)
|
|
128
|
+
case kind
|
|
129
|
+
when :counter then OpenTelemetry::SDK::Metrics::Instrument::Counter.new(name, unit, description, @instrumentation_scope, @meter_provider, exemplar_filter, exemplar_reservoir)
|
|
130
|
+
when :observable_counter then OpenTelemetry::SDK::Metrics::Instrument::ObservableCounter.new(name, unit, description, callback, @instrumentation_scope, @meter_provider, exemplar_filter, exemplar_reservoir)
|
|
131
|
+
when :gauge then OpenTelemetry::SDK::Metrics::Instrument::Gauge.new(name, unit, description, @instrumentation_scope, @meter_provider, exemplar_filter, exemplar_reservoir)
|
|
132
|
+
when :histogram then OpenTelemetry::SDK::Metrics::Instrument::Histogram.new(name, unit, description, @instrumentation_scope, @meter_provider, exemplar_filter, exemplar_reservoir)
|
|
133
|
+
when :observable_gauge then OpenTelemetry::SDK::Metrics::Instrument::ObservableGauge.new(name, unit, description, callback, @instrumentation_scope, @meter_provider, exemplar_filter, exemplar_reservoir)
|
|
134
|
+
when :up_down_counter then OpenTelemetry::SDK::Metrics::Instrument::UpDownCounter.new(name, unit, description, @instrumentation_scope, @meter_provider, exemplar_filter, exemplar_reservoir)
|
|
135
|
+
when :observable_up_down_counter then OpenTelemetry::SDK::Metrics::Instrument::ObservableUpDownCounter.new(name, unit, description, callback, @instrumentation_scope, @meter_provider, exemplar_filter, exemplar_reservoir)
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
# Returns whether an existing registration has the same identifying fields.
|
|
140
|
+
def identical?(descriptor, kind, unit, description)
|
|
141
|
+
descriptor.kind == kind &&
|
|
142
|
+
descriptor.unit.to_s == unit.to_s &&
|
|
143
|
+
descriptor.description.to_s == description.to_s
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# Warns which identifying fields differ from the existing registration.
|
|
147
|
+
# The spec's View-based recipes are omitted because Views cannot rename a stream or override its description.
|
|
148
|
+
def warn_conflicting_fields(existing, kind, unit, description)
|
|
149
|
+
conflicts = []
|
|
150
|
+
conflicts << "kind (#{existing.kind} and #{kind})" if existing.kind != kind
|
|
151
|
+
conflicts << "unit (#{existing.unit.inspect} and #{unit.inspect})" if existing.unit.to_s != unit.to_s
|
|
152
|
+
conflicts << "description (#{existing.description.inspect} and #{description.inspect})" if existing.description.to_s != description.to_s
|
|
153
|
+
|
|
154
|
+
OpenTelemetry.logger.warn("conflicting fields: #{conflicts.join(', ')}")
|
|
90
155
|
end
|
|
91
156
|
end
|
|
92
157
|
end
|
|
@@ -13,6 +13,11 @@ module OpenTelemetry
|
|
|
13
13
|
# rubocop:disable-next Metrics/ClassLength
|
|
14
14
|
class MeterProvider < OpenTelemetry::Metrics::MeterProvider
|
|
15
15
|
EMPTY_ATTRIBUTES = {}.freeze
|
|
16
|
+
READER_OWNERS = ObjectSpace::WeakMap.new
|
|
17
|
+
READER_OWNERS_MUTEX = Mutex.new
|
|
18
|
+
READER_OWNERSHIP_ERROR = 'MetricReader cannot be registered with more than one MeterProvider'
|
|
19
|
+
|
|
20
|
+
private_constant :READER_OWNERS, :READER_OWNERS_MUTEX, :READER_OWNERSHIP_ERROR
|
|
16
21
|
|
|
17
22
|
Key = Struct.new(:name, :version, :attributes)
|
|
18
23
|
private_constant(:Key)
|
|
@@ -118,6 +123,7 @@ module OpenTelemetry
|
|
|
118
123
|
if @stopped
|
|
119
124
|
OpenTelemetry.logger.warn('calling MetricProvider#add_metric_reader after shutdown.')
|
|
120
125
|
else
|
|
126
|
+
register_metric_reader(metric_reader)
|
|
121
127
|
@metric_readers.push(metric_reader)
|
|
122
128
|
@meter_registry.each_value { |meter| meter.add_metric_reader(metric_reader) }
|
|
123
129
|
end
|
|
@@ -126,11 +132,31 @@ module OpenTelemetry
|
|
|
126
132
|
end
|
|
127
133
|
end
|
|
128
134
|
|
|
135
|
+
def register_metric_reader(metric_reader)
|
|
136
|
+
READER_OWNERS_MUTEX.synchronize do
|
|
137
|
+
owner = READER_OWNERS[metric_reader]
|
|
138
|
+
raise ArgumentError, READER_OWNERSHIP_ERROR if owner && !owner.equal?(self)
|
|
139
|
+
|
|
140
|
+
READER_OWNERS[metric_reader] = self
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
metric_reader.register_meter_provider(self) if metric_reader.respond_to?(:register_meter_provider)
|
|
144
|
+
end
|
|
145
|
+
private :register_metric_reader
|
|
146
|
+
|
|
147
|
+
# @api private
|
|
148
|
+
#
|
|
149
|
+
# Returns the reader's preferred aggregation classes, or nil for a reader that
|
|
150
|
+
# does not provide any. Readers are duck typed, so the method may be absent.
|
|
151
|
+
def self.reader_config(metric_reader)
|
|
152
|
+
metric_reader.default_aggregation if metric_reader.respond_to?(:default_aggregation)
|
|
153
|
+
end
|
|
154
|
+
|
|
129
155
|
# @api private
|
|
130
156
|
def register_synchronous_instrument(instrument)
|
|
131
157
|
@mutex.synchronize do
|
|
132
158
|
@metric_readers.each do |mr|
|
|
133
|
-
instrument.register_with_new_metric_store(mr.metric_store)
|
|
159
|
+
instrument.register_with_new_metric_store(mr.metric_store, default_aggregation: MeterProvider.reader_config(mr))
|
|
134
160
|
end
|
|
135
161
|
end
|
|
136
162
|
end
|
|
@@ -27,10 +27,12 @@ module OpenTelemetry
|
|
|
27
27
|
timeout,
|
|
28
28
|
attributes,
|
|
29
29
|
exemplar_filter,
|
|
30
|
-
exemplar_reservoir
|
|
30
|
+
exemplar_reservoir,
|
|
31
|
+
default_aggregation: nil
|
|
31
32
|
)
|
|
32
33
|
# Call parent constructor with common parameters
|
|
33
|
-
super(name, description, unit, instrument_kind, meter_provider, instrumentation_scope, aggregation, exemplar_filter, exemplar_reservoir
|
|
34
|
+
super(name, description, unit, instrument_kind, meter_provider, instrumentation_scope, aggregation, exemplar_filter, exemplar_reservoir,
|
|
35
|
+
default_aggregation: default_aggregation)
|
|
34
36
|
|
|
35
37
|
# Initialize asynchronous-specific attributes
|
|
36
38
|
@callback = callback
|
|
@@ -29,7 +29,8 @@ module OpenTelemetry
|
|
|
29
29
|
instrumentation_scope,
|
|
30
30
|
aggregation,
|
|
31
31
|
exemplar_filter,
|
|
32
|
-
exemplar_reservoir
|
|
32
|
+
exemplar_reservoir,
|
|
33
|
+
default_aggregation: nil
|
|
33
34
|
)
|
|
34
35
|
@name = name
|
|
35
36
|
@description = description
|
|
@@ -37,7 +38,7 @@ module OpenTelemetry
|
|
|
37
38
|
@instrument_kind = instrument_kind
|
|
38
39
|
@meter_provider = meter_provider
|
|
39
40
|
@instrumentation_scope = instrumentation_scope
|
|
40
|
-
@default_aggregation = aggregation
|
|
41
|
+
@default_aggregation = aggregation || build_aggregation(default_aggregation, exemplar_reservoir)
|
|
41
42
|
@data_points = {}
|
|
42
43
|
@registered_views = {}
|
|
43
44
|
@exemplar_filter = exemplar_filter
|
|
@@ -47,6 +48,31 @@ module OpenTelemetry
|
|
|
47
48
|
@mutex = Mutex.new
|
|
48
49
|
end
|
|
49
50
|
|
|
51
|
+
# Builds this stream's aggregation from the metric reader's preferred
|
|
52
|
+
# aggregation classes, falling back to the spec defaults.
|
|
53
|
+
#
|
|
54
|
+
# @param [Hash{Symbol => Class}, nil] preferred aggregation classes by instrument kind
|
|
55
|
+
# @param [Object, nil] exemplar_reservoir the instrument's exemplar reservoir
|
|
56
|
+
# @return [Object] a new aggregation, owned by this stream
|
|
57
|
+
def build_aggregation(preferred, exemplar_reservoir)
|
|
58
|
+
defaults = OpenTelemetry::SDK::Metrics::Export::MetricReader::DEFAULT_AGGREGATION
|
|
59
|
+
aggregation_class = (preferred || defaults)[@instrument_kind] || defaults[@instrument_kind]
|
|
60
|
+
|
|
61
|
+
if aggregation_class.nil?
|
|
62
|
+
OpenTelemetry.logger.warn("Unknown instrument kind: #{@instrument_kind}, defaulting to Drop aggregation")
|
|
63
|
+
aggregation_class = OpenTelemetry::SDK::Metrics::Aggregation::Drop
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
kwargs = { exemplar_reservoir: exemplar_reservoir }
|
|
67
|
+
if aggregation_class <= OpenTelemetry::SDK::Metrics::Aggregation::Sum
|
|
68
|
+
kwargs[:monotonic] = %i[counter observable_counter].include?(@instrument_kind)
|
|
69
|
+
kwargs[:instrument_kind] = @instrument_kind
|
|
70
|
+
kwargs[:aggregation_temporality] = :cumulative if %i[up_down_counter observable_up_down_counter].include?(@instrument_kind)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
aggregation_class.new(**kwargs)
|
|
74
|
+
end
|
|
75
|
+
|
|
50
76
|
# Returns a snapshot of this stream's aggregated metric data.
|
|
51
77
|
def collect(start_time, end_time)
|
|
52
78
|
@mutex.synchronize do
|
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.
|
|
4
|
+
version: 0.22.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- OpenTelemetry Authors
|
|
@@ -29,14 +29,14 @@ dependencies:
|
|
|
29
29
|
requirements:
|
|
30
30
|
- - "~>"
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version:
|
|
32
|
+
version: 0.10.0
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
37
|
- - "~>"
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version:
|
|
39
|
+
version: 0.10.0
|
|
40
40
|
- !ruby/object:Gem::Dependency
|
|
41
41
|
name: opentelemetry-sdk
|
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -78,6 +78,7 @@ files:
|
|
|
78
78
|
- lib/opentelemetry/sdk/metrics/aggregation/histogram_data_point.rb
|
|
79
79
|
- lib/opentelemetry/sdk/metrics/aggregation/last_value.rb
|
|
80
80
|
- lib/opentelemetry/sdk/metrics/aggregation/number_data_point.rb
|
|
81
|
+
- lib/opentelemetry/sdk/metrics/aggregation/stream_scoped_storage.rb
|
|
81
82
|
- lib/opentelemetry/sdk/metrics/aggregation/sum.rb
|
|
82
83
|
- lib/opentelemetry/sdk/metrics/configurator_patch.rb
|
|
83
84
|
- lib/opentelemetry/sdk/metrics/exemplar.rb
|
|
@@ -121,10 +122,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby
|
|
|
121
122
|
licenses:
|
|
122
123
|
- Apache-2.0
|
|
123
124
|
metadata:
|
|
124
|
-
changelog_uri: https://rubydoc.info/gems/opentelemetry-metrics-sdk/0.
|
|
125
|
-
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/opentelemetry-metrics-sdk/v0.
|
|
125
|
+
changelog_uri: https://rubydoc.info/gems/opentelemetry-metrics-sdk/0.22.0/file/CHANGELOG.md
|
|
126
|
+
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/opentelemetry-metrics-sdk/v0.22.0/metrics_sdk
|
|
126
127
|
bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
|
|
127
|
-
documentation_uri: https://rubydoc.info/gems/opentelemetry-metrics-sdk/0.
|
|
128
|
+
documentation_uri: https://rubydoc.info/gems/opentelemetry-metrics-sdk/0.22.0
|
|
128
129
|
rdoc_options: []
|
|
129
130
|
require_paths:
|
|
130
131
|
- lib
|
|
@@ -139,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
139
140
|
- !ruby/object:Gem::Version
|
|
140
141
|
version: '0'
|
|
141
142
|
requirements: []
|
|
142
|
-
rubygems_version: 4.0.
|
|
143
|
+
rubygems_version: 4.0.20
|
|
143
144
|
specification_version: 4
|
|
144
145
|
summary: A stats collection and distributed tracing framework
|
|
145
146
|
test_files: []
|