diff --git a/.publicApi/Microsoft.ApplicationInsights.AspNetCore.dll/Stable/PublicAPI.Unshipped.txt b/.publicApi/Microsoft.ApplicationInsights.AspNetCore.dll/Stable/PublicAPI.Unshipped.txt
index 04d1e99149..5dd09fc619 100644
--- a/.publicApi/Microsoft.ApplicationInsights.AspNetCore.dll/Stable/PublicAPI.Unshipped.txt
+++ b/.publicApi/Microsoft.ApplicationInsights.AspNetCore.dll/Stable/PublicAPI.Unshipped.txt
@@ -11,6 +11,8 @@ Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOp
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.DependencyCollectionOptions.get -> Microsoft.ApplicationInsights.AspNetCore.Extensions.DependencyCollectionOptions
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableActiveTelemetryConfigurationSetup.get -> bool
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableActiveTelemetryConfigurationSetup.set -> void
+Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.DisableOfflineStorage.get -> bool
+Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.DisableOfflineStorage.set -> void
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableAdaptiveSampling.get -> bool
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableAdaptiveSampling.set -> void
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableAuthenticationTrackingJavaScript.get -> bool
@@ -19,6 +21,8 @@ Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOp
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableDebugLogger.set -> void
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableDependencyTrackingTelemetryModule.get -> bool
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableDependencyTrackingTelemetryModule.set -> void
+Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableTraceBasedLogsSampler.get -> bool
+Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableTraceBasedLogsSampler.set -> void
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnablePerformanceCounterCollectionModule.get -> bool
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnablePerformanceCounterCollectionModule.set -> void
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableQuickPulseMetricStream.get -> bool
@@ -28,6 +32,10 @@ Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOp
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EndpointAddress.get -> string
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EndpointAddress.set -> void
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.RequestCollectionOptions.get -> Microsoft.ApplicationInsights.AspNetCore.Extensions.RequestCollectionOptions
+Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.StorageDirectory.get -> string
+Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.StorageDirectory.set -> void
+Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.TracesPerSecond.get -> double
+Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.TracesPerSecond.set -> void
Microsoft.ApplicationInsights.AspNetCore.Extensions.DependencyCollectionOptions
Microsoft.ApplicationInsights.AspNetCore.Extensions.DependencyCollectionOptions.DependencyCollectionOptions() -> void
Microsoft.ApplicationInsights.AspNetCore.Extensions.DependencyCollectionOptions.EnableLegacyCorrelationHeadersInjection.get -> bool
diff --git a/.publicApi/Microsoft.ApplicationInsights.WorkerService.dll/Stable/PublicAPI.Unshipped.txt b/.publicApi/Microsoft.ApplicationInsights.WorkerService.dll/Stable/PublicAPI.Unshipped.txt
index a72838a8a7..532499d691 100644
--- a/.publicApi/Microsoft.ApplicationInsights.WorkerService.dll/Stable/PublicAPI.Unshipped.txt
+++ b/.publicApi/Microsoft.ApplicationInsights.WorkerService.dll/Stable/PublicAPI.Unshipped.txt
@@ -9,18 +9,26 @@ Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.Co
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.Credential.get -> Azure.Core.TokenCredential
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.Credential.set -> void
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.DependencyCollectionOptions.get -> Microsoft.ApplicationInsights.WorkerService.DependencyCollectionOptions
+Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.DisableOfflineStorage.get -> bool
+Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.DisableOfflineStorage.set -> void
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EnableAdaptiveSampling.get -> bool
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EnableAdaptiveSampling.set -> void
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EnableDebugLogger.get -> bool
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EnableDebugLogger.set -> void
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EnableDependencyTrackingTelemetryModule.get -> bool
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EnableDependencyTrackingTelemetryModule.set -> void
+Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EnableTraceBasedLogsSampler.get -> bool
+Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EnableTraceBasedLogsSampler.set -> void
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EnablePerformanceCounterCollectionModule.get -> bool
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EnablePerformanceCounterCollectionModule.set -> void
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EnableQuickPulseMetricStream.get -> bool
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EnableQuickPulseMetricStream.set -> void
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EndpointAddress.get -> string
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EndpointAddress.set -> void
+Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.StorageDirectory.get -> string
+Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.StorageDirectory.set -> void
+Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.TracesPerSecond.get -> double
+Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.TracesPerSecond.set -> void
Microsoft.ApplicationInsights.WorkerService.DependencyCollectionOptions
Microsoft.ApplicationInsights.WorkerService.DependencyCollectionOptions.DependencyCollectionOptions() -> void
Microsoft.ApplicationInsights.WorkerService.DependencyCollectionOptions.EnableLegacyCorrelationHeadersInjection.get -> bool
diff --git a/NETCORE/Readme.md b/NETCORE/Readme.md
index 65fb9d0e0c..7841843301 100644
--- a/NETCORE/Readme.md
+++ b/NETCORE/Readme.md
@@ -164,9 +164,38 @@ builder.Services.AddApplicationInsightsTelemetry(options =>
// When true, enables rate-limit based sampling in Azure Monitor Exporter
// When false, sampling is disabled (100% collection)
options.EnableAdaptiveSampling = true;
+
+ // Target number of traces per second for sampling (default: 5.0)
+ options.TracesPerSecond = 5.0;
+
+ // Disable offline storage for failed telemetry (default: false)
+ options.DisableOfflineStorage = false;
+
+ // Custom directory for offline storage
+ options.StorageDirectory = "C:\\AppInsightsStorage";
+
+ // Enable trace-based logs sampling (default: true)
+ // When true, logs are sampled based on their associated trace
+ options.EnableTraceBasedLogsSampler = true;
});
```
+These options can also be configured via `appsettings.json`:
+
+```json
+{
+ "ApplicationInsights": {
+ "ConnectionString": "InstrumentationKey=...",
+ "EnableQuickPulseMetricStream": true,
+ "EnableAdaptiveSampling": true,
+ "TracesPerSecond": 5.0,
+ "DisableOfflineStorage": false,
+ "StorageDirectory": "C:\\AppInsightsStorage",
+ "EnableTraceBasedLogsSampler": true
+ }
+}
+```
+
> **Note**: In version 3.x, many properties from `ApplicationInsightsServiceOptions` in 2.x are no longer functional because they related to telemetry modules, processors, and channels that have been replaced by OpenTelemetry components. The properties shown above are the ones that are actively used in the 3.x OpenTelemetry-based implementation.
## Advanced Configuration
diff --git a/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs b/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs
index 3bd29b38f8..f4e258766e 100644
--- a/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs
+++ b/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs
@@ -199,6 +199,23 @@ internal static IOpenTelemetryBuilder UseApplicationInsightsTelemetry(this IOpen
exporterOptions.SamplingRatio = 1.0F;
}
+ // Copy TracesPerSecond to Azure Monitor Exporter (with validation)
+ if (serviceOptions.TracesPerSecond > 0)
+ {
+ exporterOptions.TracesPerSecond = serviceOptions.TracesPerSecond;
+ }
+
+ // Copy offline storage settings to Azure Monitor Exporter
+ exporterOptions.DisableOfflineStorage = serviceOptions.DisableOfflineStorage;
+
+ if (!string.IsNullOrEmpty(serviceOptions.StorageDirectory))
+ {
+ exporterOptions.StorageDirectory = serviceOptions.StorageDirectory;
+ }
+
+ // Copy trace-based logs sampler setting to Azure Monitor Exporter
+ exporterOptions.EnableTraceBasedLogsSampler = serviceOptions.EnableTraceBasedLogsSampler;
+
if (serviceOptions.EnableQuickPulseMetricStream)
{
exporterOptions.EnableLiveMetrics = true;
diff --git a/NETCORE/src/Microsoft.ApplicationInsights.WorkerService/ApplicationInsightsExtensions.cs b/NETCORE/src/Microsoft.ApplicationInsights.WorkerService/ApplicationInsightsExtensions.cs
index 36a3c134c4..00f9cf1d0b 100644
--- a/NETCORE/src/Microsoft.ApplicationInsights.WorkerService/ApplicationInsightsExtensions.cs
+++ b/NETCORE/src/Microsoft.ApplicationInsights.WorkerService/ApplicationInsightsExtensions.cs
@@ -194,6 +194,23 @@ internal static IOpenTelemetryBuilder UseApplicationInsightsTelemetry(this IOpen
exporterOptions.SamplingRatio = 1.0F;
}
+ // Copy TracesPerSecond to Azure Monitor Exporter (with validation)
+ if (serviceOptions.TracesPerSecond > 0)
+ {
+ exporterOptions.TracesPerSecond = serviceOptions.TracesPerSecond;
+ }
+
+ // Copy offline storage settings to Azure Monitor Exporter
+ exporterOptions.DisableOfflineStorage = serviceOptions.DisableOfflineStorage;
+
+ if (!string.IsNullOrEmpty(serviceOptions.StorageDirectory))
+ {
+ exporterOptions.StorageDirectory = serviceOptions.StorageDirectory;
+ }
+
+ // Copy trace-based logs sampler setting to Azure Monitor Exporter
+ exporterOptions.EnableTraceBasedLogsSampler = serviceOptions.EnableTraceBasedLogsSampler;
+
exporterOptions.EnableLiveMetrics = serviceOptions.EnableQuickPulseMetricStream;
});
diff --git a/NETCORE/src/Shared/Extensions/ApplicationInsightsServiceOptions.cs b/NETCORE/src/Shared/Extensions/ApplicationInsightsServiceOptions.cs
index c5809c52a9..5f2964ce73 100644
--- a/NETCORE/src/Shared/Extensions/ApplicationInsightsServiceOptions.cs
+++ b/NETCORE/src/Shared/Extensions/ApplicationInsightsServiceOptions.cs
@@ -38,6 +38,32 @@ public class ApplicationInsightsServiceOptions
///
public bool EnableAdaptiveSampling { get; set; } = true;
+ ///
+ /// Gets or sets the target number of traces per second to be collected.
+ /// Defaults to 5.0.
+ ///
+ public double TracesPerSecond { get; set; } = 5.0;
+
+ ///
+ /// Gets or sets a value indicating whether offline storage should be disabled.
+ /// When true, telemetry will not be stored locally when transmission fails.
+ /// Defaults to false.
+ ///
+ public bool DisableOfflineStorage { get; set; } = false;
+
+ ///
+ /// Gets or sets the directory path for storing telemetry when offline.
+ /// If not specified, the default storage directory will be used.
+ ///
+ public string StorageDirectory { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether the trace-based logs sampler is enabled.
+ /// When true (default), logs are sampled based on their associated trace.
+ /// Defaults to true.
+ ///
+ public bool EnableTraceBasedLogsSampler { get; set; } = true;
+
///
/// Gets or sets the connection string for the application.
///
@@ -129,6 +155,10 @@ internal void CopyPropertiesTo(ApplicationInsightsServiceOptions target)
target.ApplicationVersion = this.ApplicationVersion;
target.EnableAdaptiveSampling = this.EnableAdaptiveSampling;
+ target.TracesPerSecond = this.TracesPerSecond;
+ target.DisableOfflineStorage = this.DisableOfflineStorage;
+ target.StorageDirectory = this.StorageDirectory;
+ target.EnableTraceBasedLogsSampler = this.EnableTraceBasedLogsSampler;
target.EnableDebugLogger = this.EnableDebugLogger;
target.EnableQuickPulseMetricStream = this.EnableQuickPulseMetricStream;
target.AddAutoCollectedMetricExtractor = this.AddAutoCollectedMetricExtractor;
diff --git a/NETCORE/test/IntegrationTests.Tests/content/config-all-default.json b/NETCORE/test/IntegrationTests.Tests/content/config-all-default.json
index 45340f7881..77596a2c33 100644
--- a/NETCORE/test/IntegrationTests.Tests/content/config-all-default.json
+++ b/NETCORE/test/IntegrationTests.Tests/content/config-all-default.json
@@ -2,6 +2,9 @@
"ApplicationInsights": {
"ConnectionString": "InstrumentationKey=11111111-2222-3333-4444-555555555555;IngestionEndpoint=http://testendpoint",
"EnableAdaptiveSampling": false,
+ "TracesPerSecond": 5.0,
+ "DisableOfflineStorage": false,
+ "EnableTraceBasedLogsSampler": true,
"EnableQuickPulseMetricStream": true,
"ApplicationVersion": "Version",
"RequestCollectionOptions": {
diff --git a/NETCORE/test/IntegrationTests.Tests/content/config-all-settings-false.json b/NETCORE/test/IntegrationTests.Tests/content/config-all-settings-false.json
index 4346f32091..1d90685aac 100644
--- a/NETCORE/test/IntegrationTests.Tests/content/config-all-settings-false.json
+++ b/NETCORE/test/IntegrationTests.Tests/content/config-all-settings-false.json
@@ -2,6 +2,10 @@
"ApplicationInsights": {
"ConnectionString": "InstrumentationKey=22222222-2222-3333-4444-555555555555",
"EnableAdaptiveSampling": false,
+ "TracesPerSecond": 1.0,
+ "DisableOfflineStorage": false,
+ "StorageDirectory": "C:\\TestStorage",
+ "EnableTraceBasedLogsSampler": false,
"EnableQuickPulseMetricStream": false,
"RequestCollectionOptions": {
"InjectResponseHeaders": false,
diff --git a/NETCORE/test/IntegrationTests.Tests/content/config-all-settings-true.json b/NETCORE/test/IntegrationTests.Tests/content/config-all-settings-true.json
index e1c54cc937..8e9fd5ec16 100644
--- a/NETCORE/test/IntegrationTests.Tests/content/config-all-settings-true.json
+++ b/NETCORE/test/IntegrationTests.Tests/content/config-all-settings-true.json
@@ -2,6 +2,9 @@
"ApplicationInsights": {
"ConnectionString": "InstrumentationKey=22222222-2222-3333-4444-555555555555",
"EnableAdaptiveSampling": true,
+ "TracesPerSecond": 10.0,
+ "DisableOfflineStorage": true,
+ "EnableTraceBasedLogsSampler": true,
"EnableQuickPulseMetricStream": true,
"ApplicationVersion": "1.0.0",
"RequestCollectionOptions": {
diff --git a/NETCORE/test/Microsoft.ApplicationInsights.AspNetCore.Tests/content/config-all-default.json b/NETCORE/test/Microsoft.ApplicationInsights.AspNetCore.Tests/content/config-all-default.json
index aeac384fd9..aad4ac7a8e 100644
--- a/NETCORE/test/Microsoft.ApplicationInsights.AspNetCore.Tests/content/config-all-default.json
+++ b/NETCORE/test/Microsoft.ApplicationInsights.AspNetCore.Tests/content/config-all-default.json
@@ -3,6 +3,9 @@
"InstrumentationKey": "11111111-2222-3333-4444-555555555555",
"ConnectionString": "InstrumentationKey=11111111-2222-3333-4444-555555555555;IngestionEndpoint=http://testendpoint",
"EnableAdaptiveSampling": false,
+ "TracesPerSecond": 5.0,
+ "DisableOfflineStorage": false,
+ "EnableTraceBasedLogsSampler": true,
"EnablePerformanceCounterCollectionModule": true,
"EnableAzureInstanceMetadataTelemetryModule": true,
"EnableRequestTrackingTelemetryModule": true,
diff --git a/NETCORE/test/Microsoft.ApplicationInsights.AspNetCore.Tests/content/config-all-settings-false.json b/NETCORE/test/Microsoft.ApplicationInsights.AspNetCore.Tests/content/config-all-settings-false.json
index 33d70c7d7b..b778c9abc9 100644
--- a/NETCORE/test/Microsoft.ApplicationInsights.AspNetCore.Tests/content/config-all-settings-false.json
+++ b/NETCORE/test/Microsoft.ApplicationInsights.AspNetCore.Tests/content/config-all-settings-false.json
@@ -3,6 +3,10 @@
"InstrumentationKey": "22222222-2222-3333-4444-555555555555",
"ConnectionString": "InstrumentationKey=22222222-2222-3333-4444-555555555555;IngestionEndpoint=http://testendpoint",
"EnableAdaptiveSampling": false,
+ "TracesPerSecond": 1.0,
+ "DisableOfflineStorage": false,
+ "StorageDirectory": "C:\\TestStorage",
+ "EnableTraceBasedLogsSampler": false,
"EnablePerformanceCounterCollectionModule": false,
"EnableAzureInstanceMetadataTelemetryModule": false,
"EnableRequestTrackingTelemetryModule": false,
diff --git a/NETCORE/test/Microsoft.ApplicationInsights.AspNetCore.Tests/content/config-all-settings-true.json b/NETCORE/test/Microsoft.ApplicationInsights.AspNetCore.Tests/content/config-all-settings-true.json
index da40a3111a..8a301700f3 100644
--- a/NETCORE/test/Microsoft.ApplicationInsights.AspNetCore.Tests/content/config-all-settings-true.json
+++ b/NETCORE/test/Microsoft.ApplicationInsights.AspNetCore.Tests/content/config-all-settings-true.json
@@ -3,6 +3,9 @@
"InstrumentationKey": "22222222-2222-3333-4444-555555555555",
"ConnectionString": "InstrumentationKey=22222222-2222-3333-4444-555555555555;IngestionEndpoint=http://testendpoint",
"EnableAdaptiveSampling": true,
+ "TracesPerSecond": 10.0,
+ "DisableOfflineStorage": true,
+ "EnableTraceBasedLogsSampler": true,
"EnablePerformanceCounterCollectionModule": true,
"EnableAzureInstanceMetadataTelemetryModule": true,
"EnableRequestTrackingTelemetryModule": true,
diff --git a/NETCORE/test/Microsoft.ApplicationInsights.WorkerService.Tests/content/config-all-default.json b/NETCORE/test/Microsoft.ApplicationInsights.WorkerService.Tests/content/config-all-default.json
index aeac384fd9..e0cab98317 100644
--- a/NETCORE/test/Microsoft.ApplicationInsights.WorkerService.Tests/content/config-all-default.json
+++ b/NETCORE/test/Microsoft.ApplicationInsights.WorkerService.Tests/content/config-all-default.json
@@ -3,8 +3,11 @@
"InstrumentationKey": "11111111-2222-3333-4444-555555555555",
"ConnectionString": "InstrumentationKey=11111111-2222-3333-4444-555555555555;IngestionEndpoint=http://testendpoint",
"EnableAdaptiveSampling": false,
+ "TracesPerSecond": 5.0,
+ "DisableOfflineStorage": false,
+ "EnableTraceBasedLogsSampler": true,
"EnablePerformanceCounterCollectionModule": true,
- "EnableAzureInstanceMetadataTelemetryModule": true,
+ "EnableAzureInstanceMetadatsaTelemetryModule": true,
"EnableRequestTrackingTelemetryModule": true,
"EnableDependencyTrackingTelemetryModule": true,
"EnableAppServicesHeartbeatTelemetryModule": true,
diff --git a/NETCORE/test/Microsoft.ApplicationInsights.WorkerService.Tests/content/config-all-settings-false.json b/NETCORE/test/Microsoft.ApplicationInsights.WorkerService.Tests/content/config-all-settings-false.json
index 33d70c7d7b..b778c9abc9 100644
--- a/NETCORE/test/Microsoft.ApplicationInsights.WorkerService.Tests/content/config-all-settings-false.json
+++ b/NETCORE/test/Microsoft.ApplicationInsights.WorkerService.Tests/content/config-all-settings-false.json
@@ -3,6 +3,10 @@
"InstrumentationKey": "22222222-2222-3333-4444-555555555555",
"ConnectionString": "InstrumentationKey=22222222-2222-3333-4444-555555555555;IngestionEndpoint=http://testendpoint",
"EnableAdaptiveSampling": false,
+ "TracesPerSecond": 1.0,
+ "DisableOfflineStorage": false,
+ "StorageDirectory": "C:\\TestStorage",
+ "EnableTraceBasedLogsSampler": false,
"EnablePerformanceCounterCollectionModule": false,
"EnableAzureInstanceMetadataTelemetryModule": false,
"EnableRequestTrackingTelemetryModule": false,
diff --git a/NETCORE/test/Microsoft.ApplicationInsights.WorkerService.Tests/content/config-all-settings-true.json b/NETCORE/test/Microsoft.ApplicationInsights.WorkerService.Tests/content/config-all-settings-true.json
index da40a3111a..8a301700f3 100644
--- a/NETCORE/test/Microsoft.ApplicationInsights.WorkerService.Tests/content/config-all-settings-true.json
+++ b/NETCORE/test/Microsoft.ApplicationInsights.WorkerService.Tests/content/config-all-settings-true.json
@@ -3,6 +3,9 @@
"InstrumentationKey": "22222222-2222-3333-4444-555555555555",
"ConnectionString": "InstrumentationKey=22222222-2222-3333-4444-555555555555;IngestionEndpoint=http://testendpoint",
"EnableAdaptiveSampling": true,
+ "TracesPerSecond": 10.0,
+ "DisableOfflineStorage": true,
+ "EnableTraceBasedLogsSampler": true,
"EnablePerformanceCounterCollectionModule": true,
"EnableAzureInstanceMetadataTelemetryModule": true,
"EnableRequestTrackingTelemetryModule": true,
diff --git a/NETCORE/test/Shared/ConfigurationTests.cs b/NETCORE/test/Shared/ConfigurationTests.cs
index a123902c8f..ecdfdd2ccb 100644
--- a/NETCORE/test/Shared/ConfigurationTests.cs
+++ b/NETCORE/test/Shared/ConfigurationTests.cs
@@ -149,12 +149,159 @@ public void ConfigurationFlowsFromApplicationInsightsSectionToAzureMonitorExport
Assert.Equal("InstrumentationKey=22222222-2222-3333-4444-555555555555", aiOptions.ConnectionString);
Assert.False(aiOptions.EnableAdaptiveSampling);
Assert.False(aiOptions.EnableQuickPulseMetricStream);
+ Assert.Equal(1.0, aiOptions.TracesPerSecond);
+ Assert.False(aiOptions.DisableOfflineStorage);
+ Assert.Equal("C:\\TestStorage", aiOptions.StorageDirectory);
+ Assert.False(aiOptions.EnableTraceBasedLogsSampler);
// Verify AzureMonitorExporterOptions gets the values
var exporterOptions = serviceProvider.GetRequiredService>().Value;
Assert.Equal("InstrumentationKey=22222222-2222-3333-4444-555555555555", exporterOptions.ConnectionString);
Assert.Equal(1.0F, exporterOptions.SamplingRatio); // No sampling when EnableAdaptiveSampling is false
Assert.False(exporterOptions.EnableLiveMetrics);
+ Assert.Equal(1.0, exporterOptions.TracesPerSecond);
+ Assert.False(exporterOptions.DisableOfflineStorage);
+ Assert.Equal("C:\\TestStorage", exporterOptions.StorageDirectory);
+ Assert.False(exporterOptions.EnableTraceBasedLogsSampler);
+ }
+
+ [Fact]
+ public void ReadsTracesPerSecondFromApplicationInsightsSectionInConfig()
+ {
+ // ARRANGE
+ var jsonFullPath = Path.Combine(Directory.GetCurrentDirectory(), "content", "config-all-settings-true.json");
+ this.output.WriteLine("json:" + jsonFullPath);
+ var config = new ConfigurationBuilder().AddJsonFile(jsonFullPath).Build();
+
+ var services = new ServiceCollection();
+ services.AddSingleton(config);
+
+ // ACT
+#if AI_ASPNETCORE_WEB
+ services.AddApplicationInsightsTelemetry();
+#else
+ services.AddApplicationInsightsTelemetryWorkerService();
+#endif
+
+ // VALIDATE
+ IServiceProvider serviceProvider = services.BuildServiceProvider();
+ var options = serviceProvider.GetRequiredService>().Value;
+ Assert.Equal(10.0, options.TracesPerSecond);
+
+ // Verify it flows to exporter options
+ var exporterOptions = serviceProvider.GetRequiredService>().Value;
+ Assert.Equal(10.0, exporterOptions.TracesPerSecond);
+ }
+
+ [Fact]
+ public void ReadsDisableOfflineStorageFromApplicationInsightsSectionInConfig()
+ {
+ // ARRANGE
+ var jsonFullPath = Path.Combine(Directory.GetCurrentDirectory(), "content", "config-all-settings-true.json");
+ this.output.WriteLine("json:" + jsonFullPath);
+ var config = new ConfigurationBuilder().AddJsonFile(jsonFullPath).Build();
+
+ var services = new ServiceCollection();
+ services.AddSingleton(config);
+
+ // ACT
+#if AI_ASPNETCORE_WEB
+ services.AddApplicationInsightsTelemetry();
+#else
+ services.AddApplicationInsightsTelemetryWorkerService();
+#endif
+
+ // VALIDATE
+ IServiceProvider serviceProvider = services.BuildServiceProvider();
+ var options = serviceProvider.GetRequiredService>().Value;
+ Assert.True(options.DisableOfflineStorage);
+
+ // Verify it flows to exporter options
+ var exporterOptions = serviceProvider.GetRequiredService>().Value;
+ Assert.True(exporterOptions.DisableOfflineStorage);
+ }
+
+ [Fact]
+ public void ReadsStorageDirectoryFromApplicationInsightsSectionInConfig()
+ {
+ // ARRANGE
+ var jsonFullPath = Path.Combine(Directory.GetCurrentDirectory(), "content", "config-all-settings-false.json");
+ this.output.WriteLine("json:" + jsonFullPath);
+ var config = new ConfigurationBuilder().AddJsonFile(jsonFullPath).Build();
+
+ var services = new ServiceCollection();
+ services.AddSingleton(config);
+
+ // ACT
+#if AI_ASPNETCORE_WEB
+ services.AddApplicationInsightsTelemetry();
+#else
+ services.AddApplicationInsightsTelemetryWorkerService();
+#endif
+
+ // VALIDATE
+ IServiceProvider serviceProvider = services.BuildServiceProvider();
+ var options = serviceProvider.GetRequiredService>().Value;
+ Assert.Equal("C:\\TestStorage", options.StorageDirectory);
+
+ // Verify it flows to exporter options
+ var exporterOptions = serviceProvider.GetRequiredService>().Value;
+ Assert.Equal("C:\\TestStorage", exporterOptions.StorageDirectory);
+ }
+
+ [Fact]
+ public void ReadsEnableTraceBasedLogsSamplerFromApplicationInsightsSectionInConfig()
+ {
+ // ARRANGE
+ var jsonFullPath = Path.Combine(Directory.GetCurrentDirectory(), "content", "config-all-settings-false.json");
+ this.output.WriteLine("json:" + jsonFullPath);
+ var config = new ConfigurationBuilder().AddJsonFile(jsonFullPath).Build();
+
+ var services = new ServiceCollection();
+ services.AddSingleton(config);
+
+ // ACT
+#if AI_ASPNETCORE_WEB
+ services.AddApplicationInsightsTelemetry();
+#else
+ services.AddApplicationInsightsTelemetryWorkerService();
+#endif
+
+ // VALIDATE
+ IServiceProvider serviceProvider = services.BuildServiceProvider();
+ var options = serviceProvider.GetRequiredService>().Value;
+ Assert.False(options.EnableTraceBasedLogsSampler);
+
+ // Verify it flows to exporter options
+ var exporterOptions = serviceProvider.GetRequiredService>().Value;
+ Assert.False(exporterOptions.EnableTraceBasedLogsSampler);
+ }
+
+ [Fact]
+ public void TracesPerSecondIgnoresNonPositiveValues()
+ {
+ // 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 = "InstrumentationKey=11111111-2222-3333-4444-555555555555";
+ options.TracesPerSecond = -1.0; // Invalid value
+ });
+
+ // VALIDATE
+ IServiceProvider serviceProvider = services.BuildServiceProvider();
+ var exporterOptions = serviceProvider.GetRequiredService>().Value;
+
+ // TracesPerSecond should not be set to a negative value - it should remain at default
+ Assert.NotEqual(-1.0, exporterOptions.TracesPerSecond);
}
[Fact]