POST POST

JUL
1
2018

Application Insights Cloud Role Name

ORIGINALLY POSTED TO: https://blog.simontimms.com/2018/07/01/app_insights_appname/

Logging is super important in any microservices environment or really any production environment. Being able to trace where your log messages are coming from is very helpful. Fortunately Application Insights have a field defined for just that.

The field we should be looking at is called cloud_RoleName in the Analytics page. You'll need to set this in your logging client. Depending on the language you're using the way to do this differs.

Let's say that we're going to call our application EMailSender the this is how to set it. (All of these assume you're Applications Insights Client is called appInsightsClient)

C #

1
appInsightsClient.Context.Cloud.RoleName = "EMailSender"

F #

1
appInsightsClient.Context.Cloud.RoleName <- "EMailSender"

VB.NET

1
appInsightsClient.Context.Cloud.RoleName = "EMailSender"

Server-side JavaScript

1
appInsightsClient.context.tags[appInsightsClient.context.keys.cloudRole] = 'EMailSender';

Client-side JavaScript

This one is a little different

1
2
3
4
5
appInsightsClient.queue.push(() => {
appInsightsClient.context.addTelemetryInitializer((envelope: Microsoft.ApplicationInsights.IEnvelope) => {
envelope.tags['ai.cloud.role'] = "EMailSender";
});
});

Python

1
appInsightsClient.context.device.role_name = 'EMailSender'

In the portal we can now add a new column to our search results called cloud_RoleName which should be populated with EMailSender. We can use this field in any query as needed.

Selecting cloud_RoleName

I like to drag that column to the left-hand side so I can see it right away.


Simon Timms

Email Email
Web Web
Twitter Twitter
GitHub GitHub
RSS

Looking for someone else?

You can find the rest of the Western Devs Crew here.

© 2015 Western Devs. All Rights Reserved. Design by Karen Chudobiak, Graphic Designer