opentelemetry-metrics-api 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +6 -2
- data/lib/opentelemetry/internal/proxy_instrument.rb +1 -1
- data/lib/opentelemetry/internal/proxy_meter.rb +1 -0
- data/lib/opentelemetry/metrics/instrument/counter.rb +1 -1
- data/lib/opentelemetry/metrics/instrument/gauge.rb +23 -0
- data/lib/opentelemetry/metrics/instrument/histogram.rb +1 -1
- data/lib/opentelemetry/metrics/instrument/up_down_counter.rb +1 -1
- data/lib/opentelemetry/metrics/instrument.rb +1 -0
- data/lib/opentelemetry/metrics/meter.rb +117 -12
- data/lib/opentelemetry/metrics/version.rb +1 -1
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aee00375b1af8d663e0b22a4a28301bd0c57539cfee2285cca68892225d33478
|
4
|
+
data.tar.gz: ab779b3f63f322226096b7e1cd81914943cc4b4f71bc39560e9c07638294b5d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc11b02c19b8b58e531b0eb725bd3d143d70a3d760ed0aefa43186be948f1017fac4318f66a9d9ac8a567f5943e4d7d35123fd13cf65d755b224a8e3fda3724d
|
7
|
+
data.tar.gz: 7740bb55aa66982a5b7c7545964692a1d9e7d24b6b1251d9ecdad9c3478347b19585bac87510ec107206251406c1f12f558fec2e33a0b029bf8cfec5891c7667
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# Release History: opentelemetry-metrics-api
|
2
2
|
|
3
|
+
### v0.2.0 / 2025-01-08
|
4
|
+
|
5
|
+
* ADDED: Add synchronous gauge
|
6
|
+
* DOCS: Add documentation for Metrics API instruments
|
7
|
+
|
8
|
+
### v0.1.1 / 2024-10-22
|
9
|
+
|
10
|
+
* FIXED: Refactor instrument validation
|
11
|
+
|
3
12
|
### v0.1.0 / 2024-07-31
|
4
13
|
|
5
14
|
Initial release.
|
data/README.md
CHANGED
@@ -12,7 +12,11 @@ OpenTelemetry provides a single set of APIs, libraries, agents, and collector se
|
|
12
12
|
|
13
13
|
The `opentelemetry-metrics-api` gem defines the core OpenTelemetry interfaces in the form of abstract classes and no-op implementations. That is, it defines interfaces and data types sufficient for a library or application to code against to produce telemetry data, but does not actually collect, analyze, or export the data.
|
14
14
|
|
15
|
-
To collect and analyze telemetry data, _applications_ should also
|
15
|
+
To collect and analyze telemetry data, _applications_ should also
|
16
|
+
install a concrete implementation of the API, such as the
|
17
|
+
`opentelemetry-metrics-sdk` gem. However, _libraries_ that produce
|
18
|
+
telemetry data should depend only on `opentelemetry-metrics-api`,
|
19
|
+
deferring the choice of concrete implementation to the application developer.
|
16
20
|
|
17
21
|
This code is still under development and is not a complete implementation of the Metrics API. Until the code becomes stable, Metrics API functionality will live outside the `opentelemetry-api` library.
|
18
22
|
|
@@ -20,7 +24,7 @@ This code is still under development and is not a complete implementation of the
|
|
20
24
|
|
21
25
|
Install the gem using:
|
22
26
|
|
23
|
-
```
|
27
|
+
```sh
|
24
28
|
gem install opentelemetry-metrics-api
|
25
29
|
```
|
26
30
|
|
@@ -19,7 +19,7 @@ module OpenTelemetry
|
|
19
19
|
|
20
20
|
def upgrade_with(meter)
|
21
21
|
@delegate = case @kind
|
22
|
-
when :counter, :histogram, :up_down_counter
|
22
|
+
when :counter, :histogram, :up_down_counter, :gauge
|
23
23
|
meter.send("create_#{@kind}", @name, unit: @unit, description: @desc)
|
24
24
|
when :observable_counter, :observable_gauge, :observable_up_down_counter
|
25
25
|
meter.send("create_#{@kind}", @name, unit: @unit, description: @desc, callback: @callback)
|
@@ -45,6 +45,7 @@ module OpenTelemetry
|
|
45
45
|
case kind
|
46
46
|
when :counter then @delegate.create_counter(name, unit: unit, description: description)
|
47
47
|
when :histogram then @delegate.create_histogram(name, unit: unit, description: description)
|
48
|
+
when :gauge then @delegate.create_gauge(name, unit: unit, description: description)
|
48
49
|
when :up_down_counter then @delegate.create_up_down_counter(name, unit: unit, description: description)
|
49
50
|
when :observable_counter then @delegate.create_observable_counter(name, unit: unit, description: description, callback: callback)
|
50
51
|
when :observable_gauge then @delegate.create_observable_gauge(name, unit: unit, description: description, callback: callback)
|
@@ -16,7 +16,7 @@ module OpenTelemetry
|
|
16
16
|
# Values must be non-nil and (array of) string, boolean or numeric type.
|
17
17
|
# Array values must not contain nil elements and all elements must be of
|
18
18
|
# the same basic type (string, numeric, boolean).
|
19
|
-
def add(increment, attributes:
|
19
|
+
def add(increment, attributes: {}); end
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -0,0 +1,23 @@
|
|
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 Metrics
|
9
|
+
module Instrument
|
10
|
+
# No-op implementation of Gauge.
|
11
|
+
class Gauge
|
12
|
+
# Record the current value for the Gauge
|
13
|
+
#
|
14
|
+
# @param [Numeric] amount The current absolute value.
|
15
|
+
# @param [Hash{String => String, Numeric, Boolean, Array<String, Numeric, Boolean>}] attributes
|
16
|
+
# Values must be non-nil and (array of) string, boolean or numeric type.
|
17
|
+
# Array values must not contain nil elements and all elements must be of
|
18
|
+
# the same basic type (string, numeric, boolean).
|
19
|
+
def record(amount, attributes: {}); end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -16,7 +16,7 @@ module OpenTelemetry
|
|
16
16
|
# Values must be non-nil and (array of) string, boolean or numeric type.
|
17
17
|
# Array values must not contain nil elements and all elements must be of
|
18
18
|
# the same basic type (string, numeric, boolean).
|
19
|
-
def record(amount, attributes:
|
19
|
+
def record(amount, attributes: {}); end
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -16,7 +16,7 @@ module OpenTelemetry
|
|
16
16
|
# Values must be non-nil and (array of) string, boolean or numeric type.
|
17
17
|
# Array values must not contain nil elements and all elements must be of
|
18
18
|
# the same basic type (string, numeric, boolean).
|
19
|
-
def add(amount, attributes:
|
19
|
+
def add(amount, attributes: {}); end
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -6,6 +6,7 @@
|
|
6
6
|
|
7
7
|
require 'opentelemetry/metrics/instrument/counter'
|
8
8
|
require 'opentelemetry/metrics/instrument/histogram'
|
9
|
+
require 'opentelemetry/metrics/instrument/gauge'
|
9
10
|
require 'opentelemetry/metrics/instrument/observable_counter'
|
10
11
|
require 'opentelemetry/metrics/instrument/observable_gauge'
|
11
12
|
require 'opentelemetry/metrics/instrument/observable_up_down_counter'
|
@@ -11,13 +11,14 @@ module OpenTelemetry
|
|
11
11
|
COUNTER = Instrument::Counter.new
|
12
12
|
OBSERVABLE_COUNTER = Instrument::ObservableCounter.new
|
13
13
|
HISTOGRAM = Instrument::Histogram.new
|
14
|
+
GAUGE = Instrument::Gauge.new
|
14
15
|
OBSERVABLE_GAUGE = Instrument::ObservableGauge.new
|
15
16
|
UP_DOWN_COUNTER = Instrument::UpDownCounter.new
|
16
17
|
OBSERVABLE_UP_DOWN_COUNTER = Instrument::ObservableUpDownCounter.new
|
17
18
|
|
18
19
|
NAME_REGEX = /\A[a-zA-Z][-.\w]{0,62}\z/
|
19
20
|
|
20
|
-
private_constant(:COUNTER, :OBSERVABLE_COUNTER, :HISTOGRAM, :OBSERVABLE_GAUGE, :UP_DOWN_COUNTER, :OBSERVABLE_UP_DOWN_COUNTER)
|
21
|
+
private_constant(:COUNTER, :OBSERVABLE_COUNTER, :HISTOGRAM, :GAUGE, :OBSERVABLE_GAUGE, :UP_DOWN_COUNTER, :OBSERVABLE_UP_DOWN_COUNTER)
|
21
22
|
|
22
23
|
DuplicateInstrumentError = Class.new(OpenTelemetry::Error)
|
23
24
|
InstrumentNameError = Class.new(OpenTelemetry::Error)
|
@@ -29,26 +30,141 @@ module OpenTelemetry
|
|
29
30
|
@instrument_registry = {}
|
30
31
|
end
|
31
32
|
|
33
|
+
# {https://opentelemetry.io/docs/specs/otel/metrics/api/#counter Counter} is a synchronous Instrument which supports non-negative increments.
|
34
|
+
#
|
35
|
+
# With this api call:
|
36
|
+
#
|
37
|
+
# exception_counter = meter.create_counter("exceptions",
|
38
|
+
# description: "number of exceptions caught",
|
39
|
+
# unit: 's')
|
40
|
+
#
|
41
|
+
# @param name [String] the name of the counter
|
42
|
+
# @param unit [optional String] an optional string provided by user.
|
43
|
+
# @param description [optional String] an optional free-form text provided by user.
|
44
|
+
#
|
45
|
+
# @return [nil] after creation of counter, it will be stored in instrument_registry
|
32
46
|
def create_counter(name, unit: nil, description: nil)
|
33
47
|
create_instrument(:counter, name, unit, description, nil) { COUNTER }
|
34
48
|
end
|
35
49
|
|
50
|
+
# Histogram is a synchronous Instrument which can be used to report arbitrary values that are likely
|
51
|
+
# to be statistically meaningful. It is intended for statistics such as histograms,
|
52
|
+
# summaries, and percentiles.
|
53
|
+
#
|
54
|
+
# With this api call:
|
55
|
+
#
|
56
|
+
# http_server_duration = meter.create_histogram("http.server.duration",
|
57
|
+
# description: "measures the duration of the inbound HTTP request",
|
58
|
+
# unit: "s")
|
59
|
+
#
|
60
|
+
# @param name [String] the name of the histogram
|
61
|
+
# @param unit [optional String] an optional string provided by user.
|
62
|
+
# @param description [optional String] an optional free-form text provided by user.
|
63
|
+
#
|
64
|
+
# @return [nil] after creation of histogram, it will be stored in instrument_registry
|
36
65
|
def create_histogram(name, unit: nil, description: nil)
|
37
66
|
create_instrument(:histogram, name, unit, description, nil) { HISTOGRAM }
|
38
67
|
end
|
39
68
|
|
69
|
+
# Gauge is an synchronous Instrument which reports non-additive value(s)
|
70
|
+
#
|
71
|
+
# With this api call:
|
72
|
+
#
|
73
|
+
# meter.create_gauge("cpu.frequency",
|
74
|
+
# description: "the real-time CPU clock speed",
|
75
|
+
# unit: "ms")
|
76
|
+
#
|
77
|
+
#
|
78
|
+
# @param name [String] the name of the gauge.
|
79
|
+
# @param unit [optional String] an optional string provided by user.
|
80
|
+
# @param description [optional String] an optional free-form text provided by user.
|
81
|
+
#
|
82
|
+
# @return [nil] after creation of gauge, it will be stored in instrument_registry
|
83
|
+
def create_gauge(name, unit: nil, description: nil)
|
84
|
+
create_instrument(:gauge, name, unit, description, nil) { GAUGE }
|
85
|
+
end
|
86
|
+
|
87
|
+
# UpDownCounter is a synchronous Instrument which supports increments and decrements.
|
88
|
+
#
|
89
|
+
# With this api call:
|
90
|
+
#
|
91
|
+
# items_counter = meter.create_up_down_counter("store.inventory",
|
92
|
+
# description: "the number of the items available",
|
93
|
+
# unit: "s")
|
94
|
+
#
|
95
|
+
# @param name [String] the name of the up_down_counter
|
96
|
+
# @param unit [optional String] an optional string provided by user.
|
97
|
+
# @param description [optional String] an optional free-form text provided by user.
|
98
|
+
#
|
99
|
+
# @return [nil] after creation of up_down_counter, it will be stored in instrument_registry
|
40
100
|
def create_up_down_counter(name, unit: nil, description: nil)
|
41
101
|
create_instrument(:up_down_counter, name, unit, description, nil) { UP_DOWN_COUNTER }
|
42
102
|
end
|
43
103
|
|
104
|
+
# ObservableCounter is an asynchronous Instrument which reports monotonically
|
105
|
+
# increasing value(s) when the instrument is being observed.
|
106
|
+
#
|
107
|
+
# With this api call:
|
108
|
+
#
|
109
|
+
# pf_callback = -> { # collect metrics here }
|
110
|
+
# meter.create_observable_counter("PF",
|
111
|
+
# pf_callback,
|
112
|
+
# description: "process page faults",
|
113
|
+
# unit: 'ms')
|
114
|
+
#
|
115
|
+
#
|
116
|
+
# @param name [String] the name of the observable_counter
|
117
|
+
# @param callback [Proc] the callback function that used to collect metrics
|
118
|
+
# @param unit [optional String] an optional string provided by user.
|
119
|
+
# @param description [optional String] an optional free-form text provided by user.
|
120
|
+
#
|
121
|
+
# @return [nil] after creation of observable_counter, it will be stored in instrument_registry
|
44
122
|
def create_observable_counter(name, callback:, unit: nil, description: nil)
|
45
123
|
create_instrument(:observable_counter, name, unit, description, callback) { OBSERVABLE_COUNTER }
|
46
124
|
end
|
47
125
|
|
126
|
+
# ObservableGauge is an asynchronous Instrument which reports non-additive value(s)
|
127
|
+
# (e.g. the room temperature - it makes no sense to report the temperature value
|
128
|
+
# from multiple rooms and sum them up) when the instrument is being observed.
|
129
|
+
#
|
130
|
+
# With this api call:
|
131
|
+
#
|
132
|
+
# pf_callback = -> { # collect metrics here }
|
133
|
+
# meter.create_observable_counter("cpu.frequency",
|
134
|
+
# pf_callback,
|
135
|
+
# description: "the real-time CPU clock speed",
|
136
|
+
# unit: 'ms')
|
137
|
+
#
|
138
|
+
#
|
139
|
+
# @param name [String] the name of the observable_gauge
|
140
|
+
# @param callback [Proc] the callback function that used to collect metrics
|
141
|
+
# @param unit [optional String] an optional string provided by user.
|
142
|
+
# @param description [optional String] an optional free-form text provided by user.
|
143
|
+
#
|
144
|
+
# @return [nil] after creation of observable_gauge, it will be stored in instrument_registry
|
48
145
|
def create_observable_gauge(name, callback:, unit: nil, description: nil)
|
49
146
|
create_instrument(:observable_gauge, name, unit, description, callback) { OBSERVABLE_GAUGE }
|
50
147
|
end
|
51
148
|
|
149
|
+
# ObservableUpDownCounter is an asynchronous Instrument which reports additive value(s)
|
150
|
+
# (e.g. the process heap size - it makes sense to report the heap size from multiple processes
|
151
|
+
# and sum them up, so we get the total heap usage) when the instrument is being observed.
|
152
|
+
#
|
153
|
+
# With this api call:
|
154
|
+
#
|
155
|
+
# pf_callback = -> { # collect metrics here }
|
156
|
+
# meter.create_observable_up_down_counter("process.workingset",
|
157
|
+
# pf_callback,
|
158
|
+
# description: "process working set",
|
159
|
+
# unit: 'KB')
|
160
|
+
#
|
161
|
+
#
|
162
|
+
# @param name [String] the name of the observable_up_down_counter
|
163
|
+
# @param callback [Proc] the callback function that used to collect metrics
|
164
|
+
# @param unit [optional String] an optional string provided by user.
|
165
|
+
# @param description [optional String] an optional free-form text provided by user.
|
166
|
+
#
|
167
|
+
# @return [nil] after creation of observable_up_down_counter, it will be stored in instrument_registry
|
52
168
|
def create_observable_up_down_counter(name, callback:, unit: nil, description: nil)
|
53
169
|
create_instrument(:observable_up_down_counter, name, unit, description, callback) { OBSERVABLE_UP_DOWN_COUNTER }
|
54
170
|
end
|
@@ -56,23 +172,12 @@ module OpenTelemetry
|
|
56
172
|
private
|
57
173
|
|
58
174
|
def create_instrument(kind, name, unit, description, callback)
|
59
|
-
raise InstrumentNameError if name.nil?
|
60
|
-
raise InstrumentNameError if name.empty?
|
61
|
-
raise InstrumentNameError unless NAME_REGEX.match?(name)
|
62
|
-
raise InstrumentUnitError if unit && (!unit.ascii_only? || unit.size > 63)
|
63
|
-
raise InstrumentDescriptionError if description && (description.size > 1023 || !utf8mb3_encoding?(description.dup))
|
64
|
-
|
65
175
|
@mutex.synchronize do
|
66
176
|
OpenTelemetry.logger.warn("duplicate instrument registration occurred for instrument #{name}") if @instrument_registry.include? name
|
67
177
|
|
68
178
|
@instrument_registry[name] = yield
|
69
179
|
end
|
70
180
|
end
|
71
|
-
|
72
|
-
def utf8mb3_encoding?(string)
|
73
|
-
string.force_encoding('UTF-8').valid_encoding? &&
|
74
|
-
string.each_char { |c| return false if c.bytesize >= 4 }
|
75
|
-
end
|
76
181
|
end
|
77
182
|
end
|
78
183
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opentelemetry-metrics-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- OpenTelemetry Authors
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opentelemetry-api
|
@@ -114,14 +114,14 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 1.
|
117
|
+
version: '1.65'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: 1.
|
124
|
+
version: '1.65'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: simplecov
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,7 +164,7 @@ dependencies:
|
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: 0.1.6
|
167
|
-
description:
|
167
|
+
description:
|
168
168
|
email:
|
169
169
|
- cncf-opentelemetry-contributors@lists.cncf.io
|
170
170
|
executables: []
|
@@ -182,6 +182,7 @@ files:
|
|
182
182
|
- lib/opentelemetry/metrics.rb
|
183
183
|
- lib/opentelemetry/metrics/instrument.rb
|
184
184
|
- lib/opentelemetry/metrics/instrument/counter.rb
|
185
|
+
- lib/opentelemetry/metrics/instrument/gauge.rb
|
185
186
|
- lib/opentelemetry/metrics/instrument/histogram.rb
|
186
187
|
- lib/opentelemetry/metrics/instrument/observable_counter.rb
|
187
188
|
- lib/opentelemetry/metrics/instrument/observable_gauge.rb
|
@@ -195,11 +196,11 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby
|
|
195
196
|
licenses:
|
196
197
|
- Apache-2.0
|
197
198
|
metadata:
|
198
|
-
changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-metrics-api/v0.
|
199
|
+
changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-metrics-api/v0.2.0/file.CHANGELOG.html
|
199
200
|
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/metrics_api
|
200
201
|
bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
|
201
|
-
documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-metrics-api/v0.
|
202
|
-
post_install_message:
|
202
|
+
documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-metrics-api/v0.2.0
|
203
|
+
post_install_message:
|
203
204
|
rdoc_options: []
|
204
205
|
require_paths:
|
205
206
|
- lib
|
@@ -215,7 +216,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
215
216
|
version: '0'
|
216
217
|
requirements: []
|
217
218
|
rubygems_version: 3.2.33
|
218
|
-
signing_key:
|
219
|
+
signing_key:
|
219
220
|
specification_version: 4
|
220
221
|
summary: A stats collection and distributed tracing framework
|
221
222
|
test_files: []
|