Skip to content

Commit

Permalink
feat: Add compatibility with env OTEL_SDK_DISABLED (#1773)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
pedrofurtado and kaylareopelle authored Jan 31, 2025
1 parent 19b5fbe commit 559e7a0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sdk/lib/opentelemetry/sdk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions sdk/test/opentelemetry/sdk_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 559e7a0

Please sign in to comment.