Azure Functions – Integrating monitoring with Application Insights

In this last part of the series of blog posts on using Azure Function, we will introduce how we monitor our Azure Function thanks to Application Insights.

Basic monitoring

It’s possible to integrate Application Insights to your Azure Functions in a very basic way (see Azure Functions integration with Application Insights for details):

  • Without adding or changing a line of code.
  • Adding a key in the Application Settings of your Azure Function App.

This key must be named « APPINSIGHTS_INSTRUMENTATIONKEY » and contains the value of your resource’s Azure Application Insights Instrumentation Key.

clip_image002

We already talked about this key in Azure Function – Provisioning and configuring our Azure Function infrastructure and in the previous post Azure Function – CI / CD DevOps Pipeline.

By making this simple change, when your Azure Functions are called, you should see metrics populating in your Application Insights.

clip_image004 clip_image006

You will notice that based on the basic configuration done thus far, we only receive request based metrics.

Send custom telemetry

In this instance, we would like to capture more detailed telemetry than just requests. For example, we also want to analyze exceptions, certain specific events, and information around external dependencies such as the REST API calls to LaunchDarkly.

For this, in addition to the configuration in the Application Settings key, we need to reference the Microsoft.ApplicationInsights Nuget package in our Azure Function App (see Microsoft.ApplicationInsights for details).

clip_image008

Then write the code to send our custom telemetry in our Function Azure with steps below:

  • First, we need to instantiate a TelemetryClient using the configuration of the Application Setting key

 

  • In your Azure Function set a new context

 

  • Then use this object to send your metrics to send a trace

 

  • To track a dependency: in our case to track calls to the LaunchDarkly Rest API

 

  • Call to LaunchDarkly Rest Api

 

The source code of this integration is available in our Azure Function Code. See ApplicationInsights-dotnet for more details and samples on the Microsoft.ApplicationInsights

Monitoring

Now that we have added custom telemetry to our Azure Function, we can monitor and analyze our application with more precisions on the Application Insights Azure Portal.

See global monitoring for a view of the Azure function’s health.

clip_image010

In the Application Map we can see the calls to LaunchDarkly’s API with the number of calls and some request based performance counters.

clip_image012

We can also analyze some performance metrics in new Performance dashboard.

clip_image014

And in workbook module, we can write and run some custom queries for a desired view of the metrics, using a grid or graph result.

clip_image016

Summary

With this post, we end our series on development and continuous deployment of our Azure Functions.

In summary, we began with our research on the feasibility of the integration of feature flags with LaunchDarkly’s platform in our VSTS extensions with a three part series:

We then developed, tested and deployed these Azure Functions in our Azure subscription and decided to expose all this work around the Azure Functions and our DevOps practice through another four part series:

Finally, this article explains the integration of Application Insights in our Azure Function.

What’s the next step?

Now that we have built our infrastructure with VSTS, LaunchDarkly and the Azure Functions we can implement features flags in the Roll-Up board Widget extension as our showcase.

THANK YOU REVIEWERS: Edward Fry, Tiago Pascoal, Hamid Shahid