# Measure elapsed times for domain event handlers on Azure with using Application Insight telemetry

**URL:** <https://www.virtocommerce.org/t/measure-elapsed-times-for-domain-event-handlers-on-azure-with-using-application-insight-telemetry/340>\
**Category:** howto\
**Tags:** azure\
**Created:** [June 4, 2021, 9:52am UTC](https://www.virtocommerce.org/t/measure-elapsed-times-for-domain-event-handlers-on-azure-with-using-application-insight-telemetry/340 "2021-06-04T09:52:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tatarincev](https://yyz2.discourse-cdn.com/flex032/user_avatar/www.virtocommerce.org/tatarincev/32/161_2.png) [@tatarincev](https://www.virtocommerce.org/u/tatarincev)\
**Post date:** [June 4, 2021, 9:52am UTC](https://www.virtocommerce.org/t/measure-elapsed-times-for-domain-event-handlers-on-azure-with-using-application-insight-telemetry/340/1 "2021-06-04T09:52:34Z")

</div>

In this article, we introduce the basic technique how to measure the elapsed time for VirtoCommerce [domain handlers](https://www.virtocommerce.org/t/extensibility-basics-the-domain-model-and-persistence-layer-extension/141) with using [Microsoft Azure Monitoring Logs.](https://docs.microsoft.com/en-us/azure/azure-monitor/logs/data-platform-logs)

The domain events and their side effects (the actions triggered afterwards that are managed by event handlers) can be synchronous or asynchronous. But you should prefer asynchronous handlers on synchronous since the big amount of synchronous handles or their long execution can increase the execution time for the logical transaction or operation where this event is raised.

Sometimes it’s very helpful to see how long the event handler takes to execute, especially if you faced with performance issues on production on Azure that hard to reproduce locally or in another environment.

Luckily, the VC platform measures all execution times for all registered event handlers and writes them in the `ILogger` interface, which can be later read and analyzed.

To capture elapsed execution times for event handlers and instrument your app with the Application Insights you have to set this setting in the ` appsettings.{Environment}.json`

```auto
{
"Logging" : {
     "ApplicationInsights" : {
        "LogLevel" : {
            "VirtoCommerce.Platform.Core.Bus.InProcessBus" : "Information"
        }
     }
}

```

or set as one line in an Azure App configuration

```auto
Logging:ApplicationInsights:LogLevel:VirtoCommerce.Platform.Core.Bus.InProcessBus = Information

```

 ![image](https://canada1.discourse-cdn.com/flex032/uploads/virtocommerce/original/1X/976abbe5dae7c24335e2ee9d1e1b2c5a2c03a97f.png)

Afterwards you can analyze the resulting logs in the [Log queries in Azure Monitor](https://docs.microsoft.com/en-us/azure/azure-monitor/logs/log-query-overview)

By executed this [Kusto](https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/tutorial?pivots=azuredataexplorer) script:

```auto
union isfuzzy=true traces
| where timestamp > datetime("2021-05-03T09:15:16.814Z")
| where * has "VirtoCommerce.Platform.Core.Bus.InProcessBus"
| take 100
| project timestamp, Event = extract("event:([^\\s]+)", 1, message), Module = extract("module:([^\\s]+)", 1, message), Duration = toint(extract("overall_elapsed:([0-9.]+)", 1, message))
| order by Duration desc

```

 ![image](https://canada1.discourse-cdn.com/flex032/uploads/virtocommerce/original/1X/83d6ec3adf57a38b55126975cef0733a945fbc31.png)

With these statistics, you can better diagnose the performance problem for your solution.
