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
+24-28Lines changed: 24 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,11 +22,9 @@ You can write code to filter, modify, or enrich your telemetry before it's sent
22
22
> [!NOTE]
23
23
> [The SDK API](./api-custom-events-metrics.md) is used to send custom events and metrics.
24
24
25
-
Before you start:
25
+
## Prerequisites
26
26
27
-
* Install the appropriate SDK for your application: [ASP.NET](asp-net.md), [ASP.NET Core](asp-net-core.md), [Non-HTTP/Worker for .NET/.NET Core](worker-service.md), or [JavaScript](javascript.md).
28
-
29
-
<aname="filtering"></a>
27
+
Install the appropriate SDK for your application: [ASP.NET](asp-net.md), [ASP.NET Core](asp-net-core.md), [Non-HTTP/Worker for .NET/.NET Core](worker-service.md), or [JavaScript](javascript.md).
30
28
31
29
## Filtering
32
30
@@ -38,13 +36,11 @@ To filter telemetry, you write a telemetry processor and register it with `Telem
38
36
> Filtering the telemetry sent from the SDK by using processors can skew the statistics that you see in the portal and make it difficult to follow related items.
39
37
>
40
38
> Instead, consider using [sampling](./sampling.md).
41
-
>
42
-
>
43
-
44
-
### Create a telemetry processor
45
39
46
40
### C#
47
41
42
+
#### Create a telemetry processor
43
+
48
44
1. To create a filter, implement `ITelemetryProcessor`.
49
45
50
46
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.
@@ -139,23 +135,23 @@ To filter telemetry, you write a telemetry processor and register it with `Telem
139
135
140
136
ToregistertelemetryprocessorsthatneedparametersinASP.NETCore, createacustomclassimplementing **ITelemetryProcessorFactory**. Call the constructor with the desired parameters in the **Create** method and then use **AddSingleton<ITelemetryProcessorFactory, MyTelemetryProcessorFactory>()**.
141
137
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.
138
+
#### Example filters
139
+
140
+
##### Synthetic requests
141
+
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
+
144
+
```csharp
145
+
public void Process(ITelemetryitem)
146
+
{
147
+
if (!string.IsNullOrEmpty(item.Context.Operation.SyntheticSource)) {return;}
147
148
148
-
```csharp
149
-
public void Process(ITelemetryitem)
150
-
{
151
-
if (!string.IsNullOrEmpty(item.Context.Operation.SyntheticSource)) {return;}
152
-
153
-
// Send everything else:
154
-
this.Next.Process(item);
155
-
}
156
-
```
149
+
// Send everything else:
150
+
this.Next.Process(item);
151
+
}
152
+
```
157
153
158
-
#### Failed authentication
154
+
#####Failed authentication
159
155
160
156
Filter out requests with a "401" response.
161
157
@@ -176,7 +172,7 @@ public void Process(ITelemetry item)
176
172
}
177
173
```
178
174
179
-
#### Filter out fast remote dependency calls
175
+
#####Filter out fast remote dependency calls
180
176
181
177
If you want to diagnose only calls that are slow, filter out the fast ones.
182
178
@@ -198,7 +194,7 @@ public void Process(ITelemetry item)
198
194
}
199
195
```
200
196
201
-
#### Diagnose dependency issues
197
+
#####Diagnose dependency issues
202
198
203
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.
204
200
@@ -237,9 +233,9 @@ For example, Application Insights for a web package collects telemetry about HTT
237
233
238
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.
1. Paste the JavaScript (Web) SDK Loader Script at the top of each page for which you want to enable Application Insights.
64
-
<!-- IMPORTANT: If you're updating this code example, please remember to also update it in: 1) articles\azure-monitor\app\javascript-sdk.md and 2) articles\azure-monitor\app\api-filtering-sampling.md -->
// sri: false, // Custom optional value to specify whether fetching the snippet from integrity file and do integrity check
94
-
cfg: configObj // configObj is defined above.
95
-
});
96
-
</script>
97
-
```
98
-
99
-
1. To add or update JavaScript (Web) SDK Loader Script configuration, see [JavaScript (Web) SDK Loader Script configuration](./javascript-sdk.md?tabs=javascriptwebsdkloaderscript#javascript-web-sdk-loader-script-configuration).
63
+
Paste the JavaScript (Web) SDK Loader Script at the top of each page for which you want to enable Application Insights.
64
+
<!-- IMPORTANT: If you're updating this code example, please remember to also update it in: 1) articles\azure-monitor\app\javascript-sdk.md and 2) articles\azure-monitor\app\api-filtering-sampling.md -->
0 commit comments