From ffac0371f5609478cf02ebec4dcc49bcaf980589 Mon Sep 17 00:00:00 2001 From: Pedro Furtado Date: Wed, 4 Dec 2024 18:54:50 -0300 Subject: [PATCH 1/7] feat: disable SDK with env OTEL_SDK_DISABLED is defined as true --- sdk/lib/opentelemetry/sdk.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sdk/lib/opentelemetry/sdk.rb b/sdk/lib/opentelemetry/sdk.rb index 8bfde7198e..5c0e720c96 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 From 0b2653dd615a0a0dee72aca44a1b8402c2902653 Mon Sep 17 00:00:00 2001 From: Pedro Furtado Date: Wed, 4 Dec 2024 18:59:59 -0300 Subject: [PATCH 2/7] feat: add tests --- sdk/test/opentelemetry/sdk_test.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sdk/test/opentelemetry/sdk_test.rb b/sdk/test/opentelemetry/sdk_test.rb index f0ad461213..ef37dff046 100644 --- a/sdk/test/opentelemetry/sdk_test.rb +++ b/sdk/test/opentelemetry/sdk_test.rb @@ -27,4 +27,19 @@ _(received_message).must_match(/unexpected configuration error due to unknown keyword: .*invalid_option/) end end + + describe '#configure (no-op)' do + before do + ENV['OTEL_SDK_DISABLED'] = 'true' + end + + after do + ENV.delete('OTEL_SDK_DISABLED') + end + + it 'logs a warning and generate a no-op tracer if env OTEL_SDK_DISABLED is defined' do + tracer = OpenTelemetry::SDK.configure + _(tracer).must_be_instance_of OpenTelemetry::Internal::ProxyTracer + end + end end From 3debcde6a193aea2372b9cd3647a4d1d8ff2911e Mon Sep 17 00:00:00 2001 From: Pedro Furtado Date: Wed, 4 Dec 2024 19:02:01 -0300 Subject: [PATCH 3/7] fix: revert test --- sdk/test/opentelemetry/sdk_test.rb | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/sdk/test/opentelemetry/sdk_test.rb b/sdk/test/opentelemetry/sdk_test.rb index ef37dff046..f0ad461213 100644 --- a/sdk/test/opentelemetry/sdk_test.rb +++ b/sdk/test/opentelemetry/sdk_test.rb @@ -27,19 +27,4 @@ _(received_message).must_match(/unexpected configuration error due to unknown keyword: .*invalid_option/) end end - - describe '#configure (no-op)' do - before do - ENV['OTEL_SDK_DISABLED'] = 'true' - end - - after do - ENV.delete('OTEL_SDK_DISABLED') - end - - it 'logs a warning and generate a no-op tracer if env OTEL_SDK_DISABLED is defined' do - tracer = OpenTelemetry::SDK.configure - _(tracer).must_be_instance_of OpenTelemetry::Internal::ProxyTracer - end - end end From 93d77cb07d0172ab49e74c86b1e9deb22e8ec2ae Mon Sep 17 00:00:00 2001 From: Pedro Furtado Date: Wed, 4 Dec 2024 19:10:57 -0300 Subject: [PATCH 4/7] feat: fix rubocop --- sdk/lib/opentelemetry/sdk.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/lib/opentelemetry/sdk.rb b/sdk/lib/opentelemetry/sdk.rb index 5c0e720c96..fbe5f7f4b4 100644 --- a/sdk/lib/opentelemetry/sdk.rb +++ b/sdk/lib/opentelemetry/sdk.rb @@ -62,7 +62,7 @@ module SDK # end def configure if ENV['OTEL_SDK_DISABLED'] == 'true' - OpenTelemetry.logger.warn "Environment variable OTEL_SDK_DISABLED is defined as true. SDK is disabled" + OpenTelemetry.logger.warn 'Environment variable OTEL_SDK_DISABLED is defined as true. SDK is disabled' return end From 5a7ae6003fcd5b1fc0b7be873de059276a7e1fa8 Mon Sep 17 00:00:00 2001 From: Pedro Furtado Date: Thu, 5 Dec 2024 07:37:32 -0300 Subject: [PATCH 5/7] Update sdk/lib/opentelemetry/sdk.rb Co-authored-by: Kayla Reopelle <87386821+kaylareopelle@users.noreply.github.com> --- sdk/lib/opentelemetry/sdk.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/lib/opentelemetry/sdk.rb b/sdk/lib/opentelemetry/sdk.rb index fbe5f7f4b4..6447f18af5 100644 --- a/sdk/lib/opentelemetry/sdk.rb +++ b/sdk/lib/opentelemetry/sdk.rb @@ -62,7 +62,7 @@ module SDK # end def configure if ENV['OTEL_SDK_DISABLED'] == 'true' - OpenTelemetry.logger.warn 'Environment variable OTEL_SDK_DISABLED is defined as true. SDK is disabled' + OpenTelemetry.logger.warn 'Environment variable OTEL_SDK_DISABLED is defined as true. SDK is disabled.' return end From 3ee1b46b09cb574160f6f79e8f3ce93ce68a043b Mon Sep 17 00:00:00 2001 From: Pedro Furtado Date: Thu, 5 Dec 2024 07:50:00 -0300 Subject: [PATCH 6/7] feat: add test --- sdk/test/opentelemetry/sdk_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sdk/test/opentelemetry/sdk_test.rb b/sdk/test/opentelemetry/sdk_test.rb index f0ad461213..31e20bc9ea 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 From 7bbf5c166e6adee8d1b28442486f59963a8bcc4f Mon Sep 17 00:00:00 2001 From: Pedro Furtado Date: Thu, 5 Dec 2024 11:15:53 -0300 Subject: [PATCH 7/7] fix: fix rubocop --- sdk/test/opentelemetry/sdk_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/test/opentelemetry/sdk_test.rb b/sdk/test/opentelemetry/sdk_test.rb index 31e20bc9ea..a7f65eb9a6 100644 --- a/sdk/test/opentelemetry/sdk_test.rb +++ b/sdk/test/opentelemetry/sdk_test.rb @@ -31,7 +31,7 @@ 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 + OpenTelemetry::SDK.configure end _(config).must_equal nil end