Querying Python Metrics custom tags as CustomDimensions in Azure Application Insight

Azure Application Insights can be a collection point for Python Metrics that you can query and filter against.  We can send Open Census metrics from any data center into Azure Application Insights. This lets us see our program events from anywhere that can reach the Azure console.  It provides a zero admin performance console.

We can add custom dimensions (attributes) to every metrics record we send to Azure Application Insights. The OpenCensus Azure Exporter sends tags to Azure Application Insights as CustomDimensions.

Execution pre-requisites

  1. You have an Azure login
  2. You have created an Azure Application Insights Application key https://docs.microsoft.com/en-us/azure/azure-monitor/app/create-new-resource
  3. You have pushed data to Application Insights.  I used https://github.com/freemansoft/speedtest-app-insights

Video walkthrough

Data Capture Notes

Our test program generates custom metrics which we can see in the Metrics section as aggregates and in the Logs section as individual events. Metrics, Tracing, and Logs are all captured in the form of individual events in the Logs section of Application Insights.

Querying Metrics in the Application Insights Logs

  • Log in to the Azure portal 
  • Open up the Application Insights  resource that contains your data
  • Scroll down the left-hand side until you find Monitoring / Logs

  • Close the sample query pane on the right
  • You should end up with a query screen that was behind the overlay pane.

    • Type customMetrics into the query field and delete any extra terms that may have been added.
    • Set the time window for your query in the dropdown on the right.
    • Press on the Run button.
    • You should see a list of individual events.

    You may not see a custom dimensions column in the result table.  

    Do the following if there is no custom dimensions column
    • Click on the Columns drop list and scroll until you see custom dimensions in the list item.
    • Select that column.
    • The column will appear in future queries.

    All of the values in the customDimensions field are stored in a single JSON string.  You can see here how two custom speedtest tags were stored in Azure Application Insights as a JSON blob in the cusomDimensions field.


    Python Metrics and logs in Azure Applications Insights
    • http://joe.blog.freemansoft.com/2021/03/querying-python-logs-azure-application.html
    • http://joe.blog.freemansoft.com/2021/03/querying-python-metrics-custom-tags-as.html
    • http://joe.blog.freemansoft.com/2021/03/displaying-python-metrics-in-azure.html
    Microsoft Guides
    • https://docs.microsoft.com/en-us/azure/azure-monitor/app/opencensus-python
    • https://docs.microsoft.com/en-us/azure/azure-monitor/app/create-new-resource
    • https://github.com/census-instrumentation/opencensus-python/tree/master/contrib/opencensus-ext-azure
    Python Data generator 
    • https://github.com/freemansoft/speedtest-app-insights
    Created 3/2021


    Popular posts from this blog

    Accelerate Storage Spaces with SSDs in Windows 10 Storage Pool tiers

    Docker on a Chromebook on Crostini - Neverware CloudReady is ready

    Java 8 development on Linux/WSL with Visual Studio Code on Windows 10