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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOp
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.TracesPerSecond.set -> void
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableRequestTrackingTelemetryModule.get -> bool
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableRequestTrackingTelemetryModule.set -> void
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableTraceBasedLogsSampler.get -> bool?
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableTraceBasedLogsSampler.set -> void
Microsoft.ApplicationInsights.AspNetCore.IJavaScriptSnippet
Microsoft.ApplicationInsights.AspNetCore.IJavaScriptSnippet.FullScript.get -> string
Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.Sa
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.SamplingRatio.set -> void
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.TracesPerSecond.get -> double?
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.TracesPerSecond.set -> void
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EnableTraceBasedLogsSampler.get -> bool?
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EnableTraceBasedLogsSampler.set -> void
Microsoft.Extensions.DependencyInjection.ApplicationInsightsExtensions
static Microsoft.Extensions.DependencyInjection.ApplicationInsightsExtensions.AddApplicationInsightsTelemetryWorkerService(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection
static Microsoft.Extensions.DependencyInjection.ApplicationInsightsExtensions.AddApplicationInsightsTelemetryWorkerService(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions options) -> Microsoft.Extensions.DependencyInjection.IServiceCollection
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
- OpenTelemetry.Resources.Azure 1.15.0-beta.1
- [Added support to disable telemetry via TelemetryConfiguration.DisableTelemetry](https://github.com/microsoft/ApplicationInsights-dotnet/pull/3084)
- [Removed `EnabledAdaptiveSampling` and replaced with `TracesPerSecond` and `SamplingRatio`](https://github.com/microsoft/ApplicationInsights-dotnet/pull/3085)
- [Added `EnableTraceBasedLogsSampler` property to `ApplicationInsightsServiceOptions` for ASP.NET Core and WorkerService packages](https://github.com/microsoft/ApplicationInsights-dotnet/pull/3088)
- [Added support for `StorageDirectory` and `DisableOfflineStorage` from `TelemetryConfiguration` in DI scenarios](https://github.com/microsoft/ApplicationInsights-dotnet/pull/3088)

## Version 3.0.0-beta2
### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,21 @@ internal static IOpenTelemetryBuilder UseApplicationInsightsTelemetry(this IOpen
{
config["OTEL_SDK_DISABLED"] = "true";
}

if (!string.IsNullOrEmpty(telemetryConfig.StorageDirectory))
{
exporterOptions.StorageDirectory = telemetryConfig.StorageDirectory;
}

if (telemetryConfig.DisableOfflineStorage.HasValue)
{
exporterOptions.DisableOfflineStorage = telemetryConfig.DisableOfflineStorage.Value;
}

if (serviceOptions.EnableTraceBasedLogsSampler.HasValue)
{
exporterOptions.EnableTraceBasedLogsSampler = serviceOptions.EnableTraceBasedLogsSampler.Value;
}

// Copy connection string to Azure Monitor Exporter
if (!string.IsNullOrEmpty(serviceOptions.ConnectionString))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,21 @@ internal static IOpenTelemetryBuilder UseApplicationInsightsTelemetry(this IOpen
config["OTEL_SDK_DISABLED"] = "true";
}

if (!string.IsNullOrEmpty(telemetryConfig.StorageDirectory))
{
exporterOptions.StorageDirectory = telemetryConfig.StorageDirectory;
}

if (telemetryConfig.DisableOfflineStorage.HasValue)
{
exporterOptions.DisableOfflineStorage = telemetryConfig.DisableOfflineStorage.Value;
}

if (serviceOptions.EnableTraceBasedLogsSampler.HasValue)
{
exporterOptions.EnableTraceBasedLogsSampler = serviceOptions.EnableTraceBasedLogsSampler.Value;
}

// Copy connection string to Azure Monitor Exporter
if (!string.IsNullOrEmpty(serviceOptions.ConnectionString))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ public class ApplicationInsightsServiceOptions
/// </summary>
public float? SamplingRatio { get; set; }

/// <summary>
/// Gets or sets a value indicating whether trace-based log sampling is enabled.
/// When null, the Azure Monitor Exporter default of true is used.
/// </summary>
public bool? EnableTraceBasedLogsSampler { get; set; }

#if AI_ASPNETCORE_WEB
/// <summary>
/// Gets or sets a value indicating whether RequestTrackingTelemetryModule should be enabled.
Expand Down Expand Up @@ -101,6 +107,7 @@ internal void CopyPropertiesTo(ApplicationInsightsServiceOptions target)
target.EnableDependencyTrackingTelemetryModule = this.EnableDependencyTrackingTelemetryModule;
target.TracesPerSecond = this.TracesPerSecond;
target.SamplingRatio = this.SamplingRatio;
target.EnableTraceBasedLogsSampler = this.EnableTraceBasedLogsSampler;

#if AI_ASPNETCORE_WEB
target.EnableAuthenticationTrackingJavaScript = this.EnableAuthenticationTrackingJavaScript;
Expand Down
61 changes: 61 additions & 0 deletions NETCORE/test/Shared/ConfigurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,5 +305,66 @@ public void ExplicitConfigurationTakesPrecedenceOverDefaultConfiguration()
var options = serviceProvider.GetRequiredService<IOptions<ApplicationInsightsServiceOptions>>().Value;
Assert.Equal(explicitConnectionString, options.ConnectionString);
}

[Fact]
public void EnableTraceBasedLogsSamplerFlowsToExporterOptions()
{
// ARRANGE
var services = new ServiceCollection();
var config = new ConfigurationBuilder().AddInMemoryCollection().Build();
services.AddSingleton<IConfiguration>(config);

// ACT
#if AI_ASPNETCORE_WEB
services.AddApplicationInsightsTelemetry(options =>
#else
services.AddApplicationInsightsTelemetryWorkerService(options =>
#endif
{
options.ConnectionString = TestConnectionString;
options.EnableTraceBasedLogsSampler = false;
});

// VALIDATE
IServiceProvider serviceProvider = services.BuildServiceProvider();
var aiOptions = serviceProvider.GetRequiredService<IOptions<ApplicationInsightsServiceOptions>>().Value;
Assert.False(aiOptions.EnableTraceBasedLogsSampler);

var exporterOptions = serviceProvider.GetRequiredService<IOptions<AzureMonitorExporterOptions>>().Value;
Assert.False(exporterOptions.EnableTraceBasedLogsSampler);
}

[Fact]
public void StorageOptionsFlowFromTelemetryConfigurationToExporterOptions()
{
// ARRANGE
var services = new ServiceCollection();
var config = new ConfigurationBuilder().AddInMemoryCollection().Build();
services.AddSingleton<IConfiguration>(config);

// ACT
#if AI_ASPNETCORE_WEB
services.AddApplicationInsightsTelemetry(options =>
#else
services.AddApplicationInsightsTelemetryWorkerService(options =>
#endif
{
options.ConnectionString = TestConnectionString;
});

// Configure TelemetryConfiguration with storage options
services.Configure<Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration>(tc =>
{
tc.StorageDirectory = @"C:\CustomStorage";
tc.DisableOfflineStorage = true;
});

// VALIDATE
IServiceProvider serviceProvider = services.BuildServiceProvider();
var exporterOptions = serviceProvider.GetRequiredService<IOptions<AzureMonitorExporterOptions>>().Value;

Assert.Equal(@"C:\CustomStorage", exporterOptions.StorageDirectory);
Assert.True(exporterOptions.DisableOfflineStorage);
}
}
}
Loading