Click here to Skip to main content
15,885,365 members
Articles / Hosted Services / Azure
Tip/Trick

Add tags to Azure functions - Application Insights

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
7 Feb 2021CPOL 5.2K   1  
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)


Written By
Software Developer
Ireland Ireland
C# / SQL Server developer
Microsoft MVP (Azure) 2017
Microsoft MVP (Visual Basic) 2006, 2007

Comments and Discussions

 
-- There are no messages in this forum --