Skip to content

Commit cb55bfa

Browse files
committed
examples
1 parent c665b4c commit cb55bfa

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ protected void Application_Start()
278278

279279
[See more of this sample.](https://github.com/Microsoft/ApplicationInsights-Home/tree/master/Samples/AzureEmailService/MvcWebRole)
280280

281-
**ASP.NET Core apps: Load your initializer**
281+
**ASP.NET Core/ Worker Service apps: Load your initializer**
282282

283283
> [!NOTE]
284284
> Adding initializer using `ApplicationInsights.config` or using `TelemetryConfiguration.Active` is not valid for ASP.NET Core applications.
@@ -361,6 +361,37 @@ For a summary of the non-custom properties available on the telemetryItem, see [
361361

362362
You can add as many initializers as you like, and they are called in the order they are added.
363363

364+
### Example enrichers
365+
366+
#### Add custom property
367+
368+
The following sample initializer adds a custom property to every tracked telemetry.
369+
370+
```csharp
371+
public void Initialize(ITelemetry item)
372+
{
373+
var itemProperties = item as ISupportProperties;
374+
if(itemProperties != null && !itemProperties.ContainsKey("customProp"))
375+
{
376+
itemProperties.Properties["customProp"] = "customValue";
377+
}
378+
}
379+
```
380+
381+
#### Add cloud role name
382+
383+
The following sample initializer sets cloud role name to every tracked telemetry.
384+
385+
```csharp
386+
public void Initialize(ITelemetry telemetry)
387+
{
388+
if(string.IsNullOrEmpty(telemetry.Context.Cloud.RoleName))
389+
{
390+
telemetry.Context.Cloud.RoleName = "MyCloudRoleName";
391+
}
392+
}
393+
```
394+
364395
## ITelemetryProcessor and ITelemetryInitializer
365396

366397
What's the difference between telemetry processors and telemetry initializers?

0 commit comments

Comments
 (0)