Skip to content

Commit c29b346

Browse files
author
Kai Nawroth
committed
Improving structure and formatting
1 parent 9a09253 commit c29b346

File tree

1 file changed

+75
-73
lines changed

1 file changed

+75
-73
lines changed

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

Lines changed: 75 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -85,75 +85,75 @@ To filter telemetry, you write a telemetry processor and register it with `Telem
8585

8686
2. Add your processor.
8787

88-
ASP.NET **apps**
89-
90-
Insert this snippet in ApplicationInsights.config:
91-
92-
```xml
93-
<TelemetryProcessors>
94-
<Add Type="WebApplication9.SuccessfulDependencyFilter, WebApplication9">
95-
<!-- Set public property -->
96-
<MyParamFromConfigFile>2-beta</MyParamFromConfigFile>
97-
</Add>
98-
</TelemetryProcessors>
99-
```
100-
101-
You can pass string values from the .config file by providing public named properties in your class.
102-
103-
> [!WARNING]
104-
> Take care to match the type name and any property names in the .config file to the class and property names in the code. If the .config file references a nonexistent type or property, the SDK may silently fail to send any telemetry.
105-
>
106-
107-
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:
108-
109-
```csharp
110-
var builder = TelemetryConfiguration.Active.DefaultTelemetrySink.TelemetryProcessorChainBuilder;
111-
builder.Use((next) => new SuccessfulDependencyFilter(next));
112-
113-
// If you have more processors:
114-
builder.Use((next) => new AnotherProcessor(next));
115-
116-
builder.Build();
117-
```
118-
119-
Telemetry clients created after this point use your processors.
120-
121-
ASP.NET **Core/Worker service apps**
122-
123-
> [!NOTE]
124-
> 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.
125-
126-
For apps written by using [ASP.NET Core](asp-net-core.md#add-telemetry-processors) or [WorkerService](worker-service.md#add-telemetry-processors), adding a new telemetry processor is done by using the `AddApplicationInsightsTelemetryProcessor` extension method on `IServiceCollection`, as shown. This method is called in the `ConfigureServices` method of your `Startup.cs` class.
127-
128-
```csharp
129-
public void ConfigureServices(IServiceCollection services)
130-
{
131-
// ...
132-
services.AddApplicationInsightsTelemetry();
133-
services.AddApplicationInsightsTelemetryProcessor<SuccessfulDependencyFilter>();
134-
88+
**ASP.NET apps**
89+
90+
Insert this snippet in ApplicationInsights.config:
91+
92+
```xml
93+
<TelemetryProcessors>
94+
<Add Type="WebApplication9.SuccessfulDependencyFilter, WebApplication9">
95+
<!-- Set public property -->
96+
<MyParamFromConfigFile>2-beta</MyParamFromConfigFile>
97+
</Add>
98+
</TelemetryProcessors>
99+
```
100+
101+
You can pass string values from the .config file by providing public named properties in your class.
102+
103+
> [!WARNING]
104+
> Take care to match the type name and any property names in the .config file to the class and property names in the code. If the .config file references a nonexistent type or property, the SDK may silently fail to send any telemetry.
105+
>
106+
107+
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:
108+
109+
```csharp
110+
var builder = TelemetryConfiguration.Active.DefaultTelemetrySink.TelemetryProcessorChainBuilder;
111+
builder.Use((next) => new SuccessfulDependencyFilter(next));
112+
135113
// If you have more processors:
136-
services.AddApplicationInsightsTelemetryProcessor<AnotherProcessor>();
137-
}
138-
```
139-
140-
To register telemetry processors that need parameters in ASP.NET Core, create a custom class implementing **ITelemetryProcessorFactory**. Call the constructor with the desired parameters in the **Create** method and then use **AddSingleton<ITelemetryProcessorFactory, MyTelemetryProcessorFactory>()**.
141-
142-
### Example filters
143-
144-
#### Synthetic requests
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.
147-
148-
```csharp
149-
public void Process(ITelemetry item)
150-
{
151-
if (!string.IsNullOrEmpty(item.Context.Operation.SyntheticSource)) {return;}
114+
builder.Use((next) => new AnotherProcessor(next));
152115

153-
// Send everything else:
154-
this.Next.Process(item);
155-
}
156-
```
116+
builder.Build();
117+
```
118+
119+
Telemetry clients created after this point use your processors.
120+
121+
**ASP.NET Core/Worker service apps**
122+
123+
> [!NOTE]
124+
> 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.
125+
126+
For apps written by using [ASP.NET Core](asp-net-core.md#add-telemetry-processors) or [WorkerService](worker-service.md#add-telemetry-processors), adding a new telemetry processor is done by using the `AddApplicationInsightsTelemetryProcessor` extension method on `IServiceCollection`, as shown. This method is called in the `ConfigureServices` method of your `Startup.cs` class.
127+
128+
```csharp
129+
public void ConfigureServices(IServiceCollection services)
130+
{
131+
// ...
132+
services.AddApplicationInsightsTelemetry();
133+
services.AddApplicationInsightsTelemetryProcessor<SuccessfulDependencyFilter>();
134+
135+
// If you have more processors:
136+
services.AddApplicationInsightsTelemetryProcessor<AnotherProcessor>();
137+
}
138+
```
139+
140+
To register telemetry processors that need parameters in ASP.NET Core, create a custom class implementing **ITelemetryProcessorFactory**. Call the constructor with the desired parameters in the **Create** method and then use **AddSingleton<ITelemetryProcessorFactory, MyTelemetryProcessorFactory>()**.
141+
142+
### Example filters
143+
144+
#### Synthetic requests
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.
147+
148+
```csharp
149+
public void Process(ITelemetry item)
150+
{
151+
if (!string.IsNullOrEmpty(item.Context.Operation.SyntheticSource)) {return;}
152+
153+
// Send everything else:
154+
this.Next.Process(item);
155+
}
156+
```
157157

158158
#### Failed authentication
159159

@@ -233,13 +233,13 @@ To learn more about telemetry processors and their implementation in Java, refer
233233

234234
Use telemetry initializers to enrich telemetry with additional information or to override telemetry properties set by the standard telemetry modules.
235235

236-
For example, Application Insights for a 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.
236+
For example, Application Insights for a web package collects telemetry about HTTP requests. By default, it flags any request with a response code >=400 as failed. If instead you want to treat 400 as a success, you can provide a telemetry initializer that sets the success property.
237237

238-
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.
238+
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.
239239

240-
**Define your initializer**
240+
### Define your initializer
241241

242-
*C#*
242+
**C#**
243243

244244
```csharp
245245
using System;
@@ -278,7 +278,9 @@ namespace MvcWebRole.Telemetry
278278
}
279279
```
280280

281-
ASP.NET **apps: Load your initializer**
281+
### Load your initializer
282+
283+
**ASP.NET apps**
282284

283285
In ApplicationInsights.config:
284286

@@ -304,7 +306,7 @@ protected void Application_Start()
304306

305307
See more of [this sample](https://github.com/MohanGsk/ApplicationInsights-Home/tree/master/Samples/AzureEmailService/MvcWebRole).
306308

307-
ASP.NET **Core/Worker service apps: Load your initializer**
309+
**ASP.NET Core/Worker service apps**
308310

309311
> [!NOTE]
310312
> 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.

0 commit comments

Comments
 (0)