Skip to content

Commit 0c47cd2

Browse files
committed
Merge branch 'main' of github.com:open-telemetry/opentelemetry-ruby into issues-1783
* 'main' of github.com:open-telemetry/opentelemetry-ruby: release: Release 3 gems (open-telemetry#1791) docs: add documentation for Metrics API instruments (open-telemetry#1720) docs: use link-inspector (open-telemetry#1790) feat: Gauge metrics exporter encoding (open-telemetry#1780)
2 parents cb2df41 + baeda39 commit 0c47cd2

File tree

14 files changed

+150
-24
lines changed

14 files changed

+150
-24
lines changed

.github/workflows/ci-markdown-link.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@ name: Markdown Link Check
22

33
on:
44
pull_request:
5+
paths:
6+
- '**/*.md'
57

68
jobs:
79
markdown-link-check:
810
runs-on: ubuntu-latest
911
steps:
1012
- uses: actions/checkout@v4
1113

12-
- name: "Markdown Link Check"
13-
uses: gaurav-nelson/github-action-markdown-link-check@v1
14+
# equivalent cli: linkspector check
15+
- name: Run linkspector
16+
uses: umbrelladocs/action-linkspector@v1
1417
with:
15-
config-file: '.markdown-link-check.json'
16-
use-quiet-mode: 'yes'
17-
use-verbose-mode: 'yes'
18+
github_token: ${{ secrets.GITHUB_TOKEN }}
19+
reporter: github-pr-review
20+
fail_on_error: true

.markdown-link-check.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

exporter/otlp-metrics/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release History: opentelemetry-exporter-otlp-metrics
22

3+
### v0.3.0 / 2025-01-08
4+
5+
* ADDED: Gauge metrics exporter encoding
6+
37
### v0.2.1 / 2024-12-04
48

59
* FIXED: Handle float value in NumberDataPoint

exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics/metrics_exporter.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,17 @@ def encode(metrics_data)
214214
end
215215

216216
# metrics_pb has following type of data: :gauge, :sum, :histogram, :exponential_histogram, :summary
217-
# current metric sdk only implements instrument: :counter -> :sum, :histogram -> :histogram
217+
# current metric sdk only implements instrument: :counter -> :sum, :histogram -> :histogram, :gauge -> :gauge
218218
#
219219
# metrics [MetricData]
220220
def as_otlp_metrics(metrics)
221221
case metrics.instrument_kind
222-
when :observable_gauge
222+
when :observable_gauge, :gauge
223223
Opentelemetry::Proto::Metrics::V1::Metric.new(
224224
name: metrics.name,
225225
description: metrics.description,
226226
unit: metrics.unit,
227227
gauge: Opentelemetry::Proto::Metrics::V1::Gauge.new(
228-
aggregation_temporality: as_otlp_aggregation_temporality(metrics.aggregation_temporality),
229228
data_points: metrics.data_points.map do |ndp|
230229
number_data_point(ndp)
231230
end

exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module Exporter
99
module OTLP
1010
module Metrics
1111
## Current OpenTelemetry OTLP exporter version
12-
VERSION = '0.2.1'
12+
VERSION = '0.3.0'
1313
end
1414
end
1515
end

exporter/otlp-metrics/opentelemetry-exporter-otlp-metrics.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ Gem::Specification.new do |spec|
2929
spec.add_dependency 'google-protobuf', '>= 3.18', '< 5.0'
3030
spec.add_dependency 'opentelemetry-api', '~> 1.1'
3131
spec.add_dependency 'opentelemetry-common', '~> 0.20'
32-
spec.add_dependency 'opentelemetry-metrics-api', '~> 0.1'
33-
spec.add_dependency 'opentelemetry-metrics-sdk', '~> 0.2'
32+
spec.add_dependency 'opentelemetry-metrics-api', '~> 0.2'
33+
spec.add_dependency 'opentelemetry-metrics-sdk', '~> 0.5'
3434
spec.add_dependency 'opentelemetry-sdk', '~> 1.2'
3535
spec.add_dependency 'opentelemetry-semantic_conventions'
3636

exporter/otlp-metrics/test/opentelemetry/exporter/otlp/metrics/metrics_exporter_test.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,11 +576,16 @@
576576
stub_request(:post, 'http://localhost:4318/v1/metrics').to_return(status: 200)
577577
meter_provider.add_metric_reader(exporter)
578578
meter = meter_provider.meter('test')
579+
579580
counter = meter.create_counter('test_counter', unit: 'smidgen', description: 'a small amount of something')
580581
counter.add(5, attributes: { 'foo' => 'bar' })
581582

582583
histogram = meter.create_histogram('test_histogram', unit: 'smidgen', description: 'a small amount of something')
583584
histogram.record(10, attributes: { 'oof' => 'rab' })
585+
586+
gauge = meter.create_gauge('test_gauge', unit: 'smidgen', description: 'a small amount of something')
587+
gauge.record(15, attributes: { 'baz' => 'qux' })
588+
584589
exporter.pull
585590
meter_provider.shutdown
586591

@@ -644,6 +649,24 @@
644649
],
645650
aggregation_temporality: Opentelemetry::Proto::Metrics::V1::AggregationTemporality::AGGREGATION_TEMPORALITY_DELTA
646651
)
652+
),
653+
Opentelemetry::Proto::Metrics::V1::Metric.new(
654+
name: 'test_gauge',
655+
description: 'a small amount of something',
656+
unit: 'smidgen',
657+
gauge: Opentelemetry::Proto::Metrics::V1::Gauge.new(
658+
data_points: [
659+
Opentelemetry::Proto::Metrics::V1::NumberDataPoint.new(
660+
attributes: [
661+
Opentelemetry::Proto::Common::V1::KeyValue.new(key: 'baz', value: Opentelemetry::Proto::Common::V1::AnyValue.new(string_value: 'qux'))
662+
],
663+
as_int: 15,
664+
start_time_unix_nano: 1_699_593_427_329_946_585,
665+
time_unix_nano: 1_699_593_427_329_946_586,
666+
exemplars: nil
667+
)
668+
]
669+
)
647670
)
648671
]
649672
)

exporter/otlp-metrics/test/test_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def collect(start_time, end_time, data_points)
2626

2727
OpenTelemetry::SDK::Metrics::Aggregation::Sum.prepend(MockSum)
2828
OpenTelemetry::SDK::Metrics::Aggregation::ExplicitBucketHistogram.prepend(MockSum)
29+
OpenTelemetry::SDK::Metrics::Aggregation::LastValue.prepend(MockSum)
2930

3031
def create_metrics_data(name: '', description: '', unit: '', instrument_kind: :counter, resource: nil,
3132
instrumentation_scope: OpenTelemetry::SDK::InstrumentationScope.new('', 'v0.0.1'),

metrics_api/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Release History: opentelemetry-metrics-api
22

3+
### v0.2.0 / 2025-01-08
4+
5+
* ADDED: Add synchronous gauge
6+
* DOCS: Add documentation for Metrics API instruments
7+
38
### v0.1.1 / 2024-10-22
49

510
* FIXED: Refactor instrument validation

metrics_api/lib/opentelemetry/metrics/meter.rb

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,38 @@ def initialize
3030
@instrument_registry = {}
3131
end
3232

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
3346
def create_counter(name, unit: nil, description: nil)
3447
create_instrument(:counter, name, unit, description, nil) { COUNTER }
3548
end
3649

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
3765
def create_histogram(name, unit: nil, description: nil)
3866
create_instrument(:histogram, name, unit, description, nil) { HISTOGRAM }
3967
end
@@ -56,18 +84,87 @@ def create_gauge(name, unit: nil, description: nil)
5684
create_instrument(:gauge, name, unit, description, nil) { GAUGE }
5785
end
5886

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
59100
def create_up_down_counter(name, unit: nil, description: nil)
60101
create_instrument(:up_down_counter, name, unit, description, nil) { UP_DOWN_COUNTER }
61102
end
62103

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
63122
def create_observable_counter(name, callback:, unit: nil, description: nil)
64123
create_instrument(:observable_counter, name, unit, description, callback) { OBSERVABLE_COUNTER }
65124
end
66125

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
67145
def create_observable_gauge(name, callback:, unit: nil, description: nil)
68146
create_instrument(:observable_gauge, name, unit, description, callback) { OBSERVABLE_GAUGE }
69147
end
70148

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
71168
def create_observable_up_down_counter(name, callback:, unit: nil, description: nil)
72169
create_instrument(:observable_up_down_counter, name, unit, description, callback) { OBSERVABLE_UP_DOWN_COUNTER }
73170
end

0 commit comments

Comments
 (0)