From 5bd774923f10ff8efb4a1f1a20419082fa550a6a Mon Sep 17 00:00:00 2001 From: Kayla Reopelle <87386821+kaylareopelle@users.noreply.github.com> Date: Wed, 4 Dec 2024 14:44:55 -0800 Subject: [PATCH 1/7] chore: Update http example gems (#1772) The Faraday and Sinatra versions were very out of date. Dependabot noticed the Sinatra version had known vulnerabilities. This updates the Gemfile. The example has the same output. --- examples/http/Gemfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/http/Gemfile b/examples/http/Gemfile index 5cc31fb399..2992148952 100644 --- a/examples/http/Gemfile +++ b/examples/http/Gemfile @@ -2,9 +2,10 @@ source "https://rubygems.org" -gem "faraday", "~> 0.16.1" +gem "faraday", "~> 2.0" gem "opentelemetry-api" gem "opentelemetry-common" gem "opentelemetry-sdk" -gem "sinatra", "~> 2.0" +gem "sinatra", "~> 4.1" gem "puma" +gem "rackup" From 208a18c4caad697ba31e7857454c37d0191838bd Mon Sep 17 00:00:00 2001 From: Kayla Reopelle <87386821+kaylareopelle@users.noreply.github.com> Date: Wed, 4 Dec 2024 15:14:23 -0800 Subject: [PATCH 2/7] chore: Prepare logs gems for release (#1775) * ci: Add logs-related gems to releases * docs: Update gem name in logs exporter readme --- .toys/.data/releases.yml | 14 ++++++++++++++ exporter/otlp-logs/README.md | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.toys/.data/releases.yml b/.toys/.data/releases.yml index a63f0be44f..20e894e3b5 100644 --- a/.toys/.data/releases.yml +++ b/.toys/.data/releases.yml @@ -63,6 +63,10 @@ gems: directory: exporter/otlp version_constant: [OpenTelemetry, Exporter, OTLP, VERSION] + - name: opentelemetry-exporter-otlp-logs + directory: exporter/otlp-logs + version_constant: [OpenTelemetry, Exporter, OTLP, Logs, VERSION] + - name: opentelemetry-exporter-otlp-metrics directory: exporter/otlp-metrics version_constant: [OpenTelemetry, Exporter, OTLP, Metrics, VERSION] @@ -98,3 +102,13 @@ gems: directory: metrics_sdk version_rb_path: lib/opentelemetry/sdk/metrics/version.rb version_constant: [OpenTelemetry, SDK, Metrics, VERSION] + + - name: opentelemetry-logs-api + directory: logs_api + version_rb_path: lib/opentelemetry/logs/version.rb + version_constant: [OpenTelemetry, Logs, VERSION] + + - name: opentelemetry-logs-sdk + directory: logs_sdk + version_rb_path: lib/opentelemetry/sdk/logs/version.rb + version_constant: [OpenTelemetry, SDK, Logs, VERSION] diff --git a/exporter/otlp-logs/README.md b/exporter/otlp-logs/README.md index ed45d75fa5..e1a9b9a5bc 100644 --- a/exporter/otlp-logs/README.md +++ b/exporter/otlp-logs/README.md @@ -25,7 +25,7 @@ Install the gem using: ```console gem install opentelemetry-logs-sdk -gem install opentelemetry-exporter-otlp +gem install opentelemetry-exporter-otlp-logs ``` From 8c7d016e740783185c2814d56045b537bd305a65 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 4 Dec 2024 16:00:15 -0800 Subject: [PATCH 3/7] release: Release 9 gems (#1776) * release: Release 9 gems * opentelemetry-sdk 1.6.0 (was 1.5.0) * opentelemetry-exporter-otlp 0.29.1 (was 0.29.0) * opentelemetry-exporter-otlp-logs 0.1.0 (initial release) * opentelemetry-exporter-otlp-metrics 0.2.1 (was 0.2.0) * opentelemetry-exporter-zipkin 0.23.2 (was 0.23.1) * opentelemetry-test-helpers 0.5.0 (was 0.4.0) * opentelemetry-metrics-sdk 0.5.0 (was 0.4.0) * opentelemetry-logs-api 0.1.0 (initial release) * opentelemetry-logs-sdk 0.1.0 (initial release) * chore: Fix dates from last release RubyGems release date matches UTC, updating the entries to match * chore: Update CHANGELOG entries * chore: Adjust version to 0.4.1 The ADDED commit was a false alarm. This only includes fixes. --------- Co-authored-by: Daniel Azuma Co-authored-by: Kayla Reopelle --- exporter/otlp-logs/CHANGELOG.md | 4 ++++ exporter/otlp-metrics/CHANGELOG.md | 6 +++++- .../opentelemetry/exporter/otlp/metrics/version.rb | 2 +- exporter/otlp/CHANGELOG.md | 4 ++++ .../otlp/lib/opentelemetry/exporter/otlp/version.rb | 2 +- exporter/zipkin/CHANGELOG.md | 4 ++++ .../lib/opentelemetry/exporter/zipkin/version.rb | 2 +- logs_api/CHANGELOG.md | 4 ++++ logs_sdk/CHANGELOG.md | 4 ++++ metrics_sdk/CHANGELOG.md | 6 +++++- metrics_sdk/lib/opentelemetry/sdk/metrics/version.rb | 2 +- sdk/CHANGELOG.md | 4 ++++ sdk/lib/opentelemetry/sdk/version.rb | 2 +- test_helpers/CHANGELOG.md | 12 ++++++++---- .../lib/opentelemetry/test_helpers/version.rb | 2 +- 15 files changed, 48 insertions(+), 12 deletions(-) diff --git a/exporter/otlp-logs/CHANGELOG.md b/exporter/otlp-logs/CHANGELOG.md index d1805e9311..ee391a1bd2 100644 --- a/exporter/otlp-logs/CHANGELOG.md +++ b/exporter/otlp-logs/CHANGELOG.md @@ -1 +1,5 @@ # Release History: opentelemetry-exporter-otlp-logs + +### v0.1.0 / 2024-12-04 + +Initial release. diff --git a/exporter/otlp-metrics/CHANGELOG.md b/exporter/otlp-metrics/CHANGELOG.md index 774137ffd4..2151e8eaa9 100644 --- a/exporter/otlp-metrics/CHANGELOG.md +++ b/exporter/otlp-metrics/CHANGELOG.md @@ -1,6 +1,10 @@ # Release History: opentelemetry-exporter-otlp-metrics -### v0.2.0 / 2024-11-19 +### v0.2.1 / 2024-12-04 + +* FIXED: Handle float value in NumberDataPoint + +### v0.2.0 / 2024-11-20 * ADDED: Add basic metrics view * FIXED: Remove Metrics OTLP exporter `Util#measure_request_duration` and duplicate files diff --git a/exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics/version.rb b/exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics/version.rb index 9e526448a6..4dd459fd6d 100644 --- a/exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics/version.rb +++ b/exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics/version.rb @@ -9,7 +9,7 @@ module Exporter module OTLP module Metrics ## Current OpenTelemetry OTLP exporter version - VERSION = '0.2.0' + VERSION = '0.2.1' end end end diff --git a/exporter/otlp/CHANGELOG.md b/exporter/otlp/CHANGELOG.md index bd86c03135..4f5dfd7702 100644 --- a/exporter/otlp/CHANGELOG.md +++ b/exporter/otlp/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History: opentelemetry-exporter-otlp +### v0.29.1 / 2024-12-04 + +* FIXED: Remove WRITE_TIMEOUT_SUPPORTED + ### v0.29.0 / 2024-08-27 * ADDED: Add support for mutual TLS. diff --git a/exporter/otlp/lib/opentelemetry/exporter/otlp/version.rb b/exporter/otlp/lib/opentelemetry/exporter/otlp/version.rb index fd37180664..387c9767af 100644 --- a/exporter/otlp/lib/opentelemetry/exporter/otlp/version.rb +++ b/exporter/otlp/lib/opentelemetry/exporter/otlp/version.rb @@ -8,7 +8,7 @@ module OpenTelemetry module Exporter module OTLP ## Current OpenTelemetry OTLP exporter version - VERSION = '0.29.0' + VERSION = '0.29.1' end end end diff --git a/exporter/zipkin/CHANGELOG.md b/exporter/zipkin/CHANGELOG.md index ced4945479..2edf12753b 100644 --- a/exporter/zipkin/CHANGELOG.md +++ b/exporter/zipkin/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History: opentelemetry-exporter-zipkin +### v0.23.2 / 2024-12-04 + +* FIXED: Remove WRITE_TIMEOUT_SUPPORTED + ### v0.23.1 / 2024-02-06 * FIXED: Require csv for ruby-3.4 compatibility diff --git a/exporter/zipkin/lib/opentelemetry/exporter/zipkin/version.rb b/exporter/zipkin/lib/opentelemetry/exporter/zipkin/version.rb index 380f61d940..f8d084a794 100644 --- a/exporter/zipkin/lib/opentelemetry/exporter/zipkin/version.rb +++ b/exporter/zipkin/lib/opentelemetry/exporter/zipkin/version.rb @@ -8,7 +8,7 @@ module OpenTelemetry module Exporter module Zipkin ## Current OpenTelemetry Zipkin exporter version - VERSION = '0.23.1' + VERSION = '0.23.2' end end end diff --git a/logs_api/CHANGELOG.md b/logs_api/CHANGELOG.md index 5a2fa37308..a3128fc2b5 100644 --- a/logs_api/CHANGELOG.md +++ b/logs_api/CHANGELOG.md @@ -1 +1,5 @@ # Release History: opentelemetry-logs-api + +### v0.1.0 / 2024-12-04 + +Initial release. diff --git a/logs_sdk/CHANGELOG.md b/logs_sdk/CHANGELOG.md index 7fb1a4db06..a06779fefc 100644 --- a/logs_sdk/CHANGELOG.md +++ b/logs_sdk/CHANGELOG.md @@ -1 +1,5 @@ # Release History: opentelemetry-logs-sdk + +### v0.1.0 / 2024-12-04 + +Initial release. diff --git a/metrics_sdk/CHANGELOG.md b/metrics_sdk/CHANGELOG.md index 6a6ffa15ea..57e69fb906 100644 --- a/metrics_sdk/CHANGELOG.md +++ b/metrics_sdk/CHANGELOG.md @@ -1,6 +1,10 @@ # Release History: opentelemetry-metrics-sdk -### v0.4.0 / 2024-11-19 +### v0.4.1 / 2024-12-04 + +* FIXED: Handle float value in NumberDataPoint + +### v0.4.0 / 2024-11-20 * ADDED: Update metrics configuration patch diff --git a/metrics_sdk/lib/opentelemetry/sdk/metrics/version.rb b/metrics_sdk/lib/opentelemetry/sdk/metrics/version.rb index 0256af7fa4..c33a284e94 100644 --- a/metrics_sdk/lib/opentelemetry/sdk/metrics/version.rb +++ b/metrics_sdk/lib/opentelemetry/sdk/metrics/version.rb @@ -8,7 +8,7 @@ module OpenTelemetry module SDK module Metrics # Current OpenTelemetry metrics sdk version - VERSION = '0.4.0' + VERSION = '0.4.1' end end end diff --git a/sdk/CHANGELOG.md b/sdk/CHANGELOG.md index a832c5ed8a..2157ef9359 100644 --- a/sdk/CHANGELOG.md +++ b/sdk/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History: opentelemetry-sdk +### v1.6.0 / 2024-12-04 + +* ADDED: Add hooks to configure logs + ### v1.5.0 / 2024-07-24 * ADDED: Add add_link to span api/sdk diff --git a/sdk/lib/opentelemetry/sdk/version.rb b/sdk/lib/opentelemetry/sdk/version.rb index bdc6d2eacd..87183d988e 100644 --- a/sdk/lib/opentelemetry/sdk/version.rb +++ b/sdk/lib/opentelemetry/sdk/version.rb @@ -7,6 +7,6 @@ module OpenTelemetry module SDK ## Current OpenTelemetry version - VERSION = '1.5.0' + VERSION = '1.6.0' end end diff --git a/test_helpers/CHANGELOG.md b/test_helpers/CHANGELOG.md index 75e407ff49..06db8bff75 100644 --- a/test_helpers/CHANGELOG.md +++ b/test_helpers/CHANGELOG.md @@ -1,18 +1,22 @@ # Release History: opentelemetry-test-helpers +### v0.5.0 / 2024-12-04 + +* ADDED: Add OTLP Log Record Exporter + ### v0.4.0 / 2023-06-08 -* BREAKING CHANGE: Remove support for EoL Ruby 2.7 +* BREAKING CHANGE: Remove support for EoL Ruby 2.7 -* ADDED: Remove support for EoL Ruby 2.7 +* ADDED: Remove support for EoL Ruby 2.7 ### v0.3.0 / 2022-09-14 -* ADDED: Support InstrumentationScope, and update OTLP proto to 0.18.0 +* ADDED: Support InstrumentationScope, and update OTLP proto to 0.18.0 ### v0.2.0 / 2022-06-09 -* ADDED: Otlp grpc +* ADDED: Otlp grpc ### v0.1.0 / 2022-04-22 diff --git a/test_helpers/lib/opentelemetry/test_helpers/version.rb b/test_helpers/lib/opentelemetry/test_helpers/version.rb index d660b3d923..4694004d50 100644 --- a/test_helpers/lib/opentelemetry/test_helpers/version.rb +++ b/test_helpers/lib/opentelemetry/test_helpers/version.rb @@ -7,6 +7,6 @@ module OpenTelemetry ## Current OpenTelemetry Test Helpers version module TestHelpers - VERSION = '0.4.0' + VERSION = '0.5.0' end end From bb5159598850b42e9da54608a8af2fbe422193b7 Mon Sep 17 00:00:00 2001 From: Xuan <112967240+xuan-cao-swi@users.noreply.github.com> Date: Tue, 10 Dec 2024 15:23:31 -0500 Subject: [PATCH 4/7] feat: add synchronous gauge (#1718) * feat: add gauge * Update metrics_api/lib/opentelemetry/metrics/instrument/gauge.rb Co-authored-by: Kayla Reopelle <87386821+kaylareopelle@users.noreply.github.com> * Update metrics_api/lib/opentelemetry/metrics/instrument/gauge.rb Co-authored-by: Kayla Reopelle <87386821+kaylareopelle@users.noreply.github.com> * Update metrics_api/lib/opentelemetry/metrics/instrument/gauge.rb Co-authored-by: Kayla Reopelle <87386821+kaylareopelle@users.noreply.github.com> * Update metrics_sdk/lib/opentelemetry/sdk/metrics/instrument/gauge.rb Co-authored-by: Kayla Reopelle <87386821+kaylareopelle@users.noreply.github.com> * Update metrics_sdk/lib/opentelemetry/sdk/metrics/instrument/gauge.rb Co-authored-by: Kayla Reopelle <87386821+kaylareopelle@users.noreply.github.com> * Update metrics_sdk/lib/opentelemetry/sdk/metrics/instrument/gauge.rb Co-authored-by: Kayla Reopelle <87386821+kaylareopelle@users.noreply.github.com> * Update metrics_sdk/lib/opentelemetry/sdk/metrics/instrument/gauge.rb Co-authored-by: Kayla Reopelle <87386821+kaylareopelle@users.noreply.github.com> * create gauge api doc * change aggr to last value and update test * Update metrics_sdk/lib/opentelemetry/sdk/metrics/instrument/gauge.rb Co-authored-by: Kayla Reopelle <87386821+kaylareopelle@users.noreply.github.com> * update test name --------- Co-authored-by: Kayla Reopelle <87386821+kaylareopelle@users.noreply.github.com> --- .../internal/proxy_instrument.rb | 2 +- .../lib/opentelemetry/internal/proxy_meter.rb | 1 + .../lib/opentelemetry/metrics/instrument.rb | 1 + .../opentelemetry/metrics/instrument/gauge.rb | 23 ++++++++ .../lib/opentelemetry/metrics/meter.rb | 23 +++++++- .../opentelemetry/sdk/metrics/instrument.rb | 1 + .../sdk/metrics/instrument/gauge.rb | 47 +++++++++++++++ .../lib/opentelemetry/sdk/metrics/meter.rb | 1 + .../sdk/metrics/instrument/gauge_test.rb | 58 +++++++++++++++++++ 9 files changed, 155 insertions(+), 2 deletions(-) create mode 100644 metrics_api/lib/opentelemetry/metrics/instrument/gauge.rb create mode 100644 metrics_sdk/lib/opentelemetry/sdk/metrics/instrument/gauge.rb create mode 100644 metrics_sdk/test/opentelemetry/sdk/metrics/instrument/gauge_test.rb diff --git a/metrics_api/lib/opentelemetry/internal/proxy_instrument.rb b/metrics_api/lib/opentelemetry/internal/proxy_instrument.rb index 117a400778..124b434f06 100644 --- a/metrics_api/lib/opentelemetry/internal/proxy_instrument.rb +++ b/metrics_api/lib/opentelemetry/internal/proxy_instrument.rb @@ -19,7 +19,7 @@ def initialize(kind, name, unit, desc, callable) def upgrade_with(meter) @delegate = case @kind - when :counter, :histogram, :up_down_counter + when :counter, :histogram, :up_down_counter, :gauge meter.send("create_#{@kind}", @name, unit: @unit, description: @desc) when :observable_counter, :observable_gauge, :observable_up_down_counter meter.send("create_#{@kind}", @name, unit: @unit, description: @desc, callback: @callback) diff --git a/metrics_api/lib/opentelemetry/internal/proxy_meter.rb b/metrics_api/lib/opentelemetry/internal/proxy_meter.rb index 74d497c684..9f44b4bb67 100644 --- a/metrics_api/lib/opentelemetry/internal/proxy_meter.rb +++ b/metrics_api/lib/opentelemetry/internal/proxy_meter.rb @@ -45,6 +45,7 @@ def create_instrument(kind, name, unit, description, callback) case kind when :counter then @delegate.create_counter(name, unit: unit, description: description) when :histogram then @delegate.create_histogram(name, unit: unit, description: description) + when :gauge then @delegate.create_gauge(name, unit: unit, description: description) when :up_down_counter then @delegate.create_up_down_counter(name, unit: unit, description: description) when :observable_counter then @delegate.create_observable_counter(name, unit: unit, description: description, callback: callback) when :observable_gauge then @delegate.create_observable_gauge(name, unit: unit, description: description, callback: callback) diff --git a/metrics_api/lib/opentelemetry/metrics/instrument.rb b/metrics_api/lib/opentelemetry/metrics/instrument.rb index 3782a8420c..b40f31bc2d 100644 --- a/metrics_api/lib/opentelemetry/metrics/instrument.rb +++ b/metrics_api/lib/opentelemetry/metrics/instrument.rb @@ -6,6 +6,7 @@ require 'opentelemetry/metrics/instrument/counter' require 'opentelemetry/metrics/instrument/histogram' +require 'opentelemetry/metrics/instrument/gauge' require 'opentelemetry/metrics/instrument/observable_counter' require 'opentelemetry/metrics/instrument/observable_gauge' require 'opentelemetry/metrics/instrument/observable_up_down_counter' diff --git a/metrics_api/lib/opentelemetry/metrics/instrument/gauge.rb b/metrics_api/lib/opentelemetry/metrics/instrument/gauge.rb new file mode 100644 index 0000000000..6e65f94946 --- /dev/null +++ b/metrics_api/lib/opentelemetry/metrics/instrument/gauge.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + +module OpenTelemetry + module Metrics + module Instrument + # No-op implementation of Gauge. + class Gauge + # Record the current value for the Gauge + # + # @param [Numeric] amount The current absolute value. + # @param [Hash{String => String, Numeric, Boolean, Array}] attributes + # Values must be non-nil and (array of) string, boolean or numeric type. + # Array values must not contain nil elements and all elements must be of + # the same basic type (string, numeric, boolean). + def record(amount, attributes: {}); end + end + end + end +end diff --git a/metrics_api/lib/opentelemetry/metrics/meter.rb b/metrics_api/lib/opentelemetry/metrics/meter.rb index f44b586110..7bfc1e498a 100644 --- a/metrics_api/lib/opentelemetry/metrics/meter.rb +++ b/metrics_api/lib/opentelemetry/metrics/meter.rb @@ -11,11 +11,14 @@ class Meter COUNTER = Instrument::Counter.new OBSERVABLE_COUNTER = Instrument::ObservableCounter.new HISTOGRAM = Instrument::Histogram.new + GAUGE = Instrument::Gauge.new OBSERVABLE_GAUGE = Instrument::ObservableGauge.new UP_DOWN_COUNTER = Instrument::UpDownCounter.new OBSERVABLE_UP_DOWN_COUNTER = Instrument::ObservableUpDownCounter.new - private_constant(:COUNTER, :OBSERVABLE_COUNTER, :HISTOGRAM, :OBSERVABLE_GAUGE, :UP_DOWN_COUNTER, :OBSERVABLE_UP_DOWN_COUNTER) + NAME_REGEX = /\A[a-zA-Z][-.\w]{0,62}\z/ + + private_constant(:COUNTER, :OBSERVABLE_COUNTER, :HISTOGRAM, :GAUGE, :OBSERVABLE_GAUGE, :UP_DOWN_COUNTER, :OBSERVABLE_UP_DOWN_COUNTER) DuplicateInstrumentError = Class.new(OpenTelemetry::Error) InstrumentNameError = Class.new(OpenTelemetry::Error) @@ -35,6 +38,24 @@ def create_histogram(name, unit: nil, description: nil) create_instrument(:histogram, name, unit, description, nil) { HISTOGRAM } end + # Gauge is an synchronous Instrument which reports non-additive value(s) + # + # With this api call: + # + # meter.create_gauge("cpu.frequency", + # description: "the real-time CPU clock speed", + # unit: "ms") + # + # + # @param name [String] the name of the gauge. + # @param unit [optional String] an optional string provided by user. + # @param description [optional String] an optional free-form text provided by user. + # + # @return [nil] after creation of gauge, it will be stored in instrument_registry + def create_gauge(name, unit: nil, description: nil) + create_instrument(:gauge, name, unit, description, nil) { GAUGE } + end + def create_up_down_counter(name, unit: nil, description: nil) create_instrument(:up_down_counter, name, unit, description, nil) { UP_DOWN_COUNTER } end diff --git a/metrics_sdk/lib/opentelemetry/sdk/metrics/instrument.rb b/metrics_sdk/lib/opentelemetry/sdk/metrics/instrument.rb index c440634c8c..d137cfbdd4 100644 --- a/metrics_sdk/lib/opentelemetry/sdk/metrics/instrument.rb +++ b/metrics_sdk/lib/opentelemetry/sdk/metrics/instrument.rb @@ -20,3 +20,4 @@ module Instrument require 'opentelemetry/sdk/metrics/instrument/observable_gauge' require 'opentelemetry/sdk/metrics/instrument/observable_up_down_counter' require 'opentelemetry/sdk/metrics/instrument/up_down_counter' +require 'opentelemetry/sdk/metrics/instrument/gauge' diff --git a/metrics_sdk/lib/opentelemetry/sdk/metrics/instrument/gauge.rb b/metrics_sdk/lib/opentelemetry/sdk/metrics/instrument/gauge.rb new file mode 100644 index 0000000000..1c0e8f2663 --- /dev/null +++ b/metrics_sdk/lib/opentelemetry/sdk/metrics/instrument/gauge.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + +module OpenTelemetry + module SDK + module Metrics + module Instrument + # {Gauge} is the SDK implementation of {OpenTelemetry::Metrics::Gauge}. + class Gauge < OpenTelemetry::SDK::Metrics::Instrument::SynchronousInstrument + # Returns the instrument kind as a Symbol + # + # @return [Symbol] + def instrument_kind + :gauge + end + + # Record the absolute value of the Gauge. + # + # @param [numeric] value The current absolute value. + # @param [Hash{String => String, Numeric, Boolean, Array}] attributes + # Values must be non-nil and (array of) string, boolean or numeric type. + # Array values must not contain nil elements and all elements must be of + # the same basic type (string, numeric, boolean). + def record(value, attributes: {}) + # TODO: When the metrics SDK stabilizes and is merged into the main SDK, + # we can leverage the SDK Internal validation classes to enforce this: + # https://github.com/open-telemetry/opentelemetry-ruby/blob/6bec625ef49004f364457c26263df421526b60d6/sdk/lib/opentelemetry/sdk/internal.rb#L47 + update(value, attributes) + nil + rescue StandardError => e + OpenTelemetry.handle_error(exception: e) + nil + end + + private + + def default_aggregation + OpenTelemetry::SDK::Metrics::Aggregation::LastValue.new + end + end + end + end + end +end diff --git a/metrics_sdk/lib/opentelemetry/sdk/metrics/meter.rb b/metrics_sdk/lib/opentelemetry/sdk/metrics/meter.rb index 1307817ec6..dee8fea8d2 100644 --- a/metrics_sdk/lib/opentelemetry/sdk/metrics/meter.rb +++ b/metrics_sdk/lib/opentelemetry/sdk/metrics/meter.rb @@ -46,6 +46,7 @@ def create_instrument(kind, name, unit, description, callback) case kind when :counter then OpenTelemetry::SDK::Metrics::Instrument::Counter.new(name, unit, description, @instrumentation_scope, @meter_provider) when :observable_counter then OpenTelemetry::SDK::Metrics::Instrument::ObservableCounter.new(name, unit, description, callback, @instrumentation_scope, @meter_provider) + when :gauge then OpenTelemetry::SDK::Metrics::Instrument::Gauge.new(name, unit, description, @instrumentation_scope, @meter_provider) when :histogram then OpenTelemetry::SDK::Metrics::Instrument::Histogram.new(name, unit, description, @instrumentation_scope, @meter_provider) when :observable_gauge then OpenTelemetry::SDK::Metrics::Instrument::ObservableGauge.new(name, unit, description, callback, @instrumentation_scope, @meter_provider) when :up_down_counter then OpenTelemetry::SDK::Metrics::Instrument::UpDownCounter.new(name, unit, description, @instrumentation_scope, @meter_provider) diff --git a/metrics_sdk/test/opentelemetry/sdk/metrics/instrument/gauge_test.rb b/metrics_sdk/test/opentelemetry/sdk/metrics/instrument/gauge_test.rb new file mode 100644 index 0000000000..f3fc5509c6 --- /dev/null +++ b/metrics_sdk/test/opentelemetry/sdk/metrics/instrument/gauge_test.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +# Copyright The OpenTelemetry Authors +# +# SPDX-License-Identifier: Apache-2.0 + +require 'test_helper' + +describe OpenTelemetry::SDK::Metrics::Instrument::Gauge do + let(:metric_exporter) { OpenTelemetry::SDK::Metrics::Export::InMemoryMetricPullExporter.new } + let(:meter) { OpenTelemetry.meter_provider.meter('test') } + let(:gauge) { meter.create_gauge('gauge', unit: 'smidgen', description: 'a small amount of something') } + + before do + reset_metrics_sdk + OpenTelemetry::SDK.configure + OpenTelemetry.meter_provider.add_metric_reader(metric_exporter) + end + + it 'gauge should count -2' do + gauge.record(-2, attributes: { 'foo' => 'bar' }) + metric_exporter.pull + last_snapshot = metric_exporter.metric_snapshots + + _(last_snapshot[0].name).must_equal('gauge') + _(last_snapshot[0].unit).must_equal('smidgen') + _(last_snapshot[0].description).must_equal('a small amount of something') + _(last_snapshot[0].instrumentation_scope.name).must_equal('test') + _(last_snapshot[0].data_points[0].attributes).must_equal('foo' => 'bar') + _(last_snapshot[0].data_points[0].value).must_equal(-2) + _(last_snapshot[0].aggregation_temporality).must_equal(:delta) + end + + it 'gauge should count 1 for last recording' do + gauge.record(-2, attributes: { 'foo' => 'bar' }) + gauge.record(1, attributes: { 'foo' => 'bar' }) + metric_exporter.pull + last_snapshot = metric_exporter.metric_snapshots + + _(last_snapshot.size).must_equal(1) + _(last_snapshot[0].data_points.size).must_equal(1) + _(last_snapshot[0].data_points[0].value).must_equal(1) + end + + it 'separate gauge should record their own last value' do + gauge.record(-2, attributes: { 'foo' => 'bar' }) + gauge.record(1, attributes: { 'foo' => 'bar' }) + gauge2 = meter.create_gauge('gauge2', unit: 'smidgen', description: 'a small amount of something') + gauge2.record(10, attributes: {}) + + metric_exporter.pull + last_snapshot = metric_exporter.metric_snapshots + + _(last_snapshot.size).must_equal(2) + _(last_snapshot[0].data_points[0].value).must_equal(1) + _(last_snapshot[1].data_points[0].value).must_equal(10) + end +end From 035c32ad9791f6200733e087f2ee49e0a615879a Mon Sep 17 00:00:00 2001 From: Kayla Reopelle <87386821+kaylareopelle@users.noreply.github.com> Date: Thu, 12 Dec 2024 17:03:41 -0800 Subject: [PATCH 5/7] chore: Add examples for logs (#1774) * Example with the SDK, demonstrating the env var w/console export * Example without the SDK using OTLP * Example without the SDK using the console --- examples/logs_sdk/logs_console.rb | 31 ++++++++++++++++++++ examples/logs_sdk/logs_console_with_sdk.rb | 31 ++++++++++++++++++++ examples/logs_sdk/logs_otlp.rb | 33 ++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 examples/logs_sdk/logs_console.rb create mode 100644 examples/logs_sdk/logs_console_with_sdk.rb create mode 100644 examples/logs_sdk/logs_otlp.rb diff --git a/examples/logs_sdk/logs_console.rb b/examples/logs_sdk/logs_console.rb new file mode 100644 index 0000000000..b0e6abfe62 --- /dev/null +++ b/examples/logs_sdk/logs_console.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'bundler/inline' + +gemfile(true) do + source 'https://rubygems.org' + + gem 'opentelemetry-logs-api', path: '../../logs_api' + gem 'opentelemetry-logs-sdk', path: '../../logs_sdk' +end + +require 'opentelemetry-logs-sdk' + +# Create a LoggerProvider +logger_provider = OpenTelemetry::SDK::Logs::LoggerProvider.new +# Create a batching processor configured to export to the OTLP exporter +processor = OpenTelemetry::SDK::Logs::Export::SimpleLogRecordProcessor.new(OpenTelemetry::SDK::Logs::Export::ConsoleLogRecordExporter.new) +# Add the processor to the LoggerProvider +logger_provider.add_log_record_processor(processor) +# Access a Logger for your library from your LoggerProvider +logger = logger_provider.logger(name: 'my_app_or_gem', version: '0.1.0') + +# Use your Logger to emit a log record +logger.on_emit( + timestamp: Time.now, + severity_text: 'INFO', + body: 'Thuja plicata', + attributes: { 'cedar' => true }, +) + +logger_provider.shutdown diff --git a/examples/logs_sdk/logs_console_with_sdk.rb b/examples/logs_sdk/logs_console_with_sdk.rb new file mode 100644 index 0000000000..e118118bbe --- /dev/null +++ b/examples/logs_sdk/logs_console_with_sdk.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'bundler/inline' + +gemfile(true) do + source 'https://rubygems.org' + + gem 'opentelemetry-sdk', path: '../../sdk' + gem 'opentelemetry-logs-api', path: '../../logs_api' + gem 'opentelemetry-logs-sdk', path: '../../logs_sdk' +end + +require 'opentelemetry-sdk' +require 'opentelemetry-logs-sdk' + +# Export logs to the console +ENV['OTEL_LOGS_EXPORTER'] = 'console' + +# Configure SDK with defaults, this will apply the OTEL_LOGS_EXPORTER env var +OpenTelemetry::SDK.configure + +# Access a Logger for your library from the LoggerProvider configured by the OpenTelemetry API +logger = OpenTelemetry.logger_provider.logger(name: 'my_app_or_gem', version: '0.1.0') + +# Use your Logger to emit a log record +logger.on_emit( + timestamp: Time.now, + severity_text: 'INFO', + body: 'Thuja plicata', + attributes: { 'cedar' => true }, +) diff --git a/examples/logs_sdk/logs_otlp.rb b/examples/logs_sdk/logs_otlp.rb new file mode 100644 index 0000000000..611bf8d049 --- /dev/null +++ b/examples/logs_sdk/logs_otlp.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +require 'bundler/inline' + +gemfile(true) do + source 'https://rubygems.org' + + gem 'opentelemetry-logs-api', path: '../../logs_api' + gem 'opentelemetry-logs-sdk', path: '../../logs_sdk' + gem 'opentelemetry-exporter-otlp-logs', path: '../../exporter/otlp-logs' +end + +require 'opentelemetry-logs-sdk' +require 'opentelemetry/exporter/otlp_logs' + +# Create a LoggerProvider +logger_provider = OpenTelemetry::SDK::Logs::LoggerProvider.new +# Create a batching processor configured to export to the OTLP exporter +processor = OpenTelemetry::SDK::Logs::Export::BatchLogRecordProcessor.new(OpenTelemetry::Exporter::OTLP::Logs::LogsExporter.new) +# Add the processor to the LoggerProvider +logger_provider.add_log_record_processor(processor) +# Access a Logger for your library from your LoggerProvider +logger = logger_provider.logger(name: 'my_app_or_gem', version: '0.1.0') + +# Use your Logger to emit a log record +logger.on_emit( + timestamp: Time.now, + severity_text: 'INFO', + body: 'Thuja plicata', + attributes: { 'cedar' => true }, +) + +logger_provider.shutdown From 6099f79307adc8f66b4ef0ae0692a18551b11bf1 Mon Sep 17 00:00:00 2001 From: Josh Westbrook Date: Wed, 8 Jan 2025 14:16:01 -0600 Subject: [PATCH 6/7] feat: Gauge metrics exporter encoding (#1780) * feat: Gauge metrics exporter encoding * fix: combine observable_gauge and gauge * fix: rubocop --- .../exporter/otlp/metrics/metrics_exporter.rb | 5 ++-- .../otlp/metrics/metrics_exporter_test.rb | 23 +++++++++++++++++++ exporter/otlp-metrics/test/test_helper.rb | 1 + 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics/metrics_exporter.rb b/exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics/metrics_exporter.rb index 36705bbf7d..d2beac6d53 100644 --- a/exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics/metrics_exporter.rb +++ b/exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics/metrics_exporter.rb @@ -214,18 +214,17 @@ def encode(metrics_data) end # metrics_pb has following type of data: :gauge, :sum, :histogram, :exponential_histogram, :summary - # current metric sdk only implements instrument: :counter -> :sum, :histogram -> :histogram + # current metric sdk only implements instrument: :counter -> :sum, :histogram -> :histogram, :gauge -> :gauge # # metrics [MetricData] def as_otlp_metrics(metrics) case metrics.instrument_kind - when :observable_gauge + when :observable_gauge, :gauge Opentelemetry::Proto::Metrics::V1::Metric.new( name: metrics.name, description: metrics.description, unit: metrics.unit, gauge: Opentelemetry::Proto::Metrics::V1::Gauge.new( - aggregation_temporality: as_otlp_aggregation_temporality(metrics.aggregation_temporality), data_points: metrics.data_points.map do |ndp| number_data_point(ndp) end diff --git a/exporter/otlp-metrics/test/opentelemetry/exporter/otlp/metrics/metrics_exporter_test.rb b/exporter/otlp-metrics/test/opentelemetry/exporter/otlp/metrics/metrics_exporter_test.rb index 6076a80a20..020d0e9a8d 100644 --- a/exporter/otlp-metrics/test/opentelemetry/exporter/otlp/metrics/metrics_exporter_test.rb +++ b/exporter/otlp-metrics/test/opentelemetry/exporter/otlp/metrics/metrics_exporter_test.rb @@ -576,11 +576,16 @@ stub_request(:post, 'http://localhost:4318/v1/metrics').to_return(status: 200) meter_provider.add_metric_reader(exporter) meter = meter_provider.meter('test') + counter = meter.create_counter('test_counter', unit: 'smidgen', description: 'a small amount of something') counter.add(5, attributes: { 'foo' => 'bar' }) histogram = meter.create_histogram('test_histogram', unit: 'smidgen', description: 'a small amount of something') histogram.record(10, attributes: { 'oof' => 'rab' }) + + gauge = meter.create_gauge('test_gauge', unit: 'smidgen', description: 'a small amount of something') + gauge.record(15, attributes: { 'baz' => 'qux' }) + exporter.pull meter_provider.shutdown @@ -644,6 +649,24 @@ ], aggregation_temporality: Opentelemetry::Proto::Metrics::V1::AggregationTemporality::AGGREGATION_TEMPORALITY_DELTA ) + ), + Opentelemetry::Proto::Metrics::V1::Metric.new( + name: 'test_gauge', + description: 'a small amount of something', + unit: 'smidgen', + gauge: Opentelemetry::Proto::Metrics::V1::Gauge.new( + data_points: [ + Opentelemetry::Proto::Metrics::V1::NumberDataPoint.new( + attributes: [ + Opentelemetry::Proto::Common::V1::KeyValue.new(key: 'baz', value: Opentelemetry::Proto::Common::V1::AnyValue.new(string_value: 'qux')) + ], + as_int: 15, + start_time_unix_nano: 1_699_593_427_329_946_585, + time_unix_nano: 1_699_593_427_329_946_586, + exemplars: nil + ) + ] + ) ) ] ) diff --git a/exporter/otlp-metrics/test/test_helper.rb b/exporter/otlp-metrics/test/test_helper.rb index 9fc4466458..4d3e4df6d9 100644 --- a/exporter/otlp-metrics/test/test_helper.rb +++ b/exporter/otlp-metrics/test/test_helper.rb @@ -26,6 +26,7 @@ def collect(start_time, end_time, data_points) OpenTelemetry::SDK::Metrics::Aggregation::Sum.prepend(MockSum) OpenTelemetry::SDK::Metrics::Aggregation::ExplicitBucketHistogram.prepend(MockSum) +OpenTelemetry::SDK::Metrics::Aggregation::LastValue.prepend(MockSum) def create_metrics_data(name: '', description: '', unit: '', instrument_kind: :counter, resource: nil, instrumentation_scope: OpenTelemetry::SDK::InstrumentationScope.new('', 'v0.0.1'), From 1c6004d76b985fb6ad03e30c934036c622e9ae51 Mon Sep 17 00:00:00 2001 From: Xuan <112967240+xuan-cao-swi@users.noreply.github.com> Date: Wed, 8 Jan 2025 15:32:34 -0500 Subject: [PATCH 7/7] docs: use link-inspector (#1790) Co-authored-by: Kayla Reopelle <87386821+kaylareopelle@users.noreply.github.com> --- .github/workflows/ci-markdown-link.yml | 13 ++++++++----- .markdown-link-check.json | 10 ---------- 2 files changed, 8 insertions(+), 15 deletions(-) delete mode 100644 .markdown-link-check.json diff --git a/.github/workflows/ci-markdown-link.yml b/.github/workflows/ci-markdown-link.yml index 7b42be0c1e..626a8fce42 100644 --- a/.github/workflows/ci-markdown-link.yml +++ b/.github/workflows/ci-markdown-link.yml @@ -2,6 +2,8 @@ name: Markdown Link Check on: pull_request: + paths: + - '**/*.md' jobs: markdown-link-check: @@ -9,9 +11,10 @@ jobs: steps: - uses: actions/checkout@v4 - - name: "Markdown Link Check" - uses: gaurav-nelson/github-action-markdown-link-check@v1 + # equivalent cli: linkspector check + - name: Run linkspector + uses: umbrelladocs/action-linkspector@v1 with: - config-file: '.markdown-link-check.json' - use-quiet-mode: 'yes' - use-verbose-mode: 'yes' + github_token: ${{ secrets.GITHUB_TOKEN }} + reporter: github-pr-review + fail_on_error: true diff --git a/.markdown-link-check.json b/.markdown-link-check.json deleted file mode 100644 index 12284d673f..0000000000 --- a/.markdown-link-check.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "ignorePatterns": [ - { - "pattern": "^http://localhost" - } - ], - "timeout": "5s", - "retryOn429": true, - "aliveStatusCodes": [200, 206, 429] -}