diff --git a/.publicApi/Microsoft.ApplicationInsights.AspNetCore.dll/Stable/PublicAPI.Unshipped.txt b/.publicApi/Microsoft.ApplicationInsights.AspNetCore.dll/Stable/PublicAPI.Unshipped.txt
index ff8a867fb..7083ad19f 100644
--- a/.publicApi/Microsoft.ApplicationInsights.AspNetCore.dll/Stable/PublicAPI.Unshipped.txt
+++ b/.publicApi/Microsoft.ApplicationInsights.AspNetCore.dll/Stable/PublicAPI.Unshipped.txt
@@ -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
diff --git a/.publicApi/Microsoft.ApplicationInsights.WorkerService.dll/Stable/PublicAPI.Unshipped.txt b/.publicApi/Microsoft.ApplicationInsights.WorkerService.dll/Stable/PublicAPI.Unshipped.txt
index 6321c5830..e94509291 100644
--- a/.publicApi/Microsoft.ApplicationInsights.WorkerService.dll/Stable/PublicAPI.Unshipped.txt
+++ b/.publicApi/Microsoft.ApplicationInsights.WorkerService.dll/Stable/PublicAPI.Unshipped.txt
@@ -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
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1bfb00185..a5007e853 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs b/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs
index 3e8ba531d..f8bc798b4 100644
--- a/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs
+++ b/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs
@@ -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))
diff --git a/NETCORE/src/Microsoft.ApplicationInsights.WorkerService/ApplicationInsightsExtensions.cs b/NETCORE/src/Microsoft.ApplicationInsights.WorkerService/ApplicationInsightsExtensions.cs
index 80875bdc8..c05c027d2 100644
--- a/NETCORE/src/Microsoft.ApplicationInsights.WorkerService/ApplicationInsightsExtensions.cs
+++ b/NETCORE/src/Microsoft.ApplicationInsights.WorkerService/ApplicationInsightsExtensions.cs
@@ -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))
{
diff --git a/NETCORE/src/Shared/Extensions/ApplicationInsightsServiceOptions.cs b/NETCORE/src/Shared/Extensions/ApplicationInsightsServiceOptions.cs
index fdc3e7814..6530694b1 100644
--- a/NETCORE/src/Shared/Extensions/ApplicationInsightsServiceOptions.cs
+++ b/NETCORE/src/Shared/Extensions/ApplicationInsightsServiceOptions.cs
@@ -64,6 +64,12 @@ public class ApplicationInsightsServiceOptions
///
public float? SamplingRatio { get; set; }
+ ///
+ /// Gets or sets a value indicating whether trace-based log sampling is enabled.
+ /// When null, the Azure Monitor Exporter default of true is used.
+ ///
+ public bool? EnableTraceBasedLogsSampler { get; set; }
+
#if AI_ASPNETCORE_WEB
///
/// Gets or sets a value indicating whether RequestTrackingTelemetryModule should be enabled.
@@ -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;
diff --git a/NETCORE/test/Shared/ConfigurationTests.cs b/NETCORE/test/Shared/ConfigurationTests.cs
index 6e936be98..7e44ced7e 100644
--- a/NETCORE/test/Shared/ConfigurationTests.cs
+++ b/NETCORE/test/Shared/ConfigurationTests.cs
@@ -305,5 +305,66 @@ public void ExplicitConfigurationTakesPrecedenceOverDefaultConfiguration()
var options = serviceProvider.GetRequiredService>().Value;
Assert.Equal(explicitConnectionString, options.ConnectionString);
}
+
+ [Fact]
+ public void EnableTraceBasedLogsSamplerFlowsToExporterOptions()
+ {
+ // ARRANGE
+ var services = new ServiceCollection();
+ var config = new ConfigurationBuilder().AddInMemoryCollection().Build();
+ services.AddSingleton(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>().Value;
+ Assert.False(aiOptions.EnableTraceBasedLogsSampler);
+
+ var exporterOptions = serviceProvider.GetRequiredService>().Value;
+ Assert.False(exporterOptions.EnableTraceBasedLogsSampler);
+ }
+
+ [Fact]
+ public void StorageOptionsFlowFromTelemetryConfigurationToExporterOptions()
+ {
+ // ARRANGE
+ var services = new ServiceCollection();
+ var config = new ConfigurationBuilder().AddInMemoryCollection().Build();
+ services.AddSingleton(config);
+
+ // ACT
+#if AI_ASPNETCORE_WEB
+ services.AddApplicationInsightsTelemetry(options =>
+#else
+ services.AddApplicationInsightsTelemetryWorkerService(options =>
+#endif
+ {
+ options.ConnectionString = TestConnectionString;
+ });
+
+ // Configure TelemetryConfiguration with storage options
+ services.Configure(tc =>
+ {
+ tc.StorageDirectory = @"C:\CustomStorage";
+ tc.DisableOfflineStorage = true;
+ });
+
+ // VALIDATE
+ IServiceProvider serviceProvider = services.BuildServiceProvider();
+ var exporterOptions = serviceProvider.GetRequiredService>().Value;
+
+ Assert.Equal(@"C:\CustomStorage", exporterOptions.StorageDirectory);
+ Assert.True(exporterOptions.DisableOfflineStorage);
+ }
}
}