Skip to content

Conversation

hannahhaering
Copy link
Contributor

@hannahhaering hannahhaering commented Oct 3, 2025

Fixes #4155

Changes

  • Implemented OTEL_SDK_DISABLED according to the OpenTelemetry specification
  • Applied support across TracerProvider, MeterProvider, and LoggerProvider

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

@github-actions github-actions bot added the pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package label Oct 3, 2025
Copy link

codecov bot commented Oct 3, 2025

Codecov Report

❌ Patch coverage is 94.11765% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.72%. Comparing base (0cd5701) to head (aa6027c).
⚠️ Report is 28 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...elemetry/Logs/Builder/LoggerProviderBuilderBase.cs 94.11% 1 Missing ⚠️
...emetry/Metrics/Builder/MeterProviderBuilderBase.cs 94.11% 1 Missing ⚠️
...lemetry/Trace/Builder/TracerProviderBuilderBase.cs 94.11% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6568      +/-   ##
==========================================
- Coverage   86.75%   86.72%   -0.04%     
==========================================
  Files         258      258              
  Lines       11910    11958      +48     
==========================================
+ Hits        10332    10370      +38     
- Misses       1578     1588      +10     
Flag Coverage Δ
unittests-Project-Experimental 86.63% <94.11%> (+0.11%) ⬆️
unittests-Project-Stable 86.55% <94.11%> (-0.17%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...elemetry/Logs/Builder/LoggerProviderBuilderBase.cs 95.91% <94.11%> (-1.06%) ⬇️
...emetry/Metrics/Builder/MeterProviderBuilderBase.cs 96.15% <94.11%> (-1.07%) ⬇️
...lemetry/Trace/Builder/TracerProviderBuilderBase.cs 97.05% <94.11%> (-1.02%) ⬇️

... and 3 files with indirect coverage changes

@hannahhaering hannahhaering marked this pull request as ready for review October 3, 2025 23:55
@hannahhaering hannahhaering requested a review from a team as a code owner October 3, 2025 23:55
Comment on lines 11 to 20
public LoggerProviderBuilderBaseTests()
{
Environment.SetEnvironmentVariable(SdkConfigDefinitions.SdkDisableEnvVarName, null);
}

public void Dispose()
{
Environment.SetEnvironmentVariable(SdkConfigDefinitions.SdkDisableEnvVarName, null);
GC.SuppressFinalize(this);
}
Copy link
Member

Choose a reason for hiding this comment

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

A better way to do this, IMHO, would be to:

  1. Not set the value in the constructor
  2. Let the test set the value it's interested in
  3. Set it back to the original value when being disposed

You could use a similar pattern to this to implement it in a cross-cutting way, then the usage would be something like:

using (new EnvironmentVariableScope("OTEL_SDK_DISABLED", value))
{
    var builder = new LoggerProviderBuilderBase();

    using var provider = builder.Build();

    Assert.IsType(expected, provider);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion, I've done that.

Is there any way I can retry the workflow without a commit? Sometimes the build fails even though I have no errors (like right now).

Copy link
Member

Choose a reason for hiding this comment

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

Not without write access to the repo, no.

Co-authored-by: Martin Costello <martin@martincostello.com>
@martincostello
Copy link
Member

@CodeBlanch Would you mind taking a look at this please?

if (bool.TryParse(envVarValue, out bool result) && result)
{
serviceProvider.Dispose();
return new NoopLoggerProvider();
Copy link
Member

Choose a reason for hiding this comment

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

2 comments:

  1. Would probably be good to add a log here. Don't want support tickets raised for missing telemetry when users have shot themselves in the foot 😄

  2. This won't work for hosting scenarios. See line 80. This code is only invoked for manual/detached bootstrap. Something else will need to be done for hosting style. Ideally we would have a single solution for both but I haven't looked at where that might go.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the hint. Now it should work for both scenarios. Could you please check again?

Copy link
Contributor

This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or pushing will instruct the bot to automatically remove the label. This bot runs once per day.

@github-actions github-actions bot added the Stale Issues and pull requests which have been flagged for closing due to inactivity label Oct 16, 2025
Copy link

@Copilot Copilot AI left a 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 according to the OpenTelemetry specification. When this environment variable is set to true, the SDK returns no-op provider implementations instead of functional ones, effectively disabling telemetry collection.

Key Changes:

  • Added OTEL_SDK_DISABLED environment variable support across all three telemetry signals (tracing, metrics, logging)
  • Introduced SdkConfigDefinitions class to centralize the environment variable name
  • Created EnvironmentVariableScope test helper for managing environment variables in unit tests

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
SdkConfigDefinitions.cs Defines the OTEL_SDK_DISABLED constant for centralized configuration
TracerProviderBuilderBase.cs Checks OTEL_SDK_DISABLED and returns NoopTracerProvider when disabled
MeterProviderBuilderBase.cs Checks OTEL_SDK_DISABLED and returns NoopMeterProvider when disabled
LoggerProviderBuilderBase.cs Checks OTEL_SDK_DISABLED and returns NoopLoggerProvider when disabled
EnvironmentVariableScope.cs Test utility class for temporarily setting environment variables
TracerProviderBuilderBaseTests.cs Unit tests verifying SDK disable functionality for tracer provider
MeterProviderBuilderBaseTests.cs Unit tests verifying SDK disable functionality for meter provider
LoggerProviderBuilderBaseTests.cs Unit tests verifying SDK disable functionality for logger provider
CHANGELOG.md Documents the new feature

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@github-actions github-actions bot removed the Stale Issues and pull requests which have been flagged for closing due to inactivity label Oct 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for OTEL_SDK_DISABLED

3 participants