Skip to content

Commit 559e7a0

Browse files
feat: Add compatibility with env OTEL_SDK_DISABLED (#1773)
* feat: disable SDK with env OTEL_SDK_DISABLED is defined as true * feat: add tests * fix: revert test * feat: fix rubocop * Update sdk/lib/opentelemetry/sdk.rb Co-authored-by: Kayla Reopelle <[email protected]> * feat: add test * fix: fix rubocop --------- Co-authored-by: Kayla Reopelle <[email protected]>
1 parent 19b5fbe commit 559e7a0

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

sdk/lib/opentelemetry/sdk.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ module SDK
6161
# c.use_all
6262
# end
6363
def configure
64+
if ENV['OTEL_SDK_DISABLED'] == 'true'
65+
OpenTelemetry.logger.warn 'Environment variable OTEL_SDK_DISABLED is defined as true. SDK is disabled.'
66+
return
67+
end
68+
6469
configurator = Configurator.new
6570
yield configurator if block_given?
6671
configurator.configure

sdk/test/opentelemetry/sdk_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,13 @@
2727
_(received_message).must_match(/unexpected configuration error due to unknown keyword: .*invalid_option/)
2828
end
2929
end
30+
31+
describe '#configure (sdk disabled)' do
32+
it 'ignore configuration when sdk is disabled by env' do
33+
config = OpenTelemetry::TestHelpers.with_env('OTEL_SDK_DISABLED' => 'true') do
34+
OpenTelemetry::SDK.configure
35+
end
36+
_(config).must_equal nil
37+
end
38+
end
3039
end

0 commit comments

Comments
 (0)