-
Notifications
You must be signed in to change notification settings - Fork 239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Update metrics configuration patch #1548
Open
kaylareopelle
wants to merge
6
commits into
open-telemetry:main
Choose a base branch
from
kaylareopelle:update-configuration-patch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+171
−3
Open
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8ec788b
feat: Add configuration patch to set metrics exporter by environment …
kaylareopelle 6d42d46
Merge branch 'main' into update-configuration-patch
kaylareopelle 4141e17
fix: Use updated class name for OTLP exporter
kaylareopelle 876bb81
Merge remote-tracking branch 'upstream/main' into update-configuratio…
kaylareopelle 52921b0
feat: Update config patch for spec compliance
kaylareopelle b3de60f
test: Remove setup/teardown tracer env var setting
kaylareopelle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
metrics_sdk/test/opentelemetry/sdk/metrics/configuration_patch_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
require 'test_helper' | ||
|
||
describe OpenTelemetry::SDK::Metrics::ConfiguratorPatch do | ||
let(:configurator) { OpenTelemetry::SDK::Configurator.new } | ||
let(:default_resource_attributes) do | ||
{ | ||
'telemetry.sdk.name' => 'opentelemetry', | ||
'telemetry.sdk.language' => 'ruby', | ||
'telemetry.sdk.version' => OpenTelemetry::SDK::VERSION, | ||
'process.pid' => Process.pid, | ||
'process.command' => $PROGRAM_NAME, | ||
'process.runtime.name' => RUBY_ENGINE, | ||
'process.runtime.version' => RUBY_VERSION, | ||
'process.runtime.description' => RUBY_DESCRIPTION, | ||
'service.name' => 'unknown_service' | ||
} | ||
end | ||
|
||
def setup | ||
# Suppress log warnings about trace exporter absence | ||
ENV['OTEL_TRACES_EXPORTER'] = 'none' | ||
end | ||
|
||
def teardown | ||
# Let the settings go back to their default | ||
ENV['OTEL_TRACES_EXPORTER'] = nil | ||
end | ||
|
||
describe '#configure' do | ||
describe 'meter_provider' do | ||
it 'is an instance of SDK::Metrics::MeterProvider' do | ||
configurator.configure | ||
|
||
_(OpenTelemetry.meter_provider).must_be_instance_of( | ||
OpenTelemetry::SDK::Metrics::MeterProvider | ||
) | ||
end | ||
end | ||
|
||
describe 'metric readers' do | ||
it 'defaults to the console reader' do | ||
configurator.configure | ||
|
||
assert_equal 1, OpenTelemetry.meter_provider.metric_readers.size | ||
assert_instance_of OpenTelemetry::SDK::Metrics::Export::ConsoleMetricPullExporter, OpenTelemetry.meter_provider.metric_readers[0] | ||
end | ||
|
||
it 'can be set by environment variable' do | ||
OpenTelemetry::TestHelpers.with_env('OTEL_METRICS_EXPORTER' => 'in-memory') do | ||
configurator.configure | ||
end | ||
|
||
assert_equal 1, OpenTelemetry.meter_provider.metric_readers.size | ||
assert_instance_of OpenTelemetry::SDK::Metrics::Export::InMemoryMetricPullExporter, OpenTelemetry.meter_provider.metric_readers[0] | ||
end | ||
|
||
it 'supports "none" as an environment variable' do | ||
OpenTelemetry::TestHelpers.with_test_logger do |log_stream| | ||
OpenTelemetry::TestHelpers.with_env('OTEL_METRICS_EXPORTER' => 'none') do | ||
configurator.configure | ||
end | ||
|
||
assert_empty OpenTelemetry.meter_provider.metric_readers | ||
|
||
refute_match(/The none exporter is unknown and cannot be configured/, log_stream.string) | ||
end | ||
end | ||
|
||
it 'supports multiple exporters passed by environment variable' do | ||
OpenTelemetry::TestHelpers.with_env('OTEL_METRICS_EXPORTER' => 'in-memory,console') do | ||
configurator.configure | ||
end | ||
|
||
assert_equal 2, OpenTelemetry.meter_provider.metric_readers.size | ||
assert_instance_of OpenTelemetry::SDK::Metrics::Export::InMemoryMetricPullExporter, OpenTelemetry.meter_provider.metric_readers[0] | ||
assert_instance_of OpenTelemetry::SDK::Metrics::Export::ConsoleMetricPullExporter, OpenTelemetry.meter_provider.metric_readers[1] | ||
end | ||
|
||
it 'defaults to noop with invalid env var' do | ||
OpenTelemetry::TestHelpers.with_test_logger do |log_stream| | ||
OpenTelemetry::TestHelpers.with_env('OTEL_METRICS_EXPORTER' => 'unladen_swallow') do | ||
configurator.configure | ||
end | ||
|
||
assert_empty OpenTelemetry.meter_provider.metric_readers | ||
assert_match(/The unladen_swallow exporter is unknown and cannot be configured/, log_stream.string) | ||
end | ||
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::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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mwear @xuan-cao-swi - The specs state that OTLP should be the default exporter or
OTEL_METRICS_EXPORTER
, so I updated the tests to reflect this and installed the OTLP exporter in the test group of the Gemile.However, the OTLP exporter brings in the protobuf dependencies, making the entire metrics_sdk test suite incompatible with JRuby.
It seems like the tracing test suite gets around this by avoiding any mention of the OTLP exporter in the tests, even though the spec also expects OTLP to be the default exporter for that signal (the tests use zipkin instead).
I don't want to skip JRuby for all tests in the metrics_sdk.
My current thoughts for solutions are:
What do y'all think would be the best next step?