diff --git a/.publicApi/Microsoft.ApplicationInsights.AspNetCore.dll/Stable/PublicAPI.Unshipped.txt b/.publicApi/Microsoft.ApplicationInsights.AspNetCore.dll/Stable/PublicAPI.Unshipped.txt
index 59c2efd7e..ff8a867fb 100644
--- a/.publicApi/Microsoft.ApplicationInsights.AspNetCore.dll/Stable/PublicAPI.Unshipped.txt
+++ b/.publicApi/Microsoft.ApplicationInsights.AspNetCore.dll/Stable/PublicAPI.Unshipped.txt
@@ -8,8 +8,6 @@ Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOp
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.ConnectionString.set -> void
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.Credential.get -> Azure.Core.TokenCredential
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.Credential.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
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableAuthenticationTrackingJavaScript.set -> void
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableDependencyTrackingTelemetryModule.get -> bool
@@ -18,6 +16,10 @@ Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOp
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnablePerformanceCounterCollectionModule.set -> void
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableQuickPulseMetricStream.get -> bool
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableQuickPulseMetricStream.set -> void
+Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.SamplingRatio.get -> float?
+Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.SamplingRatio.set -> void
+Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.TracesPerSecond.get -> double?
+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.IJavaScriptSnippet
diff --git a/.publicApi/Microsoft.ApplicationInsights.WorkerService.dll/Stable/PublicAPI.Unshipped.txt b/.publicApi/Microsoft.ApplicationInsights.WorkerService.dll/Stable/PublicAPI.Unshipped.txt
index 1e82d9d1f..6321c5830 100644
--- a/.publicApi/Microsoft.ApplicationInsights.WorkerService.dll/Stable/PublicAPI.Unshipped.txt
+++ b/.publicApi/Microsoft.ApplicationInsights.WorkerService.dll/Stable/PublicAPI.Unshipped.txt
@@ -8,14 +8,16 @@ Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.Co
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.ConnectionString.set -> void
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.Credential.get -> Azure.Core.TokenCredential
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.Credential.set -> void
-Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EnableAdaptiveSampling.get -> bool
-Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EnableAdaptiveSampling.set -> void
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EnableDependencyTrackingTelemetryModule.get -> bool
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EnableDependencyTrackingTelemetryModule.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.SamplingRatio.get -> float?
+Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.SamplingRatio.set -> void
+Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.TracesPerSecond.get -> double?
+Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.TracesPerSecond.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/BreakingChanges.md b/BreakingChanges.md
index 18d169e57..1b12178d7 100644
--- a/BreakingChanges.md
+++ b/BreakingChanges.md
@@ -217,12 +217,10 @@ The following extension methods remain with identical signatures:
- ❌ **`EnableHeartbeat`** - Heartbeat configuration removed
- ❌ **`RequestCollectionOptions`** - Removed (non-functional, use OpenTelemetry instrumentation options)
- ❌ **`DependencyCollectionOptions`** - Removed (non-functional, use OpenTelemetry instrumentation options)
+- ❌ `EnableAdaptiveSampling`** - Removed, rate limited sampling is now the default.
### Properties Retained
- ✅ **`ConnectionString`** - Primary configuration method
-- ✅ **`EnableAdaptiveSampling`** - Still configurable (but behavior changed)
- - **2.x**: Controls traditional adaptive sampling
- - **3.x**: Maps to rate-limit based sampling in Azure Monitor Exporter, set at 5 OpenTelemetry traces per second by default
- ✅ **`ApplicationVersion`**
- ✅ **`AddAutoCollectedMetricExtractor`**
- ✅ **`EnableQuickPulseMetricStream`**
@@ -234,6 +232,8 @@ The following extension methods remain with identical signatures:
### New Properties Added in 3.x
- ✅ **`Credential`** (Azure.Core.TokenCredential) - Enables Azure Active Directory (AAD) authentication
+- ✅ **`TracesPerSecond`** (double?) - Gets or sets the number of traces per second for rate-limited sampling (default sampling mode). Replaces `EnableAdaptiveSampling`.
+- ✅ **`SamplingRatio`** (float?) - Gets or sets the sampling ratio for traces (0.0 to 1.0). A value of 1.0 means all telemetry is sent. Replaces `EnableAdaptiveSampling`.
### JavaScriptSnippet Constructor Change
**2.x:**
@@ -285,17 +285,22 @@ The following extension methods remain with identical signatures:
- ❌ **`DeveloperMode`** - No longer configurable
- ❌ **`EndpointAddress`** - No longer configurable (`ConnectionString` contains endpoints)
- ❌ **`DependencyCollectionOptions`** - Removed (non-functional, use OpenTelemetry instrumentation options)
+- ❌ **`EnableAdaptiveSampling`** - Removed, rate limited sampling is now the default.
### Properties Retained
- ✅ **`ConnectionString`** - Primary configuration method (maps to `AzureMonitorExporterOptions.ConnectionString`)
- ✅ **`ApplicationVersion`** - Still configurable
-- ✅ **`EnableAdaptiveSampling`** - When true the rate limited sampler is used at 5 traces per second.
- ✅ **`EnableDependencyTrackingTelemetryModule`** - Still configurable
- ✅ **`EnablePerformanceCounterCollectionModule`** - Still configurable
- ✅ **`EnableQuickPulseMetricStream`** - Maps to `AzureMonitorExporterOptions.EnableLiveMetrics`
- ✅ **`EnableDebugLogger`** - Still configurable though has no effect
- ✅ **`AddAutoCollectedMetricExtractor`** - Still configurable
+### New Properties Added in 3.x
+- ✅ **`Credential`** (Azure.Core.TokenCredential) - Enables Azure Active Directory (AAD) authentication
+- ✅ **`TracesPerSecond`** (double?) - Gets or sets the number of traces per second for rate-limited sampling (default sampling mode). Replaces `EnableAdaptiveSampling`.
+- ✅ **`SamplingRatio`** (float?) - Gets or sets the sampling ratio for traces (0.0 to 1.0). A value of 1.0 means all telemetry is sent. Replaces `EnableAdaptiveSampling`.
+
## Migration Impact
- Any code depending on `InstrumentationKey` must migrate to `ConnectionString`
- Code checking or configuring the removed options (`DeveloperMode`, `EndpointAddress`, etc.) will break
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2bf75e1e4..1bfb00185 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@
- OpenTelemetry.Instrumentation.SqlClient 1.15.0-rc.1
- 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)
## Version 3.0.0-beta2
### Added
diff --git a/NETCORE/Readme.md b/NETCORE/Readme.md
index 65fb9d0e0..d6d0693fb 100644
--- a/NETCORE/Readme.md
+++ b/NETCORE/Readme.md
@@ -159,11 +159,6 @@ builder.Services.AddApplicationInsightsTelemetry(options =>
// Enable or disable Live Metrics (default: true)
options.EnableQuickPulseMetricStream = true;
-
- // Enable or disable adaptive sampling (default: true)
- // When true, enables rate-limit based sampling in Azure Monitor Exporter
- // When false, sampling is disabled (100% collection)
- options.EnableAdaptiveSampling = true;
});
```
@@ -367,17 +362,6 @@ builder.Services.AddApplicationInsightsTelemetry(options =>
});
```
-#### Disabling Adaptive Sampling
-
-To collect 100% of telemetry (disable sampling):
-
-```csharp
-builder.Services.AddApplicationInsightsTelemetry(options =>
-{
- options.EnableAdaptiveSampling = false;
-});
-```
-
#### Dropping Specific Metrics Instruments
To exclude specific instruments from being collected:
@@ -464,8 +448,6 @@ The following features are **no longer available** in version 3.x:
3. **Configuration** - Connection strings are now configured via `ApplicationInsightsServiceOptions.ConnectionString` or `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable.
-4. **Sampling** - Sampling is now controlled by the `EnableAdaptiveSampling` option, which configures the Azure Monitor Exporter's sampling behavior.
-
5. **Live Metrics** - Still supported via the `EnableQuickPulseMetricStream` option.
### Migration Steps
@@ -898,7 +880,6 @@ After migrating, thoroughly test your application to ensure:
- [ ] Remove all ITelemetryProcessor implementations
- [ ] Remove all custom ITelemetryModule implementations
- [ ] Replace RequestCollectionOptions with AspNetCoreTraceInstrumentationOptions
-- [ ] Update sampling configuration (use EnableAdaptiveSampling)
- [ ] Test all custom telemetry collection
- [ ] Verify Live Metrics is working (if enabled)
- [ ] Verify all expected telemetry appears in Azure Monitor
diff --git a/NETCORE/WorkerService.md b/NETCORE/WorkerService.md
index c30142b6e..b30474787 100644
--- a/NETCORE/WorkerService.md
+++ b/NETCORE/WorkerService.md
@@ -119,7 +119,6 @@ builder.Services.AddApplicationInsightsTelemetryWorkerService(options =>
{
options.ConnectionString = "InstrumentationKey=...";
options.EnableQuickPulseMetricStream = true;
- options.EnableAdaptiveSampling = true;
});
```
diff --git a/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs b/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs
index e82a25d9c..245ad4c9b 100644
--- a/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs
+++ b/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs
@@ -210,12 +210,6 @@ internal static IOpenTelemetryBuilder UseApplicationInsightsTelemetry(this IOpen
{
exporterOptions.Credential = serviceOptions.Credential;
}
-
- if (!serviceOptions.EnableAdaptiveSampling)
- {
- exporterOptions.SamplingRatio = 1.0F;
- exporterOptions.TracesPerSecond = null;
- }
if (serviceOptions.EnableQuickPulseMetricStream)
{
@@ -226,6 +220,34 @@ internal static IOpenTelemetryBuilder UseApplicationInsightsTelemetry(this IOpen
exporterOptions.EnableLiveMetrics = false;
}
+ if (serviceOptions.TracesPerSecond.HasValue)
+ {
+ if (serviceOptions.TracesPerSecond.Value >= 0)
+ {
+ exporterOptions.TracesPerSecond = serviceOptions.TracesPerSecond.Value;
+ }
+ else
+ {
+ AspNetCoreEventSource.Instance.LogError($"Invalid TracesPerSecond value '{serviceOptions.TracesPerSecond.Value}'. Value must be at least 0. Using default value.");
+ }
+ }
+
+ if (serviceOptions.SamplingRatio.HasValue)
+ {
+ if (serviceOptions.SamplingRatio.Value >= 0.0f && serviceOptions.SamplingRatio.Value <= 1.0f)
+ {
+ exporterOptions.SamplingRatio = serviceOptions.SamplingRatio.Value;
+ if (!serviceOptions.TracesPerSecond.HasValue)
+ {
+ exporterOptions.TracesPerSecond = null;
+ }
+ }
+ else
+ {
+ AspNetCoreEventSource.Instance.LogError($"Invalid SamplingRatio value '{serviceOptions.SamplingRatio.Value}'. Value must be between 0.0 and 1.0. Using default value.");
+ }
+ }
+
// Configure standard metrics and performance counter collection using reflection
// Only set when false since the default is true
if (!serviceOptions.AddAutoCollectedMetricExtractor)
diff --git a/NETCORE/src/Microsoft.ApplicationInsights.WorkerService/ApplicationInsightsExtensions.cs b/NETCORE/src/Microsoft.ApplicationInsights.WorkerService/ApplicationInsightsExtensions.cs
index 0389d7e84..990f89847 100644
--- a/NETCORE/src/Microsoft.ApplicationInsights.WorkerService/ApplicationInsightsExtensions.cs
+++ b/NETCORE/src/Microsoft.ApplicationInsights.WorkerService/ApplicationInsightsExtensions.cs
@@ -206,13 +206,35 @@ internal static IOpenTelemetryBuilder UseApplicationInsightsTelemetry(this IOpen
exporterOptions.Credential = serviceOptions.Credential;
}
- if (!serviceOptions.EnableAdaptiveSampling)
+ exporterOptions.EnableLiveMetrics = serviceOptions.EnableQuickPulseMetricStream;
+
+ if (serviceOptions.TracesPerSecond.HasValue)
{
- exporterOptions.SamplingRatio = 1.0F;
- exporterOptions.TracesPerSecond = null;
+ if (serviceOptions.TracesPerSecond.Value >= 0)
+ {
+ exporterOptions.TracesPerSecond = serviceOptions.TracesPerSecond.Value;
+ }
+ else
+ {
+ WorkerServiceEventSource.Instance.LogError($"Invalid TracesPerSecond value '{serviceOptions.TracesPerSecond.Value}'. Value must be at least 0. Using default value.");
+ }
}
- exporterOptions.EnableLiveMetrics = serviceOptions.EnableQuickPulseMetricStream;
+ if (serviceOptions.SamplingRatio.HasValue)
+ {
+ if (serviceOptions.SamplingRatio.Value >= 0.0f && serviceOptions.SamplingRatio.Value <= 1.0f)
+ {
+ exporterOptions.SamplingRatio = serviceOptions.SamplingRatio.Value;
+ if (!serviceOptions.TracesPerSecond.HasValue)
+ {
+ exporterOptions.TracesPerSecond = null;
+ }
+ }
+ else
+ {
+ WorkerServiceEventSource.Instance.LogError($"Invalid SamplingRatio value '{serviceOptions.SamplingRatio.Value}'. Value must be between 0.0 and 1.0. Using default value.");
+ }
+ }
// Configure standard metrics and performance counter collection using reflection
// Only set when false since the default is true
diff --git a/NETCORE/src/Shared/Extensions/ApplicationInsightsServiceOptions.cs b/NETCORE/src/Shared/Extensions/ApplicationInsightsServiceOptions.cs
index b7e8b5cc8..fdc3e7814 100644
--- a/NETCORE/src/Shared/Extensions/ApplicationInsightsServiceOptions.cs
+++ b/NETCORE/src/Shared/Extensions/ApplicationInsightsServiceOptions.cs
@@ -30,14 +30,6 @@ public class ApplicationInsightsServiceOptions
///
public bool EnableDependencyTrackingTelemetryModule { get; set; } = true;
- ///
- /// Gets or sets a value indicating whether telemetry processor that controls sampling is added to the service.
- /// Setting EnableAdaptiveSampling to false, will disable sampling entirely.
- /// When true (default), enables rate-limit based sampling in Azure Monitor Exporter.
- /// Defaults to true.
- ///
- public bool EnableAdaptiveSampling { get; set; } = true;
-
///
/// Gets or sets the connection string for the application.
///
@@ -61,6 +53,17 @@ public class ApplicationInsightsServiceOptions
///
public bool AddAutoCollectedMetricExtractor { get; set; } = true;
+ ///
+ /// Gets or sets the target number of traces per second to be collected.
+ ///
+ public double? TracesPerSecond { get; set; }
+
+ ///
+ /// Gets or sets the sampling ratio for telemetry.
+ /// Value must be between 0.0 and 1.0, where 1.0 means all telemetry is collected (no sampling).
+ ///
+ public float? SamplingRatio { get; set; }
+
#if AI_ASPNETCORE_WEB
///
/// Gets or sets a value indicating whether RequestTrackingTelemetryModule should be enabled.
@@ -92,11 +95,12 @@ internal void CopyPropertiesTo(ApplicationInsightsServiceOptions target)
}
target.ApplicationVersion = this.ApplicationVersion;
- target.EnableAdaptiveSampling = this.EnableAdaptiveSampling;
target.EnableQuickPulseMetricStream = this.EnableQuickPulseMetricStream;
target.AddAutoCollectedMetricExtractor = this.AddAutoCollectedMetricExtractor;
target.EnablePerformanceCounterCollectionModule = this.EnablePerformanceCounterCollectionModule;
target.EnableDependencyTrackingTelemetryModule = this.EnableDependencyTrackingTelemetryModule;
+ target.TracesPerSecond = this.TracesPerSecond;
+ target.SamplingRatio = this.SamplingRatio;
#if AI_ASPNETCORE_WEB
target.EnableAuthenticationTrackingJavaScript = this.EnableAuthenticationTrackingJavaScript;
diff --git a/NETCORE/test/IntegrationTests.Tests/CustomWebApplicationFactory.cs b/NETCORE/test/IntegrationTests.Tests/CustomWebApplicationFactory.cs
index 382d9897d..d860ea834 100644
--- a/NETCORE/test/IntegrationTests.Tests/CustomWebApplicationFactory.cs
+++ b/NETCORE/test/IntegrationTests.Tests/CustomWebApplicationFactory.cs
@@ -43,8 +43,8 @@ protected override void ConfigureWebHost(IWebHostBuilder builder)
{
options.AddAutoCollectedMetricExtractor = false;
options.EnableQuickPulseMetricStream = false;
- options.EnableAdaptiveSampling = false;
options.ConnectionString = "InstrumentationKey=ikey";
+ options.SamplingRatio = 1.0f; // 100% telemetry flow in tests
});
});
}
diff --git a/NETCORE/test/IntegrationTests.Tests/content/config-all-default.json b/NETCORE/test/IntegrationTests.Tests/content/config-all-default.json
index 2506a4083..a6e2e18d0 100644
--- a/NETCORE/test/IntegrationTests.Tests/content/config-all-default.json
+++ b/NETCORE/test/IntegrationTests.Tests/content/config-all-default.json
@@ -1,7 +1,6 @@
{
"ApplicationInsights": {
"ConnectionString": "InstrumentationKey=11111111-2222-3333-4444-555555555555;IngestionEndpoint=http://testendpoint",
- "EnableAdaptiveSampling": false,
"EnableQuickPulseMetricStream": true,
"ApplicationVersion": "Version"
}
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 c7a4d1e5e..2821b2414 100644
--- a/NETCORE/test/IntegrationTests.Tests/content/config-all-settings-false.json
+++ b/NETCORE/test/IntegrationTests.Tests/content/config-all-settings-false.json
@@ -1,7 +1,6 @@
{
"ApplicationInsights": {
"ConnectionString": "InstrumentationKey=22222222-2222-3333-4444-555555555555",
- "EnableAdaptiveSampling": false,
"EnableQuickPulseMetricStream": 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 47ca8f1da..225bf5f26 100644
--- a/NETCORE/test/IntegrationTests.Tests/content/config-all-settings-true.json
+++ b/NETCORE/test/IntegrationTests.Tests/content/config-all-settings-true.json
@@ -1,7 +1,6 @@
{
"ApplicationInsights": {
"ConnectionString": "InstrumentationKey=22222222-2222-3333-4444-555555555555",
- "EnableAdaptiveSampling": true,
"EnableQuickPulseMetricStream": true,
"ApplicationVersion": "1.0.0"
}
diff --git a/NETCORE/test/IntegrationTests.Tests/content/config-sampling-tracespersecond.json b/NETCORE/test/IntegrationTests.Tests/content/config-sampling-tracespersecond.json
new file mode 100644
index 000000000..0d46df2e4
--- /dev/null
+++ b/NETCORE/test/IntegrationTests.Tests/content/config-sampling-tracespersecond.json
@@ -0,0 +1,6 @@
+{
+ "ApplicationInsights": {
+ "ConnectionString": "InstrumentationKey=33333333-4444-5555-6666-777777777777",
+ "TracesPerSecond": 10.0
+ }
+}
diff --git a/NETCORE/test/IntegrationTests.Tests/content/config-samplingratio.json b/NETCORE/test/IntegrationTests.Tests/content/config-samplingratio.json
new file mode 100644
index 000000000..70f4fee1e
--- /dev/null
+++ b/NETCORE/test/IntegrationTests.Tests/content/config-samplingratio.json
@@ -0,0 +1,6 @@
+{
+ "ApplicationInsights": {
+ "ConnectionString": "InstrumentationKey=44444444-5555-6666-7777-888888888888",
+ "SamplingRatio": 0.5
+ }
+}
diff --git a/NETCORE/test/Microsoft.ApplicationInsights.AspNetCore.Tests/Extensions/ApplicationInsightsExtensionsTests/AddApplicationInsightsTelemetryTests.cs b/NETCORE/test/Microsoft.ApplicationInsights.AspNetCore.Tests/Extensions/ApplicationInsightsExtensionsTests/AddApplicationInsightsTelemetryTests.cs
index 18ecc062b..0720e269d 100644
--- a/NETCORE/test/Microsoft.ApplicationInsights.AspNetCore.Tests/Extensions/ApplicationInsightsExtensionsTests/AddApplicationInsightsTelemetryTests.cs
+++ b/NETCORE/test/Microsoft.ApplicationInsights.AspNetCore.Tests/Extensions/ApplicationInsightsExtensionsTests/AddApplicationInsightsTelemetryTests.cs
@@ -595,7 +595,6 @@ public static void AppApplicationInsightsTelemetryFromApplicationInsightsService
{
ApplicationVersion = "test",
DeveloperMode = true,
- EnableAdaptiveSampling = false,
EnableAuthenticationTrackingJavaScript = false,
EnableDebugLogger = true,
EnableQuickPulseMetricStream = false,
@@ -1062,71 +1061,6 @@ public static void ConfigureApplicationInsightsTelemetryModuleDoesNotThrowIfModu
Assert.Null(testTelemetryModule);
}
- [Fact]
- public static void AddsAddaptiveSamplingServiceToTheConfigurationByDefault()
- {
- var services = CreateServicesAndAddApplicationinsightsTelemetry(null, "http://localhost:1234/v2/track/", null, false);
- IServiceProvider serviceProvider = services.BuildServiceProvider();
- var telemetryConfiguration = serviceProvider.GetTelemetryConfiguration();
- var adaptiveSamplingProcessorCount = GetTelemetryProcessorsCountInConfigurationDefaultSink(telemetryConfiguration);
-
- // There will be 2 separate SamplingTelemetryProcessors - one for Events, and other for everything else.
- Assert.Equal(2, adaptiveSamplingProcessorCount);
- }
-
- ///
- /// User could enable or disable sampling by setting EnableAdaptiveSampling.
- /// This configuration can be read from a JSON file by the configuration factory or through code by passing ApplicationInsightsServiceOptions.
- ///
- ///
- /// DefaultConfiguration - calls services.AddApplicationInsightsTelemetry() which reads IConfiguration from user application automatically.
- /// SuppliedConfiguration - invokes services.AddApplicationInsightsTelemetry(configuration) where IConfiguration object is supplied by caller.
- /// Code - Caller creates an instance of ApplicationInsightsServiceOptions and passes it. This option overrides all configuration being used in JSON file.
- /// There is a special case where NULL values in these properties - InstrumentationKey, ConnectionString, EndpointAddress and DeveloperMode are overwritten. We check IConfiguration object to see if these properties have values, if values are present then we override it.
- ///
- /// Sets the value for property EnableAdaptiveSampling.
- [Theory]
- [InlineData("DefaultConfiguration", true)]
- [InlineData("DefaultConfiguration", false)]
- [InlineData("SuppliedConfiguration", true)]
- [InlineData("SuppliedConfiguration", false)]
- [InlineData("Code", true)]
- [InlineData("Code", false)]
- public static void DoesNotAddSamplingToConfigurationIfExplicitlyControlledThroughParameter(string configType, bool isEnable)
- {
- // ARRANGE
- Action serviceOptions = null;
- var filePath = Path.Combine("content", "config-all-settings-" + isEnable.ToString().ToLower() + ".json");
-
- if (configType == "Code")
- {
- serviceOptions = o => { o.EnableAdaptiveSampling = isEnable; };
- filePath = null;
- }
-
- // ACT
- var services = CreateServicesAndAddApplicationinsightsTelemetry(filePath, null, serviceOptions, true, configType == "DefaultConfiguration" ? true : false);
-
- // VALIDATE
- IServiceProvider serviceProvider = services.BuildServiceProvider();
- var telemetryConfiguration = serviceProvider.GetTelemetryConfiguration();
- var qpProcessorCount = GetTelemetryProcessorsCountInConfigurationDefaultSink(telemetryConfiguration);
- // There will be 2 separate SamplingTelemetryProcessors - one for Events, and other for everything else.
- Assert.Equal(isEnable ? 2 : 0, qpProcessorCount);
- }
-
- [Fact]
- public static void AddsAddaptiveSamplingServiceToTheConfigurationWithServiceOptions()
- {
- Action serviceOptions = options => options.EnableAdaptiveSampling = true;
- var services = CreateServicesAndAddApplicationinsightsTelemetry(null, "http://localhost:1234/v2/track/", serviceOptions, false);
- IServiceProvider serviceProvider = services.BuildServiceProvider();
- var telemetryConfiguration = serviceProvider.GetTelemetryConfiguration();
- var adaptiveSamplingProcessorCount = GetTelemetryProcessorsCountInConfigurationDefaultSink(telemetryConfiguration);
- // There will be 2 separate SamplingTelemetryProcessors - one for Events, and other for everything else.
- Assert.Equal(2, adaptiveSamplingProcessorCount);
- }
-
[Fact]
public static void AddsServerTelemetryChannelByDefault()
{
@@ -1257,9 +1191,6 @@ public static void ValidatesThatOnlyPassThroughProcessorIsAddedToCommonPipeline(
var metricExtractorProcessorCount = GetTelemetryProcessorsCountInConfiguration(telemetryConfiguration);
Assert.Equal(0, metricExtractorProcessorCount);
- var samplingProcessorCount = GetTelemetryProcessorsCountInConfiguration(telemetryConfiguration);
- Assert.Equal(0, samplingProcessorCount);
-
var passThroughProcessorCount = telemetryConfiguration.TelemetryProcessors.Count;
Assert.Equal(1, passThroughProcessorCount);
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 5d8346e32..1309ab919 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
@@ -2,7 +2,6 @@
"ApplicationInsights": {
"InstrumentationKey": "11111111-2222-3333-4444-555555555555",
"ConnectionString": "InstrumentationKey=11111111-2222-3333-4444-555555555555;IngestionEndpoint=http://testendpoint",
- "EnableAdaptiveSampling": false,
"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 705591032..c0716fd14 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
@@ -2,7 +2,6 @@
"ApplicationInsights": {
"InstrumentationKey": "22222222-2222-3333-4444-555555555555",
"ConnectionString": "InstrumentationKey=22222222-2222-3333-4444-555555555555;IngestionEndpoint=http://testendpoint",
- "EnableAdaptiveSampling": 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 69672bbc9..4b20494b8 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
@@ -2,7 +2,6 @@
"ApplicationInsights": {
"InstrumentationKey": "22222222-2222-3333-4444-555555555555",
"ConnectionString": "InstrumentationKey=22222222-2222-3333-4444-555555555555;IngestionEndpoint=http://testendpoint",
- "EnableAdaptiveSampling": true,
"EnablePerformanceCounterCollectionModule": true,
"EnableAzureInstanceMetadataTelemetryModule": true,
"EnableRequestTrackingTelemetryModule": true,
diff --git a/NETCORE/test/Microsoft.ApplicationInsights.WorkerService.Tests/ExtensionsTest.cs b/NETCORE/test/Microsoft.ApplicationInsights.WorkerService.Tests/ExtensionsTest.cs
index 8bca10679..3930669f2 100644
--- a/NETCORE/test/Microsoft.ApplicationInsights.WorkerService.Tests/ExtensionsTest.cs
+++ b/NETCORE/test/Microsoft.ApplicationInsights.WorkerService.Tests/ExtensionsTest.cs
@@ -404,7 +404,6 @@ public void VerifyAddAIWorkerServiceSetsUpDefaultConfigurationAndModules()
// TelemetryProcessors
Assert.Contains(telemetryConfiguration.DefaultTelemetrySink.TelemetryProcessors, proc => proc.GetType().Name.Contains("AutocollectedMetricsExtractor"));
- Assert.Contains(telemetryConfiguration.DefaultTelemetrySink.TelemetryProcessors, proc => proc.GetType().Name.Contains("AdaptiveSamplingTelemetryProcessor"));
Assert.Contains(telemetryConfiguration.DefaultTelemetrySink.TelemetryProcessors, proc => proc.GetType().Name.Contains("QuickPulseTelemetryProcessor"));
// TelemetryInitializers
@@ -483,7 +482,6 @@ public void VerifyAddAIWorkerServiceRespectsAIOptions()
// ACT
var aiOptions = new ApplicationInsightsServiceOptions();
aiOptions.AddAutoCollectedMetricExtractor = false;
- aiOptions.EnableAdaptiveSampling = false;
aiOptions.EnableQuickPulseMetricStream = false;
aiOptions.InstrumentationKey = "keyfromaioption";
services.AddApplicationInsightsTelemetryWorkerService(aiOptions);
@@ -493,7 +491,6 @@ public void VerifyAddAIWorkerServiceRespectsAIOptions()
var telemetryConfiguration = serviceProvider.GetRequiredService();
Assert.Equal("keyfromaioption", telemetryConfiguration.InstrumentationKey);
Assert.DoesNotContain(telemetryConfiguration.DefaultTelemetrySink.TelemetryProcessors, proc => proc.GetType().Name.Contains("AutocollectedMetricsExtractor"));
- Assert.DoesNotContain(telemetryConfiguration.DefaultTelemetrySink.TelemetryProcessors, proc => proc.GetType().Name.Contains("AdaptiveSamplingTelemetryProcessor"));
Assert.DoesNotContain(telemetryConfiguration.DefaultTelemetrySink.TelemetryProcessors, proc => proc.GetType().Name.Contains("QuickPulseTelemetryProcessor"));
}
@@ -719,47 +716,6 @@ public static void UserCanEnableAndDisableHeartbeatFeature(string configType, bo
Assert.Equal(isEnable, module.IsHeartbeatEnabled);
}
- ///
- /// User could enable or disable sampling by setting EnableAdaptiveSampling.
- /// This configuration can be read from a JSON file by the configuration factory or through code by passing ApplicationInsightsServiceOptions.
- ///
- ///
- /// DefaultConfiguration - calls services.AddApplicationInsightsTelemetryWorkerService() which reads IConfiguration from user application automatically.
- /// SuppliedConfiguration - invokes services.AddApplicationInsightsTelemetryWorkerService(configuration) where IConfiguration object is supplied by caller.
- /// Code - Caller creates an instance of ApplicationInsightsServiceOptions and passes it. This option overrides all configuration being used in JSON file.
- /// There is a special case where NULL values in these properties - InstrumentationKey, ConnectionString, EndpointAddress and DeveloperMode are overwritten. We check IConfiguration object to see if these properties have values, if values are present then we override it.
- ///
- /// Sets the value for property EnableAdaptiveSampling.
- [Theory]
- [InlineData("DefaultConfiguration", true)]
- [InlineData("DefaultConfiguration", false)]
- [InlineData("SuppliedConfiguration", true)]
- [InlineData("SuppliedConfiguration", false)]
- [InlineData("Code", true)]
- [InlineData("Code", false)]
- public static void DoesNotAddSamplingToConfigurationIfExplicitlyControlledThroughParameter(string configType, bool isEnable)
- {
- // ARRANGE
- Action serviceOptions = null;
- var filePath = Path.Combine("content", "config-all-settings-" + isEnable.ToString().ToLower() + ".json");
-
- if (configType == "Code")
- {
- serviceOptions = o => { o.EnableAdaptiveSampling = isEnable; };
- filePath = null;
- }
-
- // ACT
- var services = CreateServicesAndAddApplicationinsightsWorker(filePath, serviceOptions, configType == "DefaultConfiguration" ? true : false);
-
- // VALIDATE
- IServiceProvider serviceProvider = services.BuildServiceProvider();
- var telemetryConfiguration = serviceProvider.GetRequiredService>().Value;
- var qpProcessorCount = GetTelemetryProcessorsCountInConfigurationDefaultSink(telemetryConfiguration);
- // There will be 2 separate SamplingTelemetryProcessors - one for Events, and other for everything else.
- Assert.Equal(isEnable ? 2 : 0, qpProcessorCount);
- }
-
///
/// User could enable or disable auto collected metrics by setting AddAutoCollectedMetricExtractor.
/// This configuration can be read from a JSON file by the configuration factory or through code by passing ApplicationInsightsServiceOptions.
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 5d8346e32..1309ab919 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
@@ -2,7 +2,6 @@
"ApplicationInsights": {
"InstrumentationKey": "11111111-2222-3333-4444-555555555555",
"ConnectionString": "InstrumentationKey=11111111-2222-3333-4444-555555555555;IngestionEndpoint=http://testendpoint",
- "EnableAdaptiveSampling": false,
"EnablePerformanceCounterCollectionModule": true,
"EnableAzureInstanceMetadataTelemetryModule": true,
"EnableRequestTrackingTelemetryModule": 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 705591032..c0716fd14 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
@@ -2,7 +2,6 @@
"ApplicationInsights": {
"InstrumentationKey": "22222222-2222-3333-4444-555555555555",
"ConnectionString": "InstrumentationKey=22222222-2222-3333-4444-555555555555;IngestionEndpoint=http://testendpoint",
- "EnableAdaptiveSampling": 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 69672bbc9..4b20494b8 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
@@ -2,7 +2,6 @@
"ApplicationInsights": {
"InstrumentationKey": "22222222-2222-3333-4444-555555555555",
"ConnectionString": "InstrumentationKey=22222222-2222-3333-4444-555555555555;IngestionEndpoint=http://testendpoint",
- "EnableAdaptiveSampling": true,
"EnablePerformanceCounterCollectionModule": true,
"EnableAzureInstanceMetadataTelemetryModule": true,
"EnableRequestTrackingTelemetryModule": true,
diff --git a/NETCORE/test/Shared/ConfigurationTests.cs b/NETCORE/test/Shared/ConfigurationTests.cs
index 9833139b8..6e936be98 100644
--- a/NETCORE/test/Shared/ConfigurationTests.cs
+++ b/NETCORE/test/Shared/ConfigurationTests.cs
@@ -14,6 +14,7 @@ namespace Microsoft.ApplicationInsights.AspNetCore.Tests
#else
namespace Microsoft.ApplicationInsights.WorkerService.Tests
{
+ using System.Reflection;
using Microsoft.ApplicationInsights.WorkerService;
#endif
@@ -52,7 +53,7 @@ public void ReadsConnectionStringFromApplicationInsightsSectionInConfig()
}
[Fact]
- public void ReadsEnableAdaptiveSamplingFromApplicationInsightsSectionInConfig()
+ public void ReadsEnableQuickPulseMetricStreamFromApplicationInsightsSectionInConfig()
{
// ARRANGE
var jsonFullPath = Path.Combine(Directory.GetCurrentDirectory(), "content", "config-all-settings-false.json");
@@ -72,19 +73,14 @@ public void ReadsEnableAdaptiveSamplingFromApplicationInsightsSectionInConfig()
// VALIDATE
IServiceProvider serviceProvider = services.BuildServiceProvider();
var options = serviceProvider.GetRequiredService>().Value;
- Assert.False(options.EnableAdaptiveSampling);
-
- // Verify underlying AzureMonitorExporterOptions
- var exporterOptions = serviceProvider.GetRequiredService>().Value;
- Assert.Equal(1.0F, exporterOptions.SamplingRatio);
- Assert.Null(exporterOptions.TracesPerSecond);
+ Assert.False(options.EnableQuickPulseMetricStream);
}
[Fact]
- public void DefaultEnableAdaptiveSampling_ExporterHasDefaultSamplingValues()
+ public void ReadsApplicationVersionFromApplicationInsightsSectionInConfig()
{
- // ARRANGE - use config that doesn't specify EnableAdaptiveSampling
- var jsonFullPath = Path.Combine(Directory.GetCurrentDirectory(), "content", "config-connection-string.json");
+ // 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();
@@ -92,27 +88,20 @@ public void DefaultEnableAdaptiveSampling_ExporterHasDefaultSamplingValues()
services.AddSingleton(config);
// ACT
- #if AI_ASPNETCORE_WEB
+#if AI_ASPNETCORE_WEB
services.AddApplicationInsightsTelemetry();
- #else
+#else
services.AddApplicationInsightsTelemetryWorkerService();
- #endif
+#endif
// VALIDATE
IServiceProvider serviceProvider = services.BuildServiceProvider();
-
- // Verify ApplicationInsightsServiceOptions has default EnableAdaptiveSampling = true
var options = serviceProvider.GetRequiredService>().Value;
- Assert.True(options.EnableAdaptiveSampling);
-
- // Verify underlying AzureMonitorExporterOptions for adaptive sampling
- var exporterOptions = serviceProvider.GetRequiredService>().Value;
- Assert.Equal(1.0F, exporterOptions.SamplingRatio);
- Assert.Equal(5.0, exporterOptions.TracesPerSecond);
+ Assert.Equal("1.0.0", options.ApplicationVersion);
}
[Fact]
- public void ReadsEnableQuickPulseMetricStreamFromApplicationInsightsSectionInConfig()
+ public void ConfigurationFlowsFromApplicationInsightsSectionToAzureMonitorExporter()
{
// ARRANGE
var jsonFullPath = Path.Combine(Directory.GetCurrentDirectory(), "content", "config-all-settings-false.json");
@@ -131,15 +120,25 @@ public void ReadsEnableQuickPulseMetricStreamFromApplicationInsightsSectionInCon
// VALIDATE
IServiceProvider serviceProvider = services.BuildServiceProvider();
- var options = serviceProvider.GetRequiredService>().Value;
- Assert.False(options.EnableQuickPulseMetricStream);
+
+ // Verify ApplicationInsightsServiceOptions
+ var aiOptions = serviceProvider.GetRequiredService>().Value;
+ Assert.Equal("InstrumentationKey=22222222-2222-3333-4444-555555555555", aiOptions.ConnectionString);
+ Assert.False(aiOptions.EnableQuickPulseMetricStream);
+
+ // 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);
+ Assert.Equal(5, exporterOptions.TracesPerSecond);
+ Assert.False(exporterOptions.EnableLiveMetrics);
}
[Fact]
- public void ReadsApplicationVersionFromApplicationInsightsSectionInConfig()
+ public void ReadsTracesPerSecondFromApplicationInsightsSectionInConfig()
{
// ARRANGE
- var jsonFullPath = Path.Combine(Directory.GetCurrentDirectory(), "content", "config-all-settings-true.json");
+ var jsonFullPath = Path.Combine(Directory.GetCurrentDirectory(), "content", "config-sampling-tracespersecond.json");
this.output.WriteLine("json:" + jsonFullPath);
var config = new ConfigurationBuilder().AddJsonFile(jsonFullPath).Build();
@@ -156,14 +155,18 @@ public void ReadsApplicationVersionFromApplicationInsightsSectionInConfig()
// VALIDATE
IServiceProvider serviceProvider = services.BuildServiceProvider();
var options = serviceProvider.GetRequiredService>().Value;
- Assert.Equal("1.0.0", options.ApplicationVersion);
+ 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 ConfigurationFlowsFromApplicationInsightsSectionToAzureMonitorExporter()
+ public void ReadsSamplingRatioFromApplicationInsightsSectionInConfig()
{
// ARRANGE
- var jsonFullPath = Path.Combine(Directory.GetCurrentDirectory(), "content", "config-all-settings-false.json");
+ var jsonFullPath = Path.Combine(Directory.GetCurrentDirectory(), "content", "config-samplingratio.json");
this.output.WriteLine("json:" + jsonFullPath);
var config = new ConfigurationBuilder().AddJsonFile(jsonFullPath).Build();
@@ -179,18 +182,66 @@ public void ConfigurationFlowsFromApplicationInsightsSectionToAzureMonitorExport
// VALIDATE
IServiceProvider serviceProvider = services.BuildServiceProvider();
-
- // Verify ApplicationInsightsServiceOptions
- var aiOptions = serviceProvider.GetRequiredService>().Value;
- Assert.Equal("InstrumentationKey=22222222-2222-3333-4444-555555555555", aiOptions.ConnectionString);
- Assert.False(aiOptions.EnableAdaptiveSampling);
- Assert.False(aiOptions.EnableQuickPulseMetricStream);
-
- // Verify AzureMonitorExporterOptions gets the values
+ var options = serviceProvider.GetRequiredService>().Value;
+ Assert.Equal(0.5f, options.SamplingRatio);
+
+ // Verify it flows to exporter options
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(0.5f, exporterOptions.SamplingRatio);
+ }
+
+ [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.Equal(5.0, exporterOptions.TracesPerSecond);
+ }
+
+ [Fact]
+ public void SamplingRatioIgnoresInvalidValues()
+ {
+ // 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.SamplingRatio = 1.5f; // Invalid value (> 1.0)
+ });
+
+ // VALIDATE
+ IServiceProvider serviceProvider = services.BuildServiceProvider();
+ var exporterOptions = serviceProvider.GetRequiredService>().Value;
+
+ // SamplingRatio should not be set to an invalid value
+ Assert.NotEqual(1.5f, exporterOptions.SamplingRatio);
}
[Fact]
diff --git a/NETCORE/test/WorkerIntegrationTests.Tests/WorkerHostFixture.cs b/NETCORE/test/WorkerIntegrationTests.Tests/WorkerHostFixture.cs
index bb0360453..932a30ef3 100644
--- a/NETCORE/test/WorkerIntegrationTests.Tests/WorkerHostFixture.cs
+++ b/NETCORE/test/WorkerIntegrationTests.Tests/WorkerHostFixture.cs
@@ -57,9 +57,9 @@ public async Task InitializeAsync()
services.Configure(options =>
{
options.ConnectionString = TestConnectionString;
- options.EnableAdaptiveSampling = false;
options.EnableQuickPulseMetricStream = false;
options.AddAutoCollectedMetricExtractor = false;
+ options.SamplingRatio = 1.0f; // 100% telemetry flow in tests
});
services.ConfigureOpenTelemetryTracerProvider(tracer =>