Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions BreakingChanges.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`**
Expand All @@ -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:**
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 0 additions & 19 deletions NETCORE/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
```

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion NETCORE/WorkerService.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ builder.Services.AddApplicationInsightsTelemetryWorkerService(options =>
{
options.ConnectionString = "InstrumentationKey=...";
options.EnableQuickPulseMetricStream = true;
options.EnableAdaptiveSampling = true;
});
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 13 additions & 9 deletions NETCORE/src/Shared/Extensions/ApplicationInsightsServiceOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ public class ApplicationInsightsServiceOptions
/// </summary>
public bool EnableDependencyTrackingTelemetryModule { get; set; } = true;

/// <summary>
/// Gets or sets a value indicating whether telemetry processor that controls sampling is added to the service.
/// Setting EnableAdaptiveSampling to <value>false</value>, will disable sampling entirely.
/// When <value>true</value> (default), enables rate-limit based sampling in Azure Monitor Exporter.
/// Defaults to <value>true</value>.
/// </summary>
public bool EnableAdaptiveSampling { get; set; } = true;

/// <summary>
/// Gets or sets the connection string for the application.
/// </summary>
Expand All @@ -61,6 +53,17 @@ public class ApplicationInsightsServiceOptions
/// </summary>
public bool AddAutoCollectedMetricExtractor { get; set; } = true;

/// <summary>
/// Gets or sets the target number of traces per second to be collected.
/// </summary>
public double? TracesPerSecond { get; set; }

/// <summary>
/// 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).
/// </summary>
public float? SamplingRatio { get; set; }

#if AI_ASPNETCORE_WEB
/// <summary>
/// Gets or sets a value indicating whether RequestTrackingTelemetryModule should be enabled.
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"ApplicationInsights": {
"ConnectionString": "InstrumentationKey=11111111-2222-3333-4444-555555555555;IngestionEndpoint=http://testendpoint",
"EnableAdaptiveSampling": false,
"EnableQuickPulseMetricStream": true,
"ApplicationVersion": "Version"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"ApplicationInsights": {
"ConnectionString": "InstrumentationKey=22222222-2222-3333-4444-555555555555",
"EnableAdaptiveSampling": false,
"EnableQuickPulseMetricStream": false
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"ApplicationInsights": {
"ConnectionString": "InstrumentationKey=22222222-2222-3333-4444-555555555555",
"EnableAdaptiveSampling": true,
"EnableQuickPulseMetricStream": true,
"ApplicationVersion": "1.0.0"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ApplicationInsights": {
"ConnectionString": "InstrumentationKey=33333333-4444-5555-6666-777777777777",
"TracesPerSecond": 10.0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ApplicationInsights": {
"ConnectionString": "InstrumentationKey=44444444-5555-6666-7777-888888888888",
"SamplingRatio": 0.5
}
}
Loading
Loading