-
Notifications
You must be signed in to change notification settings - Fork 554
feat: add support for OTEL_SDK_DISABLED
environment variable
#3088
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
base: main
Are you sure you want to change the base?
feat: add support for OTEL_SDK_DISABLED
environment variable
#3088
Conversation
|
00ed1c4
to
cab02b4
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3088 +/- ##
=======================================
- Coverage 80.1% 79.8% -0.4%
=======================================
Files 126 126
Lines 21957 22078 +121
=======================================
+ Hits 17603 17631 +28
- Misses 4354 4447 +93 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
9fa6e81
to
3231e09
Compare
Since overwriting |
3231e09
to
f587661
Compare
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.
Pull Request Overview
This PR implements support for the OTEL_SDK_DISABLED
environment variable, which allows disabling the OpenTelemetry SDK at runtime. When set to "true", the SDK provides no-op implementations for all telemetry components (Tracer, Logger, and Meter) as specified in the OpenTelemetry specification.
Key changes:
- Adds environment variable checking in all provider types to return no-op implementations when disabled
- Implements separate disabled no-op providers distinct from shutdown no-op providers
- Adds comprehensive test coverage for the new functionality
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
scripts/test.sh | Adds test command for the new environment variable functionality |
opentelemetry-sdk/src/trace/provider.rs | Implements disabled tracer provider and environment variable checking |
opentelemetry-sdk/src/metrics/meter_provider.rs | Adds environment variable checking to meter provider |
opentelemetry-sdk/src/logs/logger_provider.rs | Implements disabled logger provider and environment variable checking |
opentelemetry-sdk/CHANGELOG.md | Documents the new feature addition |
Comments suppressed due to low confidence (2)
opentelemetry-sdk/src/trace/provider.rs:782
- [nitpick] Variable name 'noop_tracer' is misleading since this tests both disabled and enabled scenarios. Consider renaming to 'tracer' or 'test_tracer' for clarity.
let noop_tracer = tracer_provider.tracer("noop");
opentelemetry-sdk/src/trace/provider.rs:804
- [nitpick] Variable name 'noop_tracer' is misleading in this context where OTEL_SDK_DISABLED is set to 'false', meaning the tracer should be functional. Consider renaming to 'tracer' or 'functional_tracer'.
let noop_tracer = tracer_provider.tracer("noop");
scripts/test.sh
Outdated
@@ -20,6 +20,9 @@ cargo test --manifest-path=opentelemetry/Cargo.toml --no-default-features --lib | |||
echo "Running tests for opentelemetry-prometheus with --all-features" | |||
(cd opentelemetry-prometheus && cargo test --all-features --lib) | |||
|
|||
# Run test which set environment variable `` |
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.
The comment has an incomplete sentence and empty quotes. Should be: "Run test which sets environment variable"
# Run test which set environment variable `` | |
# Run test which sets the environment variable `otel_sdk_disabled_env` |
Copilot uses AI. Check for mistakes.
return SdkTracer::new(scope, noop_tracer_provider().clone()); | ||
return SdkTracer::new(scope, shutdown_tracer_provider().clone()); | ||
} | ||
if std::env::var("OTEL_SDK_DISABLED").is_ok_and(|var| var.to_lowercase() == "true") { |
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.
Environment variable is checked on every tracer creation. Consider caching this value or checking it once during provider initialization to avoid repeated environment variable lookups.
Copilot uses AI. Check for mistakes.
@@ -189,7 +189,9 @@ impl MeterProvider for SdkMeterProvider { | |||
} | |||
|
|||
fn meter_with_scope(&self, scope: InstrumentationScope) -> Meter { | |||
if self.inner.shutdown_invoked.load(Ordering::Relaxed) { | |||
if self.inner.shutdown_invoked.load(Ordering::Relaxed) | |||
|| std::env::var("OTEL_SDK_DISABLED").is_ok_and(|var| var.to_lowercase() == "true") |
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.
Environment variable is checked on every meter creation. Consider caching this value or checking it once during provider initialization to avoid repeated environment variable lookups.
Copilot uses AI. Check for mistakes.
return SdkLogger::new(scope, shutdown_logger_provider().clone()); | ||
} | ||
// If the provider is disabled, new logger will refer a disabled no-op logger provider. | ||
if std::env::var("OTEL_SDK_DISABLED").is_ok_and(|var| var.to_lowercase() == "true") { |
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.
Environment variable is checked on every logger creation. Consider caching this value or checking it once during provider initialization to avoid repeated environment variable lookups.
if std::env::var("OTEL_SDK_DISABLED").is_ok_and(|var| var.to_lowercase() == "true") { | |
if self.inner.is_disabled { |
Copilot uses AI. Check for mistakes.
// a no op logger provider used as placeholder when sdk is disabled with | ||
// help of environment variable `OTEL_SDK_DISABLED` | ||
// TODO - replace it with LazyLock once it is stable | ||
static DISABLED_LOGGER_PROVIDER: OnceLock<SdkLoggerProvider> = OnceLock::new(); |
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.
Can we reuse the existing NOOP_LOGGER_PROVIDER for both shutdown and disable ?
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.
setting is_shutdown
as true
also for disabled one have no effect currently but to me true
value looks wrong since logger provider is not in shutdown state but disabled by user so i have created new logger provider
return SdkTracer::new(scope, noop_tracer_provider().clone()); | ||
return SdkTracer::new(scope, shutdown_tracer_provider().clone()); | ||
} | ||
if std::env::var("OTEL_SDK_DISABLED").is_ok_and(|var| var.to_lowercase() == "true") { |
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.
what is the intended use case of "OTEL_SDK_DISABLED" env variable? Are we expected to re-read the env variable each time a tracer/logger/meter is requested? Or we read the env variable once at startup and not again?
It looks like the current PR is re-reading it each time. This can cause inconsistencies- tracers from before will continue to work vs new ones won't.. That is not the intended behavior in my opinion.
My suggestion:
Read the env variable once, at provider construction time, and store the value inside.
Any time tracer/logger/meter is requested, return NoOp if disabled. The log message should indicate NoOp is being returned due to the env-variable setting.
Happy to discuss other ideas.
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.
implemented similar to python implementation open-telemetry/opentelemetry-python#3648 after reading discussion at open-telemetry/opentelemetry-specification#4332
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.
Requesting changes to discuss and address comment: https://github.com/open-telemetry/opentelemetry-rust/pull/3088/files#r2237333415
c990dd7
to
43f4bb0
Compare
Signed-off-by: Saurav Sharma <appdroiddeveloper@gmail.com>
43f4bb0
to
59da472
Compare
Fixes #1936
Changes
Add support for
OTEL_SDK_DISABLED
environment variable using no-op SDK implementation as explained Opentelemetry SDK environment variable docs. When set totrue
, the SDK will provide no-op implementations for all API components (Tracer, Logger, and Meter).Implemented no-op provider classes that mimic the shutdown no-op providers for logger and tracer with only difference is shutdown variable which is set to false for disabled no op. Where as for metrics existing noop is re used
Merge requirement checklist
CHANGELOG.md
files updated for non-trivial, user-facing changes