Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Unreleased
- [Fix `DisableTelemetry` not disabling metrics export: `OTEL_SDK_DISABLED` was set in IConfiguration too late (during options callback) after the OTel MeterProvider had already been constructed. Moved the check to a hosted service that runs before OpenTelemetry's TelemetryHostedService.](https://github.com/microsoft/ApplicationInsights-dotnet/pull/3156)
- [Fix `TrackAvailability` ignoring user-specified `Timestamp` on `AvailabilityTelemetry`. The timestamp is now emitted as `microsoft.availability.testTimestamp` so downstream exporters can use the correct event time.](https://github.com/microsoft/ApplicationInsights-dotnet/pull/3153)
- [Added `netstandard2.0` target framework to `Microsoft.ApplicationInsights` package to support customers with shared libraries targeting netstandard2.0.](https://github.com/microsoft/ApplicationInsights-dotnet/pull/3142)
- [Fix `TelemetryClient.Context.Cloud.RoleName` set after construction now applies to all telemetry.](https://github.com/microsoft/ApplicationInsights-dotnet/pull/3129)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,6 @@ internal static IOpenTelemetryBuilder UseApplicationInsightsTelemetry(this IOpen
{
var serviceOptions = aiOptions.Value;

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

if (!string.IsNullOrEmpty(telemetryConfig.StorageDirectory))
{
exporterOptions.StorageDirectory = telemetryConfig.StorageDirectory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,6 @@ internal static IOpenTelemetryBuilder UseApplicationInsightsTelemetry(this IOpen
{
var serviceOptions = aiOptions.Value;

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

if (!string.IsNullOrEmpty(telemetryConfig.StorageDirectory))
{
exporterOptions.StorageDirectory = telemetryConfig.StorageDirectory;
Expand Down
15 changes: 13 additions & 2 deletions NETCORE/src/Shared/Extensions/ApplicationInsightsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private static bool IsApplicationInsightsAdded(IServiceCollection services)
private static void AddTelemetryConfigAndClient(IServiceCollection services, string extensionVersion)
{
services.AddOptions();

// Register TelemetryConfiguration singleton with factory that creates it for DI scenarios
// We use a factory to ensure skipDefaultBuilderConfiguration: true is passed
services.AddSingleton<TelemetryConfiguration>(provider =>
Expand Down Expand Up @@ -121,7 +121,18 @@ private static void AddTelemetryConfigAndClient(IServiceCollection services, str
{
postConfigure.PostConfigure(Options.DefaultName, configuration);
}


// Set OTEL_SDK_DISABLED in IConfiguration so the OTel SDK's MeterProvider/TracerProvider
// factories see it when they check IsOtelSdkDisabled(). This must happen here (during
// TelemetryConfiguration resolution) rather than in a hosted service, because the
// MeterProvider singleton factory can be triggered during the DI build phase
// (e.g., via UseAzureMonitorExporter -> options resolution) before any hosted service runs.
if (configuration.DisableTelemetry)
{
var iconfig = provider.GetRequiredService<IConfiguration>();
iconfig["OTEL_SDK_DISABLED"] = "true";
}

return configuration;
});

Expand Down
Loading