Skip to content

Commit e1bb83d

Browse files
authored
Merge pull request #3085 from microsoft/harskaur/removeEnableAdaptiveSampling
Remove EnableAdaptiveSampling and replace with TracesPerSecond and SamplingRatio
2 parents 10ad75f + 8efaec2 commit e1bb83d

File tree

25 files changed

+190
-211
lines changed

25 files changed

+190
-211
lines changed

.publicApi/Microsoft.ApplicationInsights.AspNetCore.dll/Stable/PublicAPI.Unshipped.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOp
88
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.ConnectionString.set -> void
99
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.Credential.get -> Azure.Core.TokenCredential
1010
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.Credential.set -> void
11-
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableAdaptiveSampling.get -> bool
12-
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableAdaptiveSampling.set -> void
1311
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableAuthenticationTrackingJavaScript.get -> bool
1412
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableAuthenticationTrackingJavaScript.set -> void
1513
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableDependencyTrackingTelemetryModule.get -> bool
@@ -18,6 +16,10 @@ Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOp
1816
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnablePerformanceCounterCollectionModule.set -> void
1917
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableQuickPulseMetricStream.get -> bool
2018
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableQuickPulseMetricStream.set -> void
19+
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.SamplingRatio.get -> float?
20+
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.SamplingRatio.set -> void
21+
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.TracesPerSecond.get -> double?
22+
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.TracesPerSecond.set -> void
2123
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableRequestTrackingTelemetryModule.get -> bool
2224
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions.EnableRequestTrackingTelemetryModule.set -> void
2325
Microsoft.ApplicationInsights.AspNetCore.IJavaScriptSnippet

.publicApi/Microsoft.ApplicationInsights.WorkerService.dll/Stable/PublicAPI.Unshipped.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.Co
88
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.ConnectionString.set -> void
99
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.Credential.get -> Azure.Core.TokenCredential
1010
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.Credential.set -> void
11-
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EnableAdaptiveSampling.get -> bool
12-
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EnableAdaptiveSampling.set -> void
1311
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EnableDependencyTrackingTelemetryModule.get -> bool
1412
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EnableDependencyTrackingTelemetryModule.set -> void
1513
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EnablePerformanceCounterCollectionModule.get -> bool
1614
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EnablePerformanceCounterCollectionModule.set -> void
1715
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EnableQuickPulseMetricStream.get -> bool
1816
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.EnableQuickPulseMetricStream.set -> void
17+
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.SamplingRatio.get -> float?
18+
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.SamplingRatio.set -> void
19+
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.TracesPerSecond.get -> double?
20+
Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions.TracesPerSecond.set -> void
1921
Microsoft.Extensions.DependencyInjection.ApplicationInsightsExtensions
2022
static Microsoft.Extensions.DependencyInjection.ApplicationInsightsExtensions.AddApplicationInsightsTelemetryWorkerService(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection
2123
static Microsoft.Extensions.DependencyInjection.ApplicationInsightsExtensions.AddApplicationInsightsTelemetryWorkerService(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Microsoft.ApplicationInsights.WorkerService.ApplicationInsightsServiceOptions options) -> Microsoft.Extensions.DependencyInjection.IServiceCollection

BreakingChanges.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,10 @@ The following extension methods remain with identical signatures:
217217
-**`EnableHeartbeat`** - Heartbeat configuration removed
218218
-**`RequestCollectionOptions`** - Removed (non-functional, use OpenTelemetry instrumentation options)
219219
-**`DependencyCollectionOptions`** - Removed (non-functional, use OpenTelemetry instrumentation options)
220+
-`EnableAdaptiveSampling`** - Removed, rate limited sampling is now the default.
220221

221222
### Properties Retained
222223
-**`ConnectionString`** - Primary configuration method
223-
-**`EnableAdaptiveSampling`** - Still configurable (but behavior changed)
224-
- **2.x**: Controls traditional adaptive sampling
225-
- **3.x**: Maps to rate-limit based sampling in Azure Monitor Exporter, set at 5 OpenTelemetry traces per second by default
226224
-**`ApplicationVersion`**
227225
-**`AddAutoCollectedMetricExtractor`**
228226
-**`EnableQuickPulseMetricStream`**
@@ -234,6 +232,8 @@ The following extension methods remain with identical signatures:
234232

235233
### New Properties Added in 3.x
236234
-**`Credential`** (Azure.Core.TokenCredential) - Enables Azure Active Directory (AAD) authentication
235+
-**`TracesPerSecond`** (double?) - Gets or sets the number of traces per second for rate-limited sampling (default sampling mode). Replaces `EnableAdaptiveSampling`.
236+
-**`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`.
237237

238238
### JavaScriptSnippet Constructor Change
239239
**2.x:**
@@ -285,17 +285,22 @@ The following extension methods remain with identical signatures:
285285
-**`DeveloperMode`** - No longer configurable
286286
-**`EndpointAddress`** - No longer configurable (`ConnectionString` contains endpoints)
287287
-**`DependencyCollectionOptions`** - Removed (non-functional, use OpenTelemetry instrumentation options)
288+
-**`EnableAdaptiveSampling`** - Removed, rate limited sampling is now the default.
288289

289290
### Properties Retained
290291
-**`ConnectionString`** - Primary configuration method (maps to `AzureMonitorExporterOptions.ConnectionString`)
291292
-**`ApplicationVersion`** - Still configurable
292-
-**`EnableAdaptiveSampling`** - When true the rate limited sampler is used at 5 traces per second.
293293
-**`EnableDependencyTrackingTelemetryModule`** - Still configurable
294294
-**`EnablePerformanceCounterCollectionModule`** - Still configurable
295295
-**`EnableQuickPulseMetricStream`** - Maps to `AzureMonitorExporterOptions.EnableLiveMetrics`
296296
-**`EnableDebugLogger`** - Still configurable though has no effect
297297
-**`AddAutoCollectedMetricExtractor`** - Still configurable
298298

299+
### New Properties Added in 3.x
300+
-**`Credential`** (Azure.Core.TokenCredential) - Enables Azure Active Directory (AAD) authentication
301+
-**`TracesPerSecond`** (double?) - Gets or sets the number of traces per second for rate-limited sampling (default sampling mode). Replaces `EnableAdaptiveSampling`.
302+
-**`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`.
303+
299304
## Migration Impact
300305
- Any code depending on `InstrumentationKey` must migrate to `ConnectionString`
301306
- Code checking or configuring the removed options (`DeveloperMode`, `EndpointAddress`, etc.) will break

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- OpenTelemetry.Instrumentation.SqlClient 1.15.0-rc.1
1313
- OpenTelemetry.Resources.Azure 1.15.0-beta.1
1414
- [Added support to disable telemetry via TelemetryConfiguration.DisableTelemetry](https://github.com/microsoft/ApplicationInsights-dotnet/pull/3084)
15+
- [Removed `EnabledAdaptiveSampling` and replaced with `TracesPerSecond` and `SamplingRatio`](https://github.com/microsoft/ApplicationInsights-dotnet/pull/3085)
1516

1617
## Version 3.0.0-beta2
1718
### Added

NETCORE/Readme.md

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,6 @@ builder.Services.AddApplicationInsightsTelemetry(options =>
159159

160160
// Enable or disable Live Metrics (default: true)
161161
options.EnableQuickPulseMetricStream = true;
162-
163-
// Enable or disable adaptive sampling (default: true)
164-
// When true, enables rate-limit based sampling in Azure Monitor Exporter
165-
// When false, sampling is disabled (100% collection)
166-
options.EnableAdaptiveSampling = true;
167162
});
168163
```
169164

@@ -367,17 +362,6 @@ builder.Services.AddApplicationInsightsTelemetry(options =>
367362
});
368363
```
369364

370-
#### Disabling Adaptive Sampling
371-
372-
To collect 100% of telemetry (disable sampling):
373-
374-
```csharp
375-
builder.Services.AddApplicationInsightsTelemetry(options =>
376-
{
377-
options.EnableAdaptiveSampling = false;
378-
});
379-
```
380-
381365
#### Dropping Specific Metrics Instruments
382366

383367
To exclude specific instruments from being collected:
@@ -464,8 +448,6 @@ The following features are **no longer available** in version 3.x:
464448

465449
3. **Configuration** - Connection strings are now configured via `ApplicationInsightsServiceOptions.ConnectionString` or `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable.
466450

467-
4. **Sampling** - Sampling is now controlled by the `EnableAdaptiveSampling` option, which configures the Azure Monitor Exporter's sampling behavior.
468-
469451
5. **Live Metrics** - Still supported via the `EnableQuickPulseMetricStream` option.
470452

471453
### Migration Steps
@@ -898,7 +880,6 @@ After migrating, thoroughly test your application to ensure:
898880
- [ ] Remove all ITelemetryProcessor implementations
899881
- [ ] Remove all custom ITelemetryModule implementations
900882
- [ ] Replace RequestCollectionOptions with AspNetCoreTraceInstrumentationOptions
901-
- [ ] Update sampling configuration (use EnableAdaptiveSampling)
902883
- [ ] Test all custom telemetry collection
903884
- [ ] Verify Live Metrics is working (if enabled)
904885
- [ ] Verify all expected telemetry appears in Azure Monitor

NETCORE/WorkerService.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ builder.Services.AddApplicationInsightsTelemetryWorkerService(options =>
119119
{
120120
options.ConnectionString = "InstrumentationKey=...";
121121
options.EnableQuickPulseMetricStream = true;
122-
options.EnableAdaptiveSampling = true;
123122
});
124123
```
125124

NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,6 @@ internal static IOpenTelemetryBuilder UseApplicationInsightsTelemetry(this IOpen
210210
{
211211
exporterOptions.Credential = serviceOptions.Credential;
212212
}
213-
214-
if (!serviceOptions.EnableAdaptiveSampling)
215-
{
216-
exporterOptions.SamplingRatio = 1.0F;
217-
exporterOptions.TracesPerSecond = null;
218-
}
219213

220214
if (serviceOptions.EnableQuickPulseMetricStream)
221215
{
@@ -226,6 +220,34 @@ internal static IOpenTelemetryBuilder UseApplicationInsightsTelemetry(this IOpen
226220
exporterOptions.EnableLiveMetrics = false;
227221
}
228222

223+
if (serviceOptions.TracesPerSecond.HasValue)
224+
{
225+
if (serviceOptions.TracesPerSecond.Value >= 0)
226+
{
227+
exporterOptions.TracesPerSecond = serviceOptions.TracesPerSecond.Value;
228+
}
229+
else
230+
{
231+
AspNetCoreEventSource.Instance.LogError($"Invalid TracesPerSecond value '{serviceOptions.TracesPerSecond.Value}'. Value must be at least 0. Using default value.");
232+
}
233+
}
234+
235+
if (serviceOptions.SamplingRatio.HasValue)
236+
{
237+
if (serviceOptions.SamplingRatio.Value >= 0.0f && serviceOptions.SamplingRatio.Value <= 1.0f)
238+
{
239+
exporterOptions.SamplingRatio = serviceOptions.SamplingRatio.Value;
240+
if (!serviceOptions.TracesPerSecond.HasValue)
241+
{
242+
exporterOptions.TracesPerSecond = null;
243+
}
244+
}
245+
else
246+
{
247+
AspNetCoreEventSource.Instance.LogError($"Invalid SamplingRatio value '{serviceOptions.SamplingRatio.Value}'. Value must be between 0.0 and 1.0. Using default value.");
248+
}
249+
}
250+
229251
// Configure standard metrics and performance counter collection using reflection
230252
// Only set when false since the default is true
231253
if (!serviceOptions.AddAutoCollectedMetricExtractor)

NETCORE/src/Microsoft.ApplicationInsights.WorkerService/ApplicationInsightsExtensions.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,35 @@ internal static IOpenTelemetryBuilder UseApplicationInsightsTelemetry(this IOpen
206206
exporterOptions.Credential = serviceOptions.Credential;
207207
}
208208

209-
if (!serviceOptions.EnableAdaptiveSampling)
209+
exporterOptions.EnableLiveMetrics = serviceOptions.EnableQuickPulseMetricStream;
210+
211+
if (serviceOptions.TracesPerSecond.HasValue)
210212
{
211-
exporterOptions.SamplingRatio = 1.0F;
212-
exporterOptions.TracesPerSecond = null;
213+
if (serviceOptions.TracesPerSecond.Value >= 0)
214+
{
215+
exporterOptions.TracesPerSecond = serviceOptions.TracesPerSecond.Value;
216+
}
217+
else
218+
{
219+
WorkerServiceEventSource.Instance.LogError($"Invalid TracesPerSecond value '{serviceOptions.TracesPerSecond.Value}'. Value must be at least 0. Using default value.");
220+
}
213221
}
214222

215-
exporterOptions.EnableLiveMetrics = serviceOptions.EnableQuickPulseMetricStream;
223+
if (serviceOptions.SamplingRatio.HasValue)
224+
{
225+
if (serviceOptions.SamplingRatio.Value >= 0.0f && serviceOptions.SamplingRatio.Value <= 1.0f)
226+
{
227+
exporterOptions.SamplingRatio = serviceOptions.SamplingRatio.Value;
228+
if (!serviceOptions.TracesPerSecond.HasValue)
229+
{
230+
exporterOptions.TracesPerSecond = null;
231+
}
232+
}
233+
else
234+
{
235+
WorkerServiceEventSource.Instance.LogError($"Invalid SamplingRatio value '{serviceOptions.SamplingRatio.Value}'. Value must be between 0.0 and 1.0. Using default value.");
236+
}
237+
}
216238

217239
// Configure standard metrics and performance counter collection using reflection
218240
// Only set when false since the default is true

NETCORE/src/Shared/Extensions/ApplicationInsightsServiceOptions.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,6 @@ public class ApplicationInsightsServiceOptions
3030
/// </summary>
3131
public bool EnableDependencyTrackingTelemetryModule { get; set; } = true;
3232

33-
/// <summary>
34-
/// Gets or sets a value indicating whether telemetry processor that controls sampling is added to the service.
35-
/// Setting EnableAdaptiveSampling to <value>false</value>, will disable sampling entirely.
36-
/// When <value>true</value> (default), enables rate-limit based sampling in Azure Monitor Exporter.
37-
/// Defaults to <value>true</value>.
38-
/// </summary>
39-
public bool EnableAdaptiveSampling { get; set; } = true;
40-
4133
/// <summary>
4234
/// Gets or sets the connection string for the application.
4335
/// </summary>
@@ -61,6 +53,17 @@ public class ApplicationInsightsServiceOptions
6153
/// </summary>
6254
public bool AddAutoCollectedMetricExtractor { get; set; } = true;
6355

56+
/// <summary>
57+
/// Gets or sets the target number of traces per second to be collected.
58+
/// </summary>
59+
public double? TracesPerSecond { get; set; }
60+
61+
/// <summary>
62+
/// Gets or sets the sampling ratio for telemetry.
63+
/// Value must be between 0.0 and 1.0, where 1.0 means all telemetry is collected (no sampling).
64+
/// </summary>
65+
public float? SamplingRatio { get; set; }
66+
6467
#if AI_ASPNETCORE_WEB
6568
/// <summary>
6669
/// Gets or sets a value indicating whether RequestTrackingTelemetryModule should be enabled.
@@ -92,11 +95,12 @@ internal void CopyPropertiesTo(ApplicationInsightsServiceOptions target)
9295
}
9396

9497
target.ApplicationVersion = this.ApplicationVersion;
95-
target.EnableAdaptiveSampling = this.EnableAdaptiveSampling;
9698
target.EnableQuickPulseMetricStream = this.EnableQuickPulseMetricStream;
9799
target.AddAutoCollectedMetricExtractor = this.AddAutoCollectedMetricExtractor;
98100
target.EnablePerformanceCounterCollectionModule = this.EnablePerformanceCounterCollectionModule;
99101
target.EnableDependencyTrackingTelemetryModule = this.EnableDependencyTrackingTelemetryModule;
102+
target.TracesPerSecond = this.TracesPerSecond;
103+
target.SamplingRatio = this.SamplingRatio;
100104

101105
#if AI_ASPNETCORE_WEB
102106
target.EnableAuthenticationTrackingJavaScript = this.EnableAuthenticationTrackingJavaScript;

NETCORE/test/IntegrationTests.Tests/CustomWebApplicationFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ protected override void ConfigureWebHost(IWebHostBuilder builder)
4343
{
4444
options.AddAutoCollectedMetricExtractor = false;
4545
options.EnableQuickPulseMetricStream = false;
46-
options.EnableAdaptiveSampling = false;
4746
options.ConnectionString = "InstrumentationKey=ikey";
47+
options.SamplingRatio = 1.0f; // 100% telemetry flow in tests
4848
});
4949
});
5050
}

0 commit comments

Comments
 (0)