diff --git a/sdk/lib/opentelemetry/sdk.rb b/sdk/lib/opentelemetry/sdk.rb index 8bfde7198e..6447f18af5 100644 --- a/sdk/lib/opentelemetry/sdk.rb +++ b/sdk/lib/opentelemetry/sdk.rb @@ -61,6 +61,11 @@ module SDK # c.use_all # end def configure + if ENV['OTEL_SDK_DISABLED'] == 'true' + OpenTelemetry.logger.warn 'Environment variable OTEL_SDK_DISABLED is defined as true. SDK is disabled.' + return + end + configurator = Configurator.new yield configurator if block_given? configurator.configure diff --git a/sdk/test/opentelemetry/sdk_test.rb b/sdk/test/opentelemetry/sdk_test.rb index f0ad461213..a7f65eb9a6 100644 --- a/sdk/test/opentelemetry/sdk_test.rb +++ b/sdk/test/opentelemetry/sdk_test.rb @@ -27,4 +27,13 @@ _(received_message).must_match(/unexpected configuration error due to unknown keyword: .*invalid_option/) end end + + describe '#configure (sdk disabled)' do + it 'ignore configuration when sdk is disabled by env' do + config = OpenTelemetry::TestHelpers.with_env('OTEL_SDK_DISABLED' => 'true') do + OpenTelemetry::SDK.configure + end + _(config).must_equal nil + end + end end