Skip to content

Commit 88f8f92

Browse files
author
Kai Nawroth
committed
Fixing tabs
1 parent e360907 commit 88f8f92

File tree

1 file changed

+86
-86
lines changed

1 file changed

+86
-86
lines changed

articles/azure-monitor/app/api-filtering-sampling.md

Lines changed: 86 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ To filter telemetry, you write a telemetry processor and register it with `Telem
3737
>
3838
> Instead, consider using [sampling](./sampling.md).
3939
40-
### Create a telemetry processor for .NET applications
40+
### .NET applications
4141

42-
1. To create a filter, implement `ITelemetryProcessor`.
42+
1. Implement `ITelemetryProcessor`.
4343

4444
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.
4545

@@ -112,7 +112,7 @@ To filter telemetry, you write a telemetry processor and register it with `Telem
112112

113113
Telemetry clients created after this point use your processors.
114114

115-
#### [ASP.NET Core/Worker service](#tab/dotnet)
115+
#### [ASP.NET Core/Worker service](#tab/dotnetcore)
116116

117117
> [!NOTE]
118118
> Adding a processor by using `ApplicationInsights.config` or `TelemetryConfiguration.Active` isn't valid for ASP.NET Core applications or if you're using the Microsoft.ApplicationInsights.WorkerService SDK.
@@ -135,9 +135,9 @@ To filter telemetry, you write a telemetry processor and register it with `Telem
135135

136136
---
137137

138-
#### Example filters
138+
### Example filters
139139

140-
##### Synthetic requests
140+
#### Synthetic requests
141141

142142
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.
143143

@@ -151,7 +151,7 @@ public void Process(ITelemetry item)
151151
}
152152
```
153153

154-
##### Failed authentication
154+
#### Failed authentication
155155

156156
Filter out requests with a "401" response.
157157

@@ -172,7 +172,7 @@ public void Process(ITelemetry item)
172172
}
173173
```
174174

175-
##### Filter out fast remote dependency calls
175+
#### Filter out fast remote dependency calls
176176

177177
If you want to diagnose only calls that are slow, filter out the fast ones.
178178

@@ -194,19 +194,19 @@ public void Process(ITelemetry item)
194194
}
195195
```
196196

197-
##### Diagnose dependency issues
197+
#### Diagnose dependency issues
198198

199199
[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.
200200

201201
<a name="add-properties"></a>
202202

203-
### Java
203+
### Java applications
204204

205205
To learn more about telemetry processors and their implementation in Java, reference the [Java telemetry processors documentation](./java-standalone-telemetry-processors.md).
206206

207207
### JavaScript web applications
208208

209-
**Filter by using ITelemetryInitializer**
209+
You can filter telemetry from JavaScript web applications by using ITelemetryInitializer.
210210

211211
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.
212212

@@ -233,92 +233,92 @@ For example, Application Insights for a web package collects telemetry about HTT
233233

234234
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.
235235

236-
### C#
236+
### .NET applications
237237

238-
#### Define your initializer
238+
1. Define your initializer
239239

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
254247
{
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
256254
{
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)
264256
{
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:
269-
requestTelemetry.Properties["Overridden400s"] = "true";
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)
264+
{
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:
269+
requestTelemetry.Properties["Overridden400s"] = "true";
270+
}
271+
// else leave the SDK to set the Success property
270272
}
271-
// else leave the SDK to set the Success property
272273
}
273274
}
274-
}
275-
```
276-
277-
#### Load your initializer
278-
279-
##### [ASP.NET](#tab/dotnet)
280-
281-
In ApplicationInsights.config:
282-
283-
```xml
284-
<ApplicationInsights>
285-
<TelemetryInitializers>
286-
<!-- Fully qualified type name, assembly name: -->
287-
<Add Type="MvcWebRole.Telemetry.MyTelemetryInitializer, MvcWebRole"/>
288-
...
289-
</TelemetryInitializers>
290-
</ApplicationInsights>
291-
```
292-
293-
Alternatively, you can instantiate the initializer in code, for example, in Global.aspx.cs:
294-
295-
```csharp
296-
protected void Application_Start()
297-
{
298-
// ...
299-
TelemetryConfiguration.Active.TelemetryInitializers.Add(new MyTelemetryInitializer());
300-
}
301-
```
302-
303-
See more of [this sample](https://github.com/MohanGsk/ApplicationInsights-Home/tree/master/Samples/AzureEmailService/MvcWebRole).
304-
305-
##### [ASP.NET Core/Worker service](#tab/dotnetcore)
306-
307-
> [!NOTE]
308-
> 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.WorkerService SDK.
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 new telemetry initializer is done by adding it to the Dependency Injection container, as shown. Accomplish this step in the `Startup.ConfigureServices` method.
275+
```
311276

312-
```csharp
313-
using Microsoft.ApplicationInsights.Extensibility;
314-
using CustomInitializer.Telemetry;
315-
public void ConfigureServices(IServiceCollection services)
316-
{
317-
services.AddSingleton<ITelemetryInitializer, MyTelemetryInitializer>();
318-
}
319-
```
277+
2. Load your initializer
320278

321-
---
279+
#### [ASP.NET](#tab/dotnet)
280+
281+
In ApplicationInsights.config:
282+
283+
```xml
284+
<ApplicationInsights>
285+
<TelemetryInitializers>
286+
<!-- Fully qualified type name, assembly name: -->
287+
<Add Type="MvcWebRole.Telemetry.MyTelemetryInitializer, MvcWebRole"/>
288+
...
289+
</TelemetryInitializers>
290+
</ApplicationInsights>
291+
```
292+
293+
Alternatively, you can instantiate the initializer in code, for example, in Global.aspx.cs:
294+
295+
```csharp
296+
protected void Application_Start()
297+
{
298+
// ...
299+
TelemetryConfiguration.Active.TelemetryInitializers.Add(new MyTelemetryInitializer());
300+
}
301+
```
302+
303+
See more of [this sample](https://github.com/MohanGsk/ApplicationInsights-Home/tree/master/Samples/AzureEmailService/MvcWebRole).
304+
305+
#### [ASP.NET Core/Worker service](#tab/dotnetcore)
306+
307+
> [!NOTE]
308+
> 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.WorkerService SDK.
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 new telemetry initializer is done by adding it to the Dependency Injection container, as shown. Accomplish this step in the `Startup.ConfigureServices` method.
311+
312+
```csharp
313+
using Microsoft.ApplicationInsights.Extensibility;
314+
using CustomInitializer.Telemetry;
315+
public void ConfigureServices(IServiceCollection services)
316+
{
317+
services.AddSingleton<ITelemetryInitializer, MyTelemetryInitializer>();
318+
}
319+
```
320+
321+
---
322322

323323
### JavaScript telemetry initializers
324324

0 commit comments

Comments
 (0)