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.
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.
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).
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.
In the Application Map we can see the calls to LaunchDarkly’s API with the number of calls and some request based performance counters.
We can also analyze some performance metrics in new Performance dashboard.
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.
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:
- In Building VSTS Extensions with feature flags we exposed our ideas on scenarios and use cases of feature flags integration in a VSTS extension by using the LaunchDarkly platform.
- In Building VSTS Extensions with feature flags – Part 2 we exposed various issues and theirs solutions that we had with these scenarios and use cases :
- Call to server-side code, which will be called in the Azure Functions
- Securing the call to our Azure Function by using VSTS tokens
- In Building VSTS Extensions with feature flags of this series we showed how we call the LaunchDarkly RestAPI through the Azure Functions.
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:
- Starting with development, debugging and unit testing of the Azure Functions – Prepare for continuous delivery using the latest version of Visual Studio 2017 15.3.
- The Azure Function – Provisioning and configuring our Azure Function infrastructure post entered the heart of the DevOps subject with the provisioning and the configuration of our infrastructure using Azure ARM templates.
- The Azure Function – Integration tests automation post exposed how we created and automated our integration tests with the Postman tool.
- The Azure Function – CI / CD DevOps Pipeline post gave details on the construction and execution of our pipeline DevOps of CI / CD in VSTS.
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
Comments
- Anonymous
May 08, 2018
DONT USE Microsoft.ApplicationInsights 2.5.1 Wasted whole day figuring it out. Downgrade it to 2.4.1/0 and that should be ok.System.Private.CoreLib: Exception while executing function: my-function. MyFunctionProject: Could not load file or assembly 'Microsoft.ApplicationInsights, Version=2.5.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621). System.Private.CoreLib: Could not load file or assembly 'Microsoft.ApplicationInsights, Version=2.5.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.