MS Azure Application Insights¶
Azure Application Insights is a monitoring and diagnostics service provided by Microsoft Azure that allows you to collect and analyze telemetry data. In Virto Commerce, it collects metrics, application telemetry data, and application trace logging data within the Application Insights module.
Virto Commerce Application Insights module¶
Application Insights was integrated to the VC platform till the release of 3.314.0 version, where it was replaced with Serilog library.
You can still use MS Azure Application Insights by installing it separately as a module:
- Without extra settings.
- Setting the required configurations if you prefer a customized version.
Application Insights module сonfiguration¶
Configuring the Application Insights module includes:
- Configuring telemetry from the appsettings.json file.
- Configuring logging from the appsettings.json file.
- Configuring logging from code.
Configure telemetry from appsettings.json file¶
To send data to the Application Insights dashboard via the instrumentation key:
-
Use current active telemetry configuration which is already initialized in most application types like ASP.NET Core:
-
Configure Platform AP telemetry behavior inside the
VirtoCommerce:ApplicationInsights
section:appsettings.json{ "VirtoCommerce": { "ApplicationInsights": { "SamplingOptions": { "Processor": "Adaptive", "Adaptive": { "MaxTelemetryItemsPerSecond": "5", "InitialSamplingPercentage": "100", "MinSamplingPercentage": "0.1", "MaxSamplingPercentage": "100", "EvaluationInterval": "00:00:15", "SamplingPercentageDecreaseTimeout": "00:02:00", "SamplingPercentageIncreaseTimeout": "00:15:00", "MovingAverageRatio": "0.25" }, "Fixed": { "SamplingPercentage": 90 }, "IncludedTypes": "Dependency;Event;Exception;PageView;Request;Trace", "ExcludedTypes": "" }, "EnableSqlCommandTextInstrumentation": true, "IgnoreSqlTelemetryOptions": { "QueryIgnoreSubstrings": [ "[HangFire].", "sp_getapplock", "sp_releaseapplock" ] } } } }
Values used are described below:
Node | Default or Sample Value | Description |
---|---|---|
SamplingOptions.Processor | adaptive fixed-rate |
This setting lets you chose between two sampling methods: Adaptive sampling: automatically adjusts the volume of telemetry sent from the SDK in your ASP.NET/ASP.NET Core app, and from Azure Functions. Learn more about configuring this option. Fixed-rate sampling: reduces the volume of telemetry sent from both the application. Unlike adaptive sampling, it reduces telemetry at a fixed rate controlled by SamplingPercentage setting. |
SamplingOptions.Adaptive.MaxTelemetryItemsPerSecond | 5 | Maximum telemetry items per second allowed in adaptive sampling. |
SamplingOptions.Adaptive.InitialSamplingPercentage | 100 | Initial sampling percentage in adaptive sampling. |
SamplingOptions.Adaptive.MinSamplingPercentage | 0.1 | Minimum sampling percentage in adaptive sampling. |
SamplingOptions.Adaptive.MaxSamplingPercentage | 100 | Maximum sampling percentage in adaptive sampling. |
SamplingOptions.Adaptive.EvaluationInterval | 00:00:15 | Interval between sampling evaluations in adaptive sampling. |
SamplingOptions.Adaptive.SamplingPercentageDecreaseTimeout | 00:02:00 | Timeout before decreasing sampling percentage in adaptive sampling. |
SamplingOptions.Adaptive.SamplingPercentageIncreaseTimeout | 00:15:00 | Timeout before increasing sampling percentage in adaptive sampling. |
SamplingOptions.Adaptive.MovingAverageRatio | 0.25 | Ratio used for moving average calculations in adaptive sampling. |
SamplingOptions.Fixed.SamplingPercentage | 100 | Fixed sampling percentage used for telemetry in Application Insights. |
SamplingOptions.IncludedTypes | Dependency Event Exception PageView Request Trace |
A semi-colon delimited list of types that you do want to subject to sampling. The specified types will be sampled. All telemetry of the other types will always be transmitted. All types are included by default. |
SamplingOptions.ExcludedTypes | Dependency Event Exception PageView Request Trace |
A semi-colon delimited list of types that you do not want to be sampled. All telemetry of the specified types is transmitted. The types that aren't specified will be sampled. Empty by default |
EnableSqlCommandTextInstrumentation | true | Controls Application Insight telemetry processor thats excludes dependency SQL queries. Any SQL command name or statement that contains a string from QueryIgnoreSubstrings options will be ignored. |
IgnoreSqlTelemetryOptions.QueryIgnoreSubstrings | [HangFire]., sp_getapplock, sp_releaseapplock | Specifies substrings to ignore in SQL telemetry to avoid collecting irrelevant data, particularly related to Hangfire's internal operations. |
Configure logging from appsettings.json file¶
The module includes a Serilog sink for writing events to Microsoft Application Insights. Enable Application Insights logging by updating the following Serilog configuration sections:
{
"Serilog": {
"Using": [
"Serilog.Sinks.ApplicationInsights"
],
"WriteTo": [
{
"Name": "ApplicationInsights",
"Args": {
"connectionString": "<Copy connection string from Application Insights Resource Overview>",
"telemetryConverter": "Serilog.Sinks.ApplicationInsights.TelemetryConverters.TraceTelemetryConverter, Serilog.Sinks.ApplicationInsights",
"restrictedToMinimumLevel": "Error"
}
}
]
}
}
Make sure to specify the telemetryConverter with the full type and assembly name. A connection string is optional if provided via the APPLICATIONINSIGHTS_CONNECTION_STRING environment variable.
Configure logging from code¶
To configure Serilog's Application Insights sink in code:
-
Use special
ILoggerConfigurationService
interface:public class ApplicationInsightsLoggerConfiguration : ILoggerConfigurationService { private readonly TelemetryConfiguration _configuration; public ApplicationInsightsLoggerConfiguration(TelemetryConfiguration configuration) { _configuration = configuration; } public void Configure(LoggerConfiguration loggerConfiguration) { loggerConfiguration.WriteTo.ApplicationInsights(telemetryConfiguration: _configuration, telemetryConverter: TelemetryConverter.Traces, restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Error); } }
-
Register the
Initialize
method in module.cs: