-
Notifications
You must be signed in to change notification settings - Fork 10.3k
14. Using Application Insights in eShopOnContainers
The MVC and WebForms modernized applications have installed the Application Insights Nuget packages to produce metrics and send it to an Azure Application Insights service. The only thing we need to configure is the Instrument Key of the Azure Application Insights where we want to receive the data.
We can find in the 'docker-compose.override.yml' file the variable to set:
- AppInsightsInstrumentationKey=${APP_INSIGHTS_INSTRUMENTATION_KEY}
As for the rest of variables it needs to be set in different ways depending on the environment (VM, Serfice Fabric or Kubernetes).
Open the Azure portal, click new, and search for Application Insights. In the creation form select Application Type Asp.NET web application
.
Once created the App Insights, go to the Configuration and enable 'Multi-role application map'.
Finally retrieve the Instrumentation Key from you Application Insights service and set it in your application as the value for the AppInsightsInstrumentationKey
variable.
Once the instrumentation key is set in the settings of the application and the Azure Applications Insights is created in our Azure portal, everything is ready to start receiving the metrics. Go to the Portal and select the Application Insights service bound to your application. There you can click on 'Search' in order to see all the metrics. You can select multiple filters to customize the list results.
You can see in the Search list, among other metrics, the log traces of the applications under the TRACE
type. The traces have been added to the metrics by installing in the MVC and WebForms applications the optional Nuget package Microsoft.ApplicationInsights.TraceListener with its corresponding configuration.
Another metric, this one automatically retrieved by default, are the web requests under the REQUEST
type:
For the requests as extra information you can see the field 'Cloud role name'. In this field we store the name of the service, allowing us to filter all the requests by the name of the service we want to. 'Cloud role name' parameter has been configured in the applications with the class MyTelemetryInitializer
, a custom telemetry initializer which implements ITelemetryInitializer
. Otherwise the parameter will not appear. You can review this initializer to add your own values to the Cloud role name.
In order to get some extra information from the metrics when the services are in a Service Fabric cluster, we have installed the optional Nuget package Microsoft.ApplicationInsights.ServiceFabric. Here we obtain information about the node where the container is:
In this case as you can notice that 'Clour role name' parameter does not appear here. By clicking the ...
at the end of the property list, we can see again the configured 'Clour role name' parameter with the name of the service, in this case the eShopModernizedWebForms:
- System requirements
- Development setup
- Databases & containers
- Architecture
- Application
- Code
- Logging and Monitoring
- Tests