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
+86-86Lines changed: 86 additions & 86 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,9 +37,9 @@ To filter telemetry, you write a telemetry processor and register it with `Telem
37
37
>
38
38
> Instead, consider using [sampling](./sampling.md).
39
39
40
-
### Create a telemetry processor for .NET applications
40
+
### .NET applications
41
41
42
-
1.To create a filter, implement`ITelemetryProcessor`.
42
+
1.Implement`ITelemetryProcessor`.
43
43
44
44
Telemetry processors construct a chain of processing. When you instantiate a telemetry processor, you're 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 doesn't call) the next telemetry processor in the chain.
45
45
@@ -112,7 +112,7 @@ To filter telemetry, you write a telemetry processor and register it with `Telem
>Addingaprocessorbyusing `ApplicationInsights.config` or `TelemetryConfiguration.Active` isn'tvalidforASP.NETCoreapplicationsorifyou'reusingtheMicrosoft.ApplicationInsights.WorkerServiceSDK.
@@ -135,9 +135,9 @@ To filter telemetry, you write a telemetry processor and register it with `Telem
135
135
136
136
---
137
137
138
-
#### Example filters
138
+
### Example filters
139
139
140
-
##### Synthetic requests
140
+
#### Synthetic requests
141
141
142
142
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.
143
143
@@ -151,7 +151,7 @@ public void Process(ITelemetry item)
151
151
}
152
152
```
153
153
154
-
#####Failed authentication
154
+
#### Failed authentication
155
155
156
156
Filter out requests with a "401" response.
157
157
@@ -172,7 +172,7 @@ public void Process(ITelemetry item)
172
172
}
173
173
```
174
174
175
-
#####Filter out fast remote dependency calls
175
+
#### Filter out fast remote dependency calls
176
176
177
177
If you want to diagnose only calls that are slow, filter out the fast ones.
178
178
@@ -194,19 +194,19 @@ public void Process(ITelemetry item)
194
194
}
195
195
```
196
196
197
-
#####Diagnose dependency issues
197
+
#### Diagnose dependency issues
198
198
199
199
[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.
200
200
201
201
<aname="add-properties"></a>
202
202
203
-
### Java
203
+
### Java applications
204
204
205
205
To learn more about telemetry processors and their implementation in Java, reference the [Java telemetry processors documentation](./java-standalone-telemetry-processors.md).
206
206
207
207
### JavaScript web applications
208
208
209
-
**Filter by using ITelemetryInitializer**
209
+
You can filter telemetry from JavaScript web applications by using ITelemetryInitializer.
210
210
211
211
1. Create a telemetry initializer callback function. The callback function takes `ITelemetryItem` as a parameter, which is the event that's being processed. Returning `false` from this callback results in the telemetry item to be filtered out.
212
212
@@ -233,92 +233,92 @@ For example, Application Insights for a web package collects telemetry about HTT
233
233
234
234
If you provide a telemetry initializer, it's called whenever any of the Track*() methods are called. This initializer includes `Track()` methods called by the standard telemetry modules. By convention, these modules don't set any property that was already set by an initializer. Telemetry initializers are called before calling telemetry processors, so any enrichments done by initializers are visible to processors.
235
235
236
-
### C#
236
+
### .NET applications
237
237
238
-
#### Define your initializer
238
+
1. Define your initializer
239
239
240
-
```csharp
241
-
using System;
242
-
using Microsoft.ApplicationInsights.Channel;
243
-
using Microsoft.ApplicationInsights.DataContracts;
244
-
using Microsoft.ApplicationInsights.Extensibility;
245
-
246
-
namespace MvcWebRole.Telemetry
247
-
{
248
-
/*
249
-
* Custom TelemetryInitializer that overrides the default SDK
250
-
* behavior of treating response codes >= 400 as failed requests
251
-
*
252
-
*/
253
-
public class MyTelemetryInitializer : ITelemetryInitializer
240
+
```csharp
241
+
using System;
242
+
using Microsoft.ApplicationInsights.Channel;
243
+
using Microsoft.ApplicationInsights.DataContracts;
244
+
using Microsoft.ApplicationInsights.Extensibility;
245
+
246
+
namespace MvcWebRole.Telemetry
254
247
{
255
-
public void Initialize(ITelemetry telemetry)
248
+
/*
249
+
* Custom TelemetryInitializer that overrides the default SDK
250
+
* behavior of treating response codes >= 400 as failed requests
251
+
*
252
+
*/
253
+
public class MyTelemetryInitializer : ITelemetryInitializer
256
254
{
257
-
var requestTelemetry = telemetry as RequestTelemetry;
258
-
// Is this a TrackRequest() ?
259
-
if (requestTelemetry == null) return;
260
-
int code;
261
-
bool parsed = Int32.TryParse(requestTelemetry.ResponseCode, out code);
262
-
if (!parsed) return;
263
-
if (code >= 400 && code < 500)
255
+
public void Initialize(ITelemetry telemetry)
264
256
{
265
-
// If we set the Success property, the SDK won't change it:
266
-
requestTelemetry.Success = true;
267
-
268
-
// Allow us to filter these requests in the portal:
> Adding an initializer by using `ApplicationInsights.config` or `TelemetryConfiguration.Active` isn't valid for ASP.NET Core applications or if you're using the Microsoft.ApplicationInsights.WorkerServiceSDK.
309
-
310
-
For apps written using [ASP.NET Core](asp-net-core.md#add-telemetryinitializers) or [WorkerService](worker-service.md#add-telemetry-initializers), adding a newtelemetry initializer is done by adding it to the Dependency Injection container, as shown. Accomplishthis step in the `Startup.ConfigureServices` method.
275
+
```
311
276
312
-
```csharp
313
-
using Microsoft.ApplicationInsights.Extensibility;
314
-
using CustomInitializer.Telemetry;
315
-
public void ConfigureServices(IServiceCollection services)
> Adding an initializer by using `ApplicationInsights.config` or `TelemetryConfiguration.Active` isn't valid for ASP.NET Core applications or if you're using the Microsoft.ApplicationInsights.WorkerServiceSDK.
309
+
310
+
For apps written using [ASP.NET Core](asp-net-core.md#add-telemetryinitializers) or [WorkerService](worker-service.md#add-telemetry-initializers), adding a newtelemetry initializer is done by adding it to the Dependency Injection container, as shown. Accomplishthis step in the `Startup.ConfigureServices` method.
311
+
312
+
```csharp
313
+
using Microsoft.ApplicationInsights.Extensibility;
314
+
using CustomInitializer.Telemetry;
315
+
public void ConfigureServices(IServiceCollection services)
0 commit comments