Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to set appName in Application Insights custom events?

I noticed that App Insights has a field called appName (and appId) when querying in the analytics tool (see below), however I don't see a way of setting this in the client library. Can this be set?

I'm trying to log related items to app insights, though the log source may be different. Using that field seems like a nice way to handle that scenario, though I'm open to different scenarios.


screen shot of analytics tool

like image 965
Giovanni Galbo Avatar asked Jan 17 '17 16:01

Giovanni Galbo


People also ask

How do you query custom events in application insights?

In the Azure Portal, navigate to the Application Insights resource, and click Log Analytics. Log queries help you to fully leverage the value of the data collected in Azure Monitor Logs. Query your custom events by entering “customEvents” in the prompt and click Run.

What telemetry is automatically collected by application insights?

Application Insights sends telemetry from your web application to the Azure portal so that you can analyze the performance and usage of your application. The telemetry model is standardized, so it's possible to create platform and language-independent monitoring.

What is event telemetry?

Typically it is a user interaction such as button click or order checkout. It can also be an application life cycle event like initialization or configuration update. Semantically, events may or may not be correlated to requests. However, if used properly, event telemetry is more important than requests or traces.

How can you reduce telemetry traffic while preserving a statistically correct analysis of the web app data?

Sampling is a feature in Azure Application Insights. It's the recommended way to reduce telemetry traffic, data costs, and storage costs, while preserving a statistically correct analysis of application data.


2 Answers

There is a preview where you can set the application name. This is done in the following way:

  • enable the preview Application Map
  • set the ITelemetry.Context.Cloud.RoleName (this is the application name)

Enable preview: Go to the portal -> the application insights -> previews -> Enable Multi-role Application Map

Set the application name:

This is done by adding an interceptor:

public class ServiceNameInitializer : ITelemetryInitializer
{
    public void Initialize(ITelemetry telemetry)
    {
        telemetry.Context.Cloud.RoleName = "MyProcessName";
        // RoleInstance property modifies the app name in the telmetry dashboard
        telemetry.Context.Cloud.RoleInstance = "MyAppInstanceName";
    }
}

Add the interceptor to the application insights configuration in startup.cs:

private void ConfigureAppInsights(IServiceCollection services)
{
    services.AddApplicationInsightsTelemetry(Configuration);
    TelemetryConfiguration.Active.TelemetryInitializers
       .Add(new ServiceNameInitializer());
}

Read more at: cross-process-application-insights-with-multi-role-application-map

like image 115
Peter Avatar answered Oct 14 '22 04:10

Peter


Those values are populated in the backend and specify Application Insights resource details and thus cannot be changed.

What your're looking for is custom dimensions.

For example, to send the telemetry:

EventTelemetry telemetry = new EventTelemetry("my custom event");
telemetry.Properties.Add("MyApp", "HelloWorld");
telemetryClient.TrackEvent(telemetry);

To query those custom dimensions:

customEvents
| where customDimensions['MyApp'] == "HelloWorld"
like image 42
yonisha Avatar answered Oct 14 '22 06:10

yonisha