Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Hosted-services / Azure

Add tags to Azure functions - Application Insights

5.00/5 (1 vote)
7 Feb 2021CPOL 5.7K  
Adding diagnostic tags to your functions for debugging
When looking at the traces of your Azure Functions in Application Insights, you might want some additional information available. You can add code to the function to allow custom tags to be added which you can then query on in Application Insights.

Adding the Tag in Your Function

To add the tag in your Azure function, you need to add a reference to System.Diagnostics and then call Activity.Current.AddTag to add your tag in the application insights log.

For example, a function that has a property "Account Number" could add this to the log thus:

C#
#region Tracing telemetry
   Activity.Current.AddTag("Account Number", accountnumber);
#endregion

Querying the Tag

In your application insights query, you can use the customDimension function to access your custom tag.

Image 1

History

  • 7th February, 2021: First version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)