Skip to content

Commit

Permalink
test: Update tests for JRuby
Browse files Browse the repository at this point in the history
  • Loading branch information
kaylareopelle committed Oct 29, 2024
1 parent 9876ed6 commit 94b71b0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion metrics_sdk/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ gem 'opentelemetry-sdk', path: '../sdk'
gem 'opentelemetry-test-helpers', path: '../test_helpers'

group :test, :development do
gem 'opentelemetry-exporter-otlp-metrics', path: '../exporter/otlp-metrics'
gem 'opentelemetry-exporter-otlp-metrics', path: '../exporter/otlp-metrics' unless RUBY_ENGINE == 'jruby'
gem 'pry'
gem 'pry-byebug' unless RUBY_ENGINE == 'jruby'
end
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def wrapped_metric_exporters_from_env
exporter: Metrics::Export::ConsoleMetricPullExporter.new
)
)
when 'in-memory'
OpenTelemetry.meter_provider.add_metric_reader(Metrics::Export::InMemoryMetricPullExporter.new)
when 'otlp'
begin
OpenTelemetry.meter_provider.add_metric_reader(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# SPDX-License-Identifier: Apache-2.0

require 'test_helper'
require 'opentelemetry-exporter-otlp-metrics'
require 'opentelemetry-exporter-otlp-metrics' unless RUBY_ENGINE == 'jruby'

describe OpenTelemetry::SDK::Metrics::ConfiguratorPatch do
let(:configurator) { OpenTelemetry::SDK::Configurator.new }
Expand Down Expand Up @@ -36,6 +36,8 @@

describe 'metric readers' do
it 'defaults to a periodic reader with an otlp exporter' do
skip 'OTLP exporter not compatible with JRuby' if RUBY_ENGINE == 'jruby'

configurator.configure

assert_equal 1, OpenTelemetry.meter_provider.metric_readers.size
Expand Down Expand Up @@ -71,7 +73,7 @@
end

it 'supports multiple exporters passed by environment variable' do
OpenTelemetry::TestHelpers.with_env('OTEL_METRICS_EXPORTER' => 'otlp,console') do
OpenTelemetry::TestHelpers.with_env('OTEL_METRICS_EXPORTER' => 'console,in-memory') do
configurator.configure
end

Expand All @@ -81,10 +83,9 @@
reader2 = OpenTelemetry.meter_provider.metric_readers[1]

assert_instance_of OpenTelemetry::SDK::Metrics::Export::PeriodicMetricReader, reader1
assert_instance_of OpenTelemetry::Exporter::OTLP::Metrics::MetricsExporter, reader1.instance_variable_get(:@exporter)
assert_instance_of OpenTelemetry::SDK::Metrics::Export::ConsoleMetricPullExporter, reader1.instance_variable_get(:@exporter)

assert_instance_of OpenTelemetry::SDK::Metrics::Export::PeriodicMetricReader, reader2
assert_instance_of OpenTelemetry::SDK::Metrics::Export::ConsoleMetricPullExporter, reader2.instance_variable_get(:@exporter)
assert_instance_of OpenTelemetry::SDK::Metrics::Export::InMemoryMetricPullExporter, reader2
end

it 'defaults to noop with invalid env var' do
Expand All @@ -99,15 +100,26 @@
end

it 'rescues NameErrors when otlp set to env var and the library is not installed' do
OpenTelemetry::TestHelpers.with_test_logger do |log_stream|
OpenTelemetry::Exporter::OTLP::Metrics::MetricsExporter.stub(:new, -> { raise NameError }) do
if RUBY_ENGINE == 'jruby'
OpenTelemetry::TestHelpers.with_test_logger do |log_stream|
OpenTelemetry::TestHelpers.with_env('OTEL_METRICS_EXPORTER' => 'otlp') do
configurator.configure
end

assert_empty OpenTelemetry.meter_provider.metric_readers
assert_match(/The otlp metrics exporter cannot be configured - please add opentelemetry-exporter-otlp-metrics to your Gemfile, metrics will not be exported/, log_stream.string)
end
else
OpenTelemetry::TestHelpers.with_test_logger do |log_stream|
OpenTelemetry::Exporter::OTLP::Metrics::MetricsExporter.stub(:new, -> { raise NameError }) do
OpenTelemetry::TestHelpers.with_env('OTEL_METRICS_EXPORTER' => 'otlp') do
configurator.configure
end

assert_empty OpenTelemetry.meter_provider.metric_readers
assert_match(/The otlp metrics exporter cannot be configured - please add opentelemetry-exporter-otlp-metrics to your Gemfile, metrics will not be exported/, log_stream.string)
end
end
end
end
end
Expand Down

0 comments on commit 94b71b0

Please sign in to comment.