Skip to content

3. Monitoring and Logging

Stoyan Karev edited this page Mar 24, 2024 · 15 revisions

eShopOnWeb-rg-dev

Related code changes can be found here
See Code Changes Temporary code required to simulate exceptions or add additional logging is not included.

Add Application Insights Logging and Check Metrics.

  1. The bicep script nows provisions an Application Insights resource and sets up the PublicApi Web App to connect to it.
    Application Insights SDK has been integrated into PublicApi project.

  2. CatalogItemListPagedEndpoint logs the number of matching catalog items using Information Log Level.
    The log entry can be found in Application Insights with the following query.

traces
| where customDimensions.CategoryName == "Microsoft.eShopWeb.PublicApi.CatalogItemEndpoints.CatalogItemListPagedEndpoint"
| where timestamp >= ago(1h)

Query Result

  1. Examine the number of requests and CPU metrics in App Service Metrics

  2. Simulate an exception in CatalogItemListPagedEndpoint.HandleAsync with message 'Cannot move further'. After calling the endpoint, number of matching exceptions can be found by executing the following Kusto Query

exceptions
| where timestamp > ago(1h)
| where outerMessage == 'Cannot move further'
| summarize count()

Result

Exception's stack trace is visible in the Failures tab

Stack Trace

Investigate the application that crashing during the start.

Modified Program.cs to throw an exception on line 32. After deploying the changes the application fails to start as expected. The exception is visible in Diagnose and solve problems | Application Logs

Exception

Resources

sk-appi-dev

Application Insight resource Bicep definition

sk-appi-dev - Overview

sk-log-dev

Log Analytics Workspace used by sk-appi-dev Bicep definition

sk-log-dev - Overview

sk-app-api-dev

Resource connected with Application Insights sk-appi-dev Bicep definition

sk-app-api-dev - Configuration

Clean Up

All resources were deleted afterwards