Table of Contents

Configuring Application Insights

Setting up Application Insights on a cluster for PRODUCTION

To see how to configure Application Insights in production, check this article.

Setting up Application Insights on a cluster for DEVELOPMENT

When developing, it can be very useful to link different your cluster with Application Insights. For example, if you encounter an exception, you will be able to find it later and see the events leading to it.

To set up Application Insights, you can either :

  • create a YAML file at the root of your cluster.
    The file name does not matter. In the file, create an ApplicationInsights section. In the section, you must define a sub-section for the part of the application you want to track : Generator, Server or Client. Options can be set in these sub-sections.
    Example :
    ApplicationInsights:
      Client:
        ConnectionString: InstrumentationKey=1a11a111-1a1a-1111-a111-1aaa1a1a1a11;IngestionEndpoint=https://westeurope-5.in.  applicationinsights.azure.com/;LiveEndpoint=https://westeurope.livediagnostics.monitor.azure.com/;  ApplicationId=2b22b222-2b2b-2222-b222-2bbb2b2b2b22
        CorrelationHeaderExcludedDomains:
          - domain1.com
          - domain2.com
      Generator:
        ConnectionString: InstrumentationKey=1a11a111-1a1a-1111-a111-1aaa1a1a1a11;IngestionEndpoint=https://westeurope-5.in.  applicationinsights.azure.com/;LiveEndpoint=https://westeurope.livediagnostics.monitor.azure.com/;  ApplicationId=2b22b222-2b2b-2222-b222-2bbb2b2b2b22
        DeveloperMode: true
      Server:
        ConnectionString: InstrumentationKey=1a11a111-1a1a-1111-a111-1aaa1a1a1a11;IngestionEndpoint=https://westeurope-5.in.  applicationinsights.azure.com/;LiveEndpoint=https://westeurope.livediagnostics.monitor.azure.com/;  ApplicationId=2b22b222-2b2b-2222-b222-2bbb2b2b2b22
        DeveloperMode: true
        EnableHeartbeat: false
        RequestCollectionOptions:
          TrackExceptions: false
    
  • for the server only, create an appSettings.Development.json file at the root of the cluster.
    In the file, create an ApplicationInsights section and set options inside of it.
    Example :
    {
      "ApplicationInsights": {
        "ConnectionString": "InstrumentationKey=1a11a111-1a1a-1111-a111-1aaa1a1a1a11;IngestionEndpoint=https://westeurope-5.in.  applicationinsights.azure.com/;LiveEndpoint=https://westeurope.livediagnostics.monitor.azure.com/;  ApplicationId=2b22b222-2b2b-2222-b222-2bbb2b2b2b22",
        "DeveloperMode": true,
        "EnableHeartbeat": false,
        "RequestCollectionOptions": {
          "TrackExceptions": false
        }
      }
    }
    

During the generation, Neos does the following :

  • reading the cluster YAML configuration.
  • configuring Application Insights for tracking generation logs using the generator configuration in the YAML configuration.
  • generating an appSettings.json file that contains the server Application Insights configuration. This file can be found in the same directory as the DLL of the AspNetCore project (usually myCluster\server\bin\MyCluster.AspNetCore).
  • copying the appSettings.Development.json file to the same directory as the DLL of the AspNetCore project (usually mycluster\server\bin\MyCluster.AspNetCore).
  • generating an applicationInsights.json file for the client. This file can be found in the public directory of the client (usually myCluster\client\public).

These are the files that are used to configure Application Insights in the server and client applications when you launch the neos run command.

Supported options

Before Neos 1.21

Before version 1.21, Neos only supports a predefined list of options.

Generator

Name Default value Description
DeveloperMode false When true, forces Application Insights to quickly send logs to the Azure repository to facilitate development. More information.
InstrumentationKey Required Instrumentation key of the Application Insights Azure repository that will receive logs from the generator.

Server

For more information, see the Microsoft documentation and GitHub.

Name Default value Description
AddAutoCollectedMetricExtractor true When true, adds a telemetry processor that sends pre-aggregated statistics about requests and dependencies.
DeveloperMode false Must be false in production. When true, forces Application Insights to quickly send logs to the Azure repository to facilitate development. More information.
EnableAdaptiveSampling true When true, reduces traffic by filtering certain data while maintaining accurate statistics. More information.
EnableAzureInstanceMetadataTelemetryModule true When true, monitors remote dependencies.
EnableDependencyTrackingTelemetryModule true When true, collects event counters. More information.
EnableEventCounterCollectionModule true When true, collects event counters. More information.
EnableHeartbeat true When true, periodically sends statistics about the execution environment (such as .NET version, Azure environment information, etc.) by default every 15 minutes.
EnablePerformanceCounterCollectionModule true When true, collects performance counters.
EnableQuickPulseMetricStream true When true, monitors CPU and memory usage in real-time.
EnableRequestTrackingTelemetryModule true When true, collects telemetry data for incoming web requests.
InstrumentationKey Required Instrumentation key of the Application Insights Azure repository that will receive logs from the server.
ResourceGroup Name of the Azure resource group the Application Insights repository belongs to. Only used for Application Insights code lens in Visual Studio. More information.
ResourceName Name of the Application Insights repository. Only used for Application Insights code lens in Visual Studio. More information.
TrackExceptions true When true, reports on the tracking of unhandled exceptions in the request collection module
Note

It is recommended to use the same instrumentation key for the server and the client.
This allows Application Insights to link together client and server logs to be able to see the full log history of an action.

Client

For more information, see the Microsoft documentation.

Name Default value Description
DisableAjaxTracking false When true, disables Ajax calls tracking.
DisableExceptionTracking false When true, disables exceptions tracking.
DisableFetchTracking false When true, disables Fetch requests tracking.
EnableAjaxErrorStatusText false When true, include response error data text boolean in dependency event on failed AJAX requests.
EnableAjaxPerfTracking false When true, enable looking up and including extra browser window.performance timings in the reported Ajax (XHR and fetch) reported metrics.
EnableAutoRouteTracking true When true, enables route changes tracking for Single Page Applications.
EnableCorsCorrelation true When true, adds two headers ('Request-Id' and 'Request-Context') to all CORS requests to correlate outgoing AJAX dependencies with corresponding requests on the server side.
EnableRequestHeaderTracking false When true, AJAX & Fetch request headers is tracked.
EnableResponseHeaderTracking false When true, AJAX & Fetch request's response headers is tracked
EnableUnhandledPromiseRejectionTracking true When true, tracks unhandled promise rejections in the code.
InstrumentationKey Required Instrumentation key of the Application Insights Azure repository that will receive logs from the client.
Note

It is recommended to use the same instrumentation key for the server and the client.
This allows Application Insights to link together client and server logs to be able to see the full log history of an action.

Since Neos 1.21

Generator

Name Default value Description
ConnectionString Required Connection string to the Application Insights Azure repository that will receive logs from the generator. If both ConnectionString and InstrumentationKey are configured, InstrumentationKey is ignored.
DeveloperMode false When true, forces Application Insights to quickly send logs to the Azure repository to facilitate development. More information.
InstrumentationKey Deprecated Use ConnectionString instead. Instrumentation key of the Application Insights Azure repository that will receive logs from the generator.

Server

Every available and future options are supported. Options can be found in the Microsoft documentation and on GitHub.

Prefer using ConnectionString instead of InstrumentationKey.
If both options a configured, InstrumentationKey is ignored. InstrumentationKey should only be used to see Application Insights stats in Visual Studio.

Neos sets default values for the following options when they are not set in the configuration :

Name Default value
RequestCollectionOptions.TrackExceptions true
Note

It is recommended to use the same connection string for the server and the client.
This allows Application Insights to link together client and server logs to be able to see the full log history of an action.

Client

Every available and future options are supported. Options can be found in the Microsoft documentation.

Prefer using ConnectionString instead of InstrumentationKey.
If both options a configured, InstrumentationKey is ignored.

Neos sets default values for the following options when they are not set in the configuration :

Name Default value
EnableAutoRouteTracking true
EnableCorsCorrelation true
EnableUnhandledPromiseRejectionTracking true
Note

It is recommended to use the same connection string for the server and the client.
This allows Application Insights to link together client and server logs to be able to see the full log history of an action.

Useful options for developers

DeveloperMode

This optional property is quite important when debugging a cluster. It forces Application Insights to send its logs to Azure far quicker than it usually does. This avoids having to wait several minutes before logs appearing in the Application Insights repository.
It must be set to false (its default value) in production.

Displaying Application Insights stats in the C# code in Visual Studio

Visual Studio can connect to Application Insights and display stats directly in the code through code lenses.

Neos can pre-configure generated C# projects. For this, in the Server section of the Application Insights configuration of the cluster, you can set:

  • InstrumentationKey: Instrumentation key of the Application Insights Azure repository that contains the logs.
  • ResourceGroup: the name of the Azure resource group to which the Application Insights repository belongs.
  • ResourceName: the name of the Application Insights repository.

After generation, when opening the C# solution in Visual Studio, you will see Requests and Exceptions code lenses in your code.
The first time you click on any on them, you will need to click on the Sign-in link. If your Visual Studio account is allowed to access the Azure Portal, you will see a list of the available Application Insights repositories. Choose the one matching your project an click on OK. Now stats should appear in the code lens.