Skip to content

feat: add support for OTEL_SDK_DISABLED environment variable#3088

Open
iamsauravsharma wants to merge 2 commits into
open-telemetry:mainfrom
iamsauravsharma:add-env-otel-sdk-disabled
Open

feat: add support for OTEL_SDK_DISABLED environment variable#3088
iamsauravsharma wants to merge 2 commits into
open-telemetry:mainfrom
iamsauravsharma:add-env-otel-sdk-disabled

Conversation

@iamsauravsharma

@iamsauravsharma iamsauravsharma commented Jul 28, 2025

Copy link
Copy Markdown

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 to true, 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

  • CONTRIBUTING guidelines followed
  • Unit tests added/updated (if applicable)
  • Appropriate CHANGELOG.md files updated for non-trivial, user-facing changes
  • Changes in public API reviewed (if applicable)

@iamsauravsharma iamsauravsharma requested a review from a team as a code owner July 28, 2025 12:14
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jul 28, 2025

Copy link
Copy Markdown

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: iamsauravsharma / name: Saurav Sharma (9f2f400)

@iamsauravsharma iamsauravsharma force-pushed the add-env-otel-sdk-disabled branch from 00ed1c4 to cab02b4 Compare July 28, 2025 12:15
@codecov

codecov Bot commented Jul 28, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 42.94118% with 97 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.7%. Comparing base (74cb6f3) to head (4e437db).

Files with missing lines Patch % Lines
opentelemetry-sdk/src/logs/logger_provider.rs 18.7% 39 Missing ⚠️
opentelemetry-sdk/src/trace/provider.rs 40.0% 36 Missing ⚠️
opentelemetry-sdk/src/metrics/meter_provider.rs 29.1% 17 Missing ⚠️
opentelemetry-sdk/src/logs/logger.rs 50.0% 3 Missing ⚠️
opentelemetry-sdk/src/trace/span.rs 96.1% 1 Missing ⚠️
opentelemetry-sdk/src/trace/tracer.rs 83.3% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main   #3088     +/-   ##
=======================================
- Coverage   83.0%   82.7%   -0.3%     
=======================================
  Files        130     130             
  Lines      27993   28121    +128     
=======================================
+ Hits       23250   23275     +25     
- Misses      4743    4846    +103     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@iamsauravsharma iamsauravsharma force-pushed the add-env-otel-sdk-disabled branch 2 times, most recently from 9fa6e81 to 3231e09 Compare July 28, 2025 14:17
@iamsauravsharma

iamsauravsharma commented Jul 28, 2025

Copy link
Copy Markdown
Author

Since overwriting OTEL_SDK_DISABLED environment variable would effects other test when running parallel test. 3 new test are ignored by default and scripts/test.sh is updated so 3 test run themselves in last step

@iamsauravsharma iamsauravsharma force-pushed the add-env-otel-sdk-disabled branch from 3231e09 to f587661 Compare July 28, 2025 14:48
@lalitb lalitb requested a review from Copilot July 28, 2025 15:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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");

Comment thread scripts/test.sh Outdated
Comment thread opentelemetry-sdk/src/trace/provider.rs Outdated
Comment thread opentelemetry-sdk/src/metrics/meter_provider.rs Outdated
Comment thread opentelemetry-sdk/src/logs/logger_provider.rs Outdated
// 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();

Copy link
Copy Markdown
Member

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 ?

@iamsauravsharma iamsauravsharma Jul 29, 2025

Copy link
Copy Markdown
Author

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

Comment thread opentelemetry-sdk/src/trace/provider.rs Outdated
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") {

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Author

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

@cijothomas cijothomas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamsauravsharma iamsauravsharma force-pushed the add-env-otel-sdk-disabled branch 3 times, most recently from 43f4bb0 to 59da472 Compare August 2, 2025 09:28
@iamsauravsharma iamsauravsharma force-pushed the add-env-otel-sdk-disabled branch from 59da472 to 267a3cc Compare August 5, 2025 03:29
@iamsauravsharma

Copy link
Copy Markdown
Author

Implemented some changes as requested

@iamsauravsharma

Copy link
Copy Markdown
Author

@cijothomas @lalitb just a reminder about this PR. I’ve pushed the requested changes or replied with my reasoning. could you please take another look?

return Meter::new(Arc::new(NoopMeter::new()));
}
if self.inner.is_disabled {
otel_warn!(name: "MeterProvider.NoOpMeterReturned", message = "Returned NoOpMeter. SDK is disabled");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
otel_warn!(name: "MeterProvider.NoOpMeterReturned", message = "Returned NoOpMeter. SDK is disabled");
otel_debug!(name: "MeterProvider.NoOpMeterReturned", message = "Returned NoOpMeter. SDK is disabled");

}
// If the provider is disabled, new logger will refer a disabled no-op logger provider.
if self.inner.is_disabled {
otel_warn!(name: "LoggerProvider.NoOpLoggerReturned", message = "Returned NoOpLogger. SDK is disabled");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets use consistent logging as shutdown case.

@iamsauravsharma iamsauravsharma force-pushed the add-env-otel-sdk-disabled branch from de4bc9d to a651d6b Compare November 1, 2025 02:47

@iamsauravsharma iamsauravsharma left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cijothomas I have implemented changes suggested with some comment below

if self.inner.is_shutdown.load(Ordering::Relaxed) {
otel_debug!(
name: "LoggerProvider.NoOpLoggerReturned",
name: "LoggerProvider.ShutdownNoOpLoggerReturned",

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have renamed old NoOpLoggerReturned to ShutdownNoOpLoggerReturned should i change it back to original name. Renamed so we can distinguish between shutdown and disabled case

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can keep the original name for this and for the env_variable disabled scenario both. Just add another attribute "reason", with value being "already_shutdown" and "disabled_via_env_variable".

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have used original name and added reason attribute

std::env::var("OTEL_SDK_DISABLED").is_ok_and(|var| var.to_lowercase() == "true");

if is_disabled {
otel_warn!(name: "LoggerProvider.Disabled", message = "SDK is disabled through environment variable");

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using warn! here since reference python implementation also used warn

@iamsauravsharma iamsauravsharma force-pushed the add-env-otel-sdk-disabled branch from a651d6b to 0399473 Compare November 2, 2025 02:25
@iamsauravsharma iamsauravsharma force-pushed the add-env-otel-sdk-disabled branch from 0399473 to 2054054 Compare November 22, 2025 04:46
@iamsauravsharma iamsauravsharma force-pushed the add-env-otel-sdk-disabled branch from 2054054 to e2eb5fb Compare December 22, 2025 03:04
@iamsauravsharma iamsauravsharma force-pushed the add-env-otel-sdk-disabled branch 3 times, most recently from 55fe116 to 597858c Compare February 20, 2026 04:33
@iamsauravsharma

Copy link
Copy Markdown
Author

@cijothomas can you review PR again? Implemented requested changes

@github-actions

Copy link
Copy Markdown

Thank you for your contribution! This PR has been automatically marked as stale because it has not had activity in the last 14 days. This may be due to a delay in review on our side or awaiting a response from you; either is fine, and we appreciate your patience.

It will be closed in 14 days if no further activity occurs. Pushing a new commit or leaving a comment will remove the stale label and keep the PR open.

@github-actions github-actions Bot added the Stale label May 16, 2026
@iamsauravsharma iamsauravsharma force-pushed the add-env-otel-sdk-disabled branch from 9f2f400 to 77c3ca9 Compare May 16, 2026 12:57
@github-actions github-actions Bot removed the Stale label May 17, 2026
@github-actions

Copy link
Copy Markdown

Thank you for your contribution! This PR has been automatically marked as stale because it has not had activity in the last 14 days. This may be due to a delay in review on our side or awaiting a response from you; either is fine, and we appreciate your patience.

It will be closed in 14 days if no further activity occurs. Pushing a new commit or leaving a comment will remove the stale label and keep the PR open.

@github-actions github-actions Bot added Stale and removed Stale labels Jun 11, 2026
@iamsauravsharma iamsauravsharma force-pushed the add-env-otel-sdk-disabled branch from 77c3ca9 to 74c8e11 Compare June 23, 2026 09:02
@cijothomas

Copy link
Copy Markdown
Member

@iamsauravsharma

Thanks for continuing to work on this. Given this feature is supposed to disable entire SDK, I'd like to see a benchmark added which indeed proves that the perf cost when this env var is set is comparable to the API only perf. This will allow us to confirm that we are short-circuiting early enough.

@iamsauravsharma iamsauravsharma force-pushed the add-env-otel-sdk-disabled branch 2 times, most recently from cde4b7a to 6559382 Compare June 26, 2026 06:30
@iamsauravsharma

Copy link
Copy Markdown
Author

@cijothomas I have added benchmark and below are result when running in my machine

Test api-only sdk-disabled sdk-shutdown sdk-enabled
trace 20.4 ns 38.9 ns 38.5 ns 178 ns
log 0.32 ns 2.09 ns 2.09 ns 37 ns
metrics 6.11 ns 6.11 ns 6.10 ns 66 ns

@cijothomas

Copy link
Copy Markdown
Member

@cijothomas I have added benchmark and below are result when running in my machine

Test api-only sdk-disabled sdk-shutdown sdk-enabled
trace 20.4 ns 38.9 ns 38.5 ns 178 ns
log 0.32 ns 2.09 ns 2.09 ns 37 ns
metrics 6.11 ns 6.11 ns 6.10 ns 66 ns

Thanks! Could you include the benchmark as part of this PR ? It definitely looks like there is room for improvement in traces and logs - are we running samplers/generating-trace-id etc when SDK-DISABLED? That might explain why its double the api-only...
Please see if you can optimize it more.

@iamsauravsharma

Copy link
Copy Markdown
Author

@cijothomas benchmark code is already included in PR.

Regarding the performance since sdk-disabled and sdk-shutdown yielded almost identical result. And, sdk-shutdown was already implemented I thought performance was acceptable. Anyway I would look if I can optimize further.

Signed-off-by: Saurav Sharma <appdroiddeveloper@gmail.com>
@iamsauravsharma iamsauravsharma force-pushed the add-env-otel-sdk-disabled branch from 6559382 to 6dffee7 Compare July 1, 2026 10:02
Signed-off-by: Saurav Sharma <appdroiddeveloper@gmail.com>
@iamsauravsharma

Copy link
Copy Markdown
Author

@cijothomas Performance of trace and logs were improved further
https://github.com/iamsauravsharma/opentelemetry-rust/blob/4e437db2c682b4bab38107b4f7698d3725b2e306/opentelemetry-sdk/benches/sdk_disabled.rs Latest benchmark result and code performing benchmark

Test api-only sdk-disabled sdk-shutdown sdk-enabled
trace 20.3 ns 31.9 ns 31.4 ns 185 ns
log 0.32 ns 1.28 ns 1.27 ns 38 ns
metrics 6.11 ns 6.11 ns 6.10 ns 66 ns

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: add support for environment variable OTEL_SDK_DISABLED

4 participants