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
Copy file name to clipboardExpand all lines: articles/azure-monitor/app/api-filtering-sampling.md
+54-55Lines changed: 54 additions & 55 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ ms.author: mbullwin
21
21
You can write and configure plug-ins for the Application Insights SDK to customize how telemetry is captured and processed before it is sent to the Application Insights service.
22
22
23
23
*[Sampling](../../azure-monitor/app/sampling.md) reduces the volume of telemetry without affecting your statistics. It keeps together related data points so that you can navigate between them when diagnosing a problem. In the portal, the total counts are multiplied to compensate for the sampling.
24
-
* Filtering with Telemetry Processors [for ASP.NET](#filtering) or [Java](../../azure-monitor/app/java-filter-telemetry.md) lets you select or modify telemetry in the SDK before it is sent to the server. For example, you could reduce the volume of telemetry by excluding requests from robots. But filtering is a more basic approach to reducing traffic than sampling. It allows you more control over what is transmitted, but you have to be aware that it affects your statistics - for example, if you filter out all successful requests.
24
+
* Filtering with Telemetry Processors [for ASP.NET or ASP.NET Core](#filtering) or [Java](../../azure-monitor/app/java-filter-telemetry.md) lets you select or modify telemetry in the SDK before it is sent to the server. For example, you could reduce the volume of telemetry by excluding requests from robots. But filtering is a more basic approach to reducing traffic than sampling. It allows you more control over what is transmitted, but you have to be aware that it affects your statistics - for example, if you filter out all successful requests.
25
25
*[Telemetry Initializers add properties](#add-properties) to any telemetry sent from your app, including telemetry from the standard modules. For example, you could add calculated values; or version numbers by which to filter the data in the portal.
26
26
*[The SDK API](../../azure-monitor/app/api-custom-events-metrics.md) is used to send custom events and metrics.
27
27
@@ -32,9 +32,10 @@ Before you start:
32
32
<aname="filtering"></a>
33
33
34
34
## Filtering: ITelemetryProcessor
35
-
This technique gives you more direct control over what is included or excluded from the telemetry stream. You can use it in conjunction with Sampling, or separately.
36
35
37
-
To filter telemetry, you write a telemetry processor and register it with the SDK. All telemetry goes through your processor, and you can choose to drop it from the stream, or add properties. This includes telemetry from the standard modules such as the HTTP request collector and the dependency collector, as well as telemetry you have written yourself. You can, for example, filter out telemetry about requests from robots, or successful dependency calls.
36
+
This technique gives you more direct control over what is included or excluded from the telemetry stream. Filtering can be used to drop telemetry items from being sent to Application Insights. You can use it in conjunction with Sampling, or separately.
37
+
38
+
To filter telemetry, you write a telemetry processor and register it with the `TelemetryConfiguration`. All telemetry goes through your processor, and you can choose to drop it from the stream, or add properties. This includes telemetry from the standard modules such as the HTTP request collector and the dependency collector, as well as telemetry you have written yourself. You can, for example, filter out telemetry about requests from robots, or successful dependency calls.
38
39
39
40
> [!WARNING]
40
41
> Filtering the telemetry sent from the SDK using processors can skew the statistics that you see in the portal, and make it difficult to follow related items.
@@ -44,56 +45,45 @@ To filter telemetry, you write a telemetry processor and register it with the SD
44
45
>
45
46
46
47
### Create a telemetry processor (C#)
47
-
1. Verify that the Application Insights SDK in your project is version 2.0.0 or later. Right-click your project in Visual Studio Solution Explorer and choose Manage NuGet Packages. In NuGet package manager, check Microsoft.ApplicationInsights.Web.
48
-
2. To create a filter, implement ITelemetryProcessor. This is another extensibility point like telemetry module, telemetry initializer, and telemetry channel.
49
48
50
-
Notice that Telemetry Processors construct a chain of processing. When you instantiate a telemetry processor, you pass a link to the next processor in the chain. When a telemetry data point is passed to the Process method, it does its work and then calls the next Telemetry Processor in the chain.
49
+
1. To create a filter, implement ITelemetryProcessor. This is another extensibility point like telemetry module, telemetry initializer, and telemetry channel.
50
+
51
+
Notice that Telemetry Processors construct a chain of processing. When you instantiate a telemetry processor, you are given a reference to the next processor in the chain. When a telemetry data point is passed to the Process method, it does its work and then calls (or not calls) the next Telemetry Processor in the chain.
@@ -119,7 +109,7 @@ You can pass string values from the .config file by providing public named prope
119
109
**Alternatively,** you can initialize the filter in code. In a suitable initialization class - for example AppStart in Global.asax.cs - insert your processor into the chain:
TelemetryClients created after this point will use your processors.
132
122
133
-
**ASP.NET Core apps**
123
+
**ASP.NET Core/ Worker Service apps**
134
124
135
125
> [!NOTE]
136
-
> Adding initializer using `ApplicationInsights.config` or using `TelemetryConfiguration.Active` is not valid for ASP.NET Core applications.
137
-
126
+
> Adding processor using `ApplicationInsights.config` or using `TelemetryConfiguration.Active` is not valid for ASP.NET Core applications or if you are using Microsoft.ApplicationInsights.WorkerService SDK.
138
127
139
-
For [ASP.NET Core](asp-net-core.md#adding-telemetry-processors)applications, adding a new `TelemetryInitializer` is done by adding it to the Dependency Injection container, as shown below. This is done in `ConfigureServices` method of your `Startup.cs` class.
128
+
For apps written using [ASP.NET Core](asp-net-core.md#adding-telemetry-processors)pr [WorkerService](worker-service.md#adding-telemetry-processors), adding a new `TelemetryProcessor` is done by using `AddApplicationInsightsTelemetryProcessor` extension method on `IServiceCollection`, as shown below. This is done in `ConfigureServices` method of your `Startup.cs` class.
@@ -151,8 +140,10 @@ For [ASP.NET Core](asp-net-core.md#adding-telemetry-processors) applications, ad
151
140
```
152
141
153
142
### Example filters
143
+
154
144
#### Synthetic requests
155
-
Filter out bots and web tests. Although Metrics Explorer gives you the option to filter out synthetic sources, this option reduces traffic by filtering them at the SDK.
145
+
146
+
Filter out bots and web tests. Although Metrics Explorer gives you the option to filter out synthetic sources, this option reduces traffic and ingestion size by filtering them at the SDK itself.
156
147
157
148
```csharp
158
149
publicvoidProcess(ITelemetryitem)
@@ -165,6 +156,7 @@ public void Process(ITelemetry item)
165
156
```
166
157
167
158
#### Failed authentication
159
+
168
160
Filter out requests with a "401" response.
169
161
170
162
```csharp
@@ -175,19 +167,21 @@ public void Process(ITelemetry item)
// To filter out an item, just terminate the chain:
170
+
// To filter out an item, return without calling the next processor.
179
171
return;
180
172
}
181
-
// Send everything else:
173
+
174
+
// Send everything else
182
175
this.Next.Process(item);
183
176
}
184
177
```
185
178
186
179
#### Filter out fast remote dependency calls
180
+
187
181
If you only want to diagnose calls that are slow, filter out the fast ones.
188
182
189
183
> [!NOTE]
190
-
> This will skew the statistics you see on the portal. The dependency chart will look as if the dependency calls are all failures.
184
+
> This will skew the statistics you see on the portal.
191
185
>
192
186
>
193
187
@@ -205,17 +199,18 @@ public void Process(ITelemetry item)
205
199
```
206
200
207
201
#### Diagnose dependency issues
208
-
[This blog](https://azure.microsoft.com/blog/implement-an-application-insights-telemetry-processor/) describes a project to diagnose dependency issues by automatically sending regular pings to dependencies.
209
202
203
+
[This blog](https://azure.microsoft.com/blog/implement-an-application-insights-telemetry-processor/) describes a project to diagnose dependency issues by automatically sending regular pings to dependencies.
210
204
211
205
<aname="add-properties"></a>
212
206
213
207
## Add properties: ITelemetryInitializer
214
-
Use telemetry initializers to define global properties that are sent with all telemetry; and to override selected behavior of the standard telemetry modules.
208
+
209
+
Use telemetry initializers to enrich telemetry with additional information and/or to override telemetry properties set by the standard telemetry modules.
215
210
216
211
For example, the Application Insights for Web package collects telemetry about HTTP requests. By default, it flags as failed any request with a response code >= 400. But if you want to treat 400 as a success, you can provide a telemetry initializer that sets the Success property.
217
212
218
-
If you provide a telemetry initializer, it is called whenever any of the Track*() methods are called. This includes methods called by the standard telemetry modules. By convention, these modules do not set any property that has already been set by an initializer.
213
+
If you provide a telemetry initializer, it is called whenever any of the Track*() methods are called. This includes methods called by the standard telemetry modules. By convention, these modules do not set any property that has already been set by an initializer. Telemetry initializers are called before calling telemetry processors. So any enrichment done by initializers are visible to processors.
> Adding initializer using `ApplicationInsights.config` or using `TelemetryConfiguration.Active` is not valid for ASP.NET Core applications.
290
285
291
-
For [ASP.NET Core](asp-net-core.md#adding-telemetryinitializers)applications, adding a new `TelemetryInitializer` is done by adding it to the Dependency Injection container, as shown below. This is done in `ConfigureServices` method of your `Startup.cs` class.
286
+
For apps written using [ASP.NET Core](asp-net-core.md#adding-telemetryinitializers)or [WorkerService](worker-service.md#adding-telemetryinitializers), adding a new `TelemetryInitializer` is done by adding it to the Dependency Injection container, as shown below. This is done in `Startup.ConfigureServices` method.
292
287
293
288
```csharp
294
289
usingMicrosoft.ApplicationInsights.Extensibility;
@@ -364,25 +359,29 @@ Insert a telemetry initializer immediately after the initialization code that yo
364
359
365
360
For a summary of the non-custom properties available on the telemetryItem, see [Application Insights Export Data Model](../../azure-monitor/app/export-data-model.md).
366
361
367
-
You can add as many initializers as you like.
362
+
You can add as many initializers as you like, and they are called in the order they are added.
368
363
369
364
## ITelemetryProcessor and ITelemetryInitializer
365
+
370
366
What's the difference between telemetry processors and telemetry initializers?
371
367
372
-
* There are some overlaps in what you can do with them: both can be used to add properties to telemetry.
368
+
* There are some overlaps in what you can do with them: both can be used to add properties to telemetry, though it is recommended to use initializers for that purpose.
373
369
* TelemetryInitializers always run before TelemetryProcessors.
370
+
* TelemetryInitializers may be called more than once. By convention, they do not set any property that has already been set.
374
371
* TelemetryProcessors allow you to completely replace or discard a telemetry item.
375
-
* TelemetryProcessors don't process performance counter telemetry.
376
372
377
373
## Troubleshooting ApplicationInsights.config
374
+
378
375
* Confirm that the fully qualified type name and assembly name are correct.
379
376
* Confirm that the applicationinsights.config file is in your output directory and contains any recent changes.
0 commit comments