You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sampling is a feature in [Azure Application Insights](./app-insights-overview.md). It's the recommended way to reduce telemetry traffic, data costs, and storage costs, while preserving a statistically correct analysis of application data. Sampling also helps you avoid Application Insights throttling your telemetry. The sampling filter selects items that are related, so that you can navigate between items when you're doing diagnostic investigations.
12
+
Sampling is a feature in [Application Insights](./app-insights-overview.md). It's the recommended way to reduce telemetry traffic, data costs, and storage costs, while preserving a statistically correct analysis of application data. Sampling also helps you avoid Application Insights throttling your telemetry. The sampling filter selects items that are related, so that you can navigate between items when you're doing diagnostic investigations.
13
13
14
14
When metric counts are presented in the portal, they're renormalized to take into account sampling. Doing so minimizes any effect on the statistics.
15
15
@@ -139,7 +139,7 @@ In [`ApplicationInsights.config`](./configuration-with-applicationinsights-confi
139
139
Instead of setting the sampling parameter in the `.config` file, you can programmatically set these values.
140
140
141
141
1. Remove all the `AdaptiveSamplingTelemetryProcessor` node(s) from the `.config` file.
142
-
2. Use the following snippet to configure adaptive sampling:
142
+
1. Use the following snippet to configure adaptive sampling:
143
143
144
144
```csharp
145
145
usingMicrosoft.ApplicationInsights;
@@ -179,21 +179,37 @@ Adaptive sampling is enabled by default for all ASP.NET Core applications. You c
179
179
180
180
#### Turning off adaptive sampling
181
181
182
-
The default sampling feature can be disabled while adding Application Insights service, in the method `ConfigureServices`, using `ApplicationInsightsServiceOptions` within the `Startup.cs` file:
182
+
The default sampling feature can be disabled while adding the Application Insights service.
183
+
184
+
### [ASP.NET Core 6 and later](#tab/net-core-new)
185
+
186
+
Add `ApplicationInsightsServiceOptions` after the `WebApplication.CreateBuilder()` method in the `Program.cs` file:
The above code will disable adaptive sampling. Follow the steps below to add sampling with more customization options.
198
214
199
215
#### Configure sampling settings
@@ -203,6 +219,39 @@ Use extension methods of `TelemetryProcessorChainBuilder` as shown below to cust
203
219
> [!IMPORTANT]
204
220
> If you use this method to configure sampling, please make sure to set the `aiOptions.EnableAdaptiveSampling` property to `false` when calling `AddApplicationInsightsTelemetry()`. After making this change, you then need to follow the instructions in the code block below **exactly** in order to re-enable adaptive sampling with your customizations in place. Failure to do so can result in excess data ingestion. Always test post changing sampling settings, and set an appropriate [daily data cap](../logs/daily-cap.md) to help control your costs.
// Alternately, the following configures adaptive sampling with 5 items per second, and also excludes DependencyTelemetry from being subject to sampling:
### Configuring adaptive sampling for Azure Functions
231
280
232
281
Follow instructions from [this page](../../azure-functions/configure-monitoring.md#configure-sampling) to configure adaptive sampling for apps running in Azure Functions.
@@ -252,7 +301,7 @@ In Metrics Explorer, rates such as request and exception counts are multiplied b
252
301
-->
253
302
```
254
303
255
-
2. **Enable the fixed-rate sampling module.** Add this snippet to [`ApplicationInsights.config`](./configuration-with-applicationinsights-config.md):
304
+
1. **Enable the fixed-rate sampling module.** Add this snippet to [`ApplicationInsights.config`](./configuration-with-applicationinsights-config.md):
256
305
257
306
```xml
258
307
<TelemetryProcessors>
@@ -264,8 +313,8 @@ In Metrics Explorer, rates such as request and exception counts are multiplied b
264
313
</TelemetryProcessors>
265
314
```
266
315
267
-
Alternatively, instead of setting the sampling parameter in the `ApplicationInsights.config` file, you can programmatically set these values:
268
-
316
+
Alternatively, instead of setting the sampling parameter in the `ApplicationInsights.config` file, you can programmatically set these values:
317
+
269
318
```csharp
270
319
using Microsoft.ApplicationInsights.Extensibility;
271
320
using Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel;
@@ -288,22 +337,66 @@ In Metrics Explorer, rates such as request and exception counts are multiplied b
288
337
289
338
### Configuring fixed-rate sampling for ASP.NET Core applications
290
339
291
-
1. **Disable adaptive sampling**: Changes can be made in the `ConfigureServices` method, using `ApplicationInsightsServiceOptions`:
340
+
1. **Disable adaptive sampling**
341
+
342
+
### [ASP.NET Core 6 and later](#tab/net-core-new)
343
+
344
+
Changes can be made after the `WebApplication.CreateBuilder()` method, using `ApplicationInsightsServiceOptions`:
345
+
346
+
```csharp
347
+
var builder = WebApplication.CreateBuilder(args);
348
+
349
+
var aiOptions = new Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions();
2. **Enable the fixed-rate sampling module.** Changes can be made in the `Configure` method as shown in the below snippet:
397
+
### [ASP.NET Core 5 and earlier](#tab/net-core-old)
398
+
399
+
Changes can be made in the `Configure()` method:
307
400
308
401
```csharp
309
402
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
@@ -319,11 +412,11 @@ In Metrics Explorer, rates such as request and exception counts are multiplied b
319
412
builder.UseSampling(fixedSamplingPercentage);
320
413
321
414
builder.Build();
322
-
323
-
// ...
324
415
}
325
416
```
326
417
418
+
---
419
+
327
420
### Configuring sampling overrides and fixed-rate sampling for Java applications
328
421
329
422
By default no sampling is enabled in the Java auto-instrumentation and SDK. Currently the Java auto-instrumentation, [sampling overrides](./java-standalone-sampling-overrides.md) and fixed rate sampling are supported. Adaptive sampling isn't supported in Java.
0 commit comments