opentelemetry-metrics-api 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6232b4090e467e0d9f7933342d5a1a9634a41186222306214d889b5c211af55c
4
- data.tar.gz: 6e52fe54891237e36ef39fcd29ef035772051f1a54e18b67270369af8a06f352
3
+ metadata.gz: aee00375b1af8d663e0b22a4a28301bd0c57539cfee2285cca68892225d33478
4
+ data.tar.gz: ab779b3f63f322226096b7e1cd81914943cc4b4f71bc39560e9c07638294b5d4
5
5
  SHA512:
6
- metadata.gz: cf96e7239ee84437c1b4389b763b3f80f7882c8d9e29b2db94f7bd0bb9c1cfbd8475a0cb75712e8c916833a3cc184c4028f95996905dd3d2fddec13a8999d9a3
7
- data.tar.gz: 6d048b7a1622e36a791cf5e64f104f8a75faa3a9248495bd528ad7089fa6f2d685aa5f9f52026e92366b11aa4faefabe5f18cde5262d35df39fbc7f98092c5ca
6
+ metadata.gz: fc11b02c19b8b58e531b0eb725bd3d143d70a3d760ed0aefa43186be948f1017fac4318f66a9d9ac8a567f5943e4d7d35123fd13cf65d755b224a8e3fda3724d
7
+ data.tar.gz: 7740bb55aa66982a5b7c7545964692a1d9e7d24b6b1251d9ecdad9c3478347b19585bac87510ec107206251406c1f12f558fec2e33a0b029bf8cfec5891c7667
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
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
+
3
8
  ### v0.1.1 / 2024-10-22
4
9
 
5
10
  * FIXED: Refactor instrument validation
@@ -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)
@@ -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
@@ -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,11 +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
- private_constant(:COUNTER, :OBSERVABLE_COUNTER, :HISTOGRAM, :OBSERVABLE_GAUGE, :UP_DOWN_COUNTER, :OBSERVABLE_UP_DOWN_COUNTER)
19
+ NAME_REGEX = /\A[a-zA-Z][-.\w]{0,62}\z/
20
+
21
+ private_constant(:COUNTER, :OBSERVABLE_COUNTER, :HISTOGRAM, :GAUGE, :OBSERVABLE_GAUGE, :UP_DOWN_COUNTER, :OBSERVABLE_UP_DOWN_COUNTER)
19
22
 
20
23
  DuplicateInstrumentError = Class.new(OpenTelemetry::Error)
21
24
  InstrumentNameError = Class.new(OpenTelemetry::Error)
@@ -27,26 +30,141 @@ module OpenTelemetry
27
30
  @instrument_registry = {}
28
31
  end
29
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
30
46
  def create_counter(name, unit: nil, description: nil)
31
47
  create_instrument(:counter, name, unit, description, nil) { COUNTER }
32
48
  end
33
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
34
65
  def create_histogram(name, unit: nil, description: nil)
35
66
  create_instrument(:histogram, name, unit, description, nil) { HISTOGRAM }
36
67
  end
37
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
38
100
  def create_up_down_counter(name, unit: nil, description: nil)
39
101
  create_instrument(:up_down_counter, name, unit, description, nil) { UP_DOWN_COUNTER }
40
102
  end
41
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
42
122
  def create_observable_counter(name, callback:, unit: nil, description: nil)
43
123
  create_instrument(:observable_counter, name, unit, description, callback) { OBSERVABLE_COUNTER }
44
124
  end
45
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
46
145
  def create_observable_gauge(name, callback:, unit: nil, description: nil)
47
146
  create_instrument(:observable_gauge, name, unit, description, callback) { OBSERVABLE_GAUGE }
48
147
  end
49
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
50
168
  def create_observable_up_down_counter(name, callback:, unit: nil, description: nil)
51
169
  create_instrument(:observable_up_down_counter, name, unit, description, callback) { OBSERVABLE_UP_DOWN_COUNTER }
52
170
  end
@@ -7,6 +7,6 @@
7
7
  module OpenTelemetry
8
8
  module Metrics
9
9
  ## Current OpenTelemetry metrics version
10
- VERSION = '0.1.1'
10
+ VERSION = '0.2.0'
11
11
  end
12
12
  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.1.1
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: 2024-10-22 00:00:00.000000000 Z
11
+ date: 2025-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-api
@@ -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.1.1/file.CHANGELOG.html
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.1.1
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: []