Skip to content

Restore OTEL_SDK_DISABLED in AzureMonitorExporterOptions callbacks#3157

Merged
harsimar merged 3 commits intomainfrom
rajrang/restore-otel-sdk-disabled-exporter
Apr 1, 2026
Merged

Restore OTEL_SDK_DISABLED in AzureMonitorExporterOptions callbacks#3157
harsimar merged 3 commits intomainfrom
rajrang/restore-otel-sdk-disabled-exporter

Conversation

@rajkumar-rangaraj
Copy link
Copy Markdown
Member

Problem

PR #3156 accidentally removed the OTEL_SDK_DISABLED assignment from the AzureMonitorExporterOptions configure callbacks in both AspNetCore and WorkerService packages. Without this, TracerProvider does not see the disabled flag when DisableTelemetry = true.

Fix

Restore the OTEL_SDK_DISABLED assignment in the exporter options callbacks. The TelemetryConfiguration factory (added in #3156) covers MeterProvider, but this callback is still required for TracerProvider which resolves through a different path.

Changes

File Change
NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs Restore OTEL_SDK_DISABLED in exporter options callback
NETCORE/src/Microsoft.ApplicationInsights.WorkerService/ApplicationInsightsExtensions.cs Restore OTEL_SDK_DISABLED in exporter options callback

PR #3156 accidentally removed the OTEL_SDK_DISABLED assignment from the
AzureMonitorExporterOptions configure callbacks in both AspNetCore and
WorkerService packages. This assignment is needed so the OTel SDK's
TracerProvider sees the disabled flag when it checks IConfiguration.

The TelemetryConfiguration factory (added in #3156) covers MeterProvider,
but this callback is still required for TracerProvider which resolves
through a different path.
Copilot AI review requested due to automatic review settings March 31, 2026 21:57
Copy link
Copy Markdown
Contributor

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 attempts to restore setting OTEL_SDK_DISABLED=true inside the AzureMonitorExporterOptions configure callbacks for the AspNetCore and WorkerService packages so that TelemetryConfiguration.DisableTelemetry=true is respected by the OpenTelemetry TracerProvider path.

Changes:

  • Re-add config["OTEL_SDK_DISABLED"] = "true" to the AzureMonitorExporterOptions options callback when telemetryConfig.DisableTelemetry is true (WorkerService).
  • Re-add config["OTEL_SDK_DISABLED"] = "true" to the AzureMonitorExporterOptions options callback when telemetryConfig.DisableTelemetry is true (AspNetCore).

Reviewed changes

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

File Description
NETCORE/src/Microsoft.ApplicationInsights.WorkerService/ApplicationInsightsExtensions.cs Reintroduces OTEL_SDK_DISABLED assignment in the exporter options configure callback.
NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs Reintroduces OTEL_SDK_DISABLED assignment in the exporter options configure callback.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +203 to +208
// Set OTEL_SDK_DISABLED in configuration if DisableTelemetry is true
if (telemetryConfig.DisableTelemetry)
{
config["OTEL_SDK_DISABLED"] = "true";
}

Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

This OTEL_SDK_DISABLED assignment is redundant: AddTelemetryConfigAndClient already sets IConfiguration["OTEL_SDK_DISABLED"] = "true" during TelemetryConfiguration resolution when DisableTelemetry is true (NETCORE/src/Shared/Extensions/ApplicationInsightsExtensions.cs:125-134). Since telemetryConfig is resolved before this callback executes, this block doesn’t change behavior and adds another place to maintain this logic; consider removing it and keeping the setting centralized in the shared TelemetryConfiguration factory.

Suggested change
// Set OTEL_SDK_DISABLED in configuration if DisableTelemetry is true
if (telemetryConfig.DisableTelemetry)
{
config["OTEL_SDK_DISABLED"] = "true";
}

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Intentionally keeping this as defense-in-depth. The TelemetryConfiguration factory covers MeterProvider, but TracerProvider may resolve through a different path. Setting the same value twice in IConfiguration is harmless and this was the original behavior on main before #3156.

Register a no-op ILoggerProvider at position 0 in the service collection
that depends on TelemetryConfiguration. ILoggerFactory resolves all
ILoggerProvider instances in registration order during host construction.
By inserting this first, TelemetryConfiguration is resolved (which sets
OTEL_SDK_DISABLED in IConfiguration) before OpenTelemetry's LoggerProvider
factory checks the flag. Without this, LoggerProvider was constructed before
OTEL_SDK_DISABLED was set, resulting in logs still being exported.
@harsimar harsimar merged commit 7e3cab4 into main Apr 1, 2026
18 checks passed
@harsimar harsimar deleted the rajrang/restore-otel-sdk-disabled-exporter branch April 1, 2026 17:26
This was referenced Apr 2, 2026
This was referenced Apr 5, 2026
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.

3 participants