Querying Python Transactions and Spans as dependencies in Azure Application Insights with OpenCensus

Azure Application Insights is my go-to Observability platform when I want it to "just work". Application Insights can be a collection point for custom and third-party library Python Tracing and Transaction data. You can easily send Python Open Census span data from anywhere in the world into Azure Application Insights. You see your program transaction details from any browser that can reach the Azure console. 

OpenCensus spans are captured in Application Insights as dependencies. The OpenCensus Azure Exporter supports nested spans letting you capture and measure nested operations. Every captured span is stored as a row in the Application Insights dependencies table. 

The chart to the right was created from this sample code that has one main span and 4 nested sub-spans

From FreemanSoft SpeedTest project https://github.com/freemansoft/speedtest-app-insights

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 , a project that generates metrics, dependencies, and traces

Video Walkthrough

Everything ends up in App Insights Logs.

Our Python nested trace contexts end up as individual events in the Application Insights dependencies table.  We can query the AppInsights Logs to verify we have recorded trade information.
  1. AppInsights --> Monitoring/Logs
  2. Close the popover wizard if it appears
  3. Enter 'dependencies' in the search term
  4. Select the time frame
  5. Run the Query

Nested Trace Details

There are a couple things that link the trace details together.

  1. All the items in a nested span share the same operationa_id.  That same id is also the operation ParentId for the topmost span. Highlighted in purple.
  2. This particular trace has one parent span with 4 sub spans and no further nesting.  The parentId field for each of the subs-pans has the same id as the outermost span.  Highlighted in red


Finding transactions

    The App Insights Transaction Search pane lets you locate Dependency events. These are the records from the dependencies table we queried above. It actually shows a couple record types but we want Dependency

    This view shows us we have data and when but doesn't show us any correlated information. This trace just picks up everything in the last 6 hours


    We see the 5 OpenCensus Trace records here similar to the ones we saw above.

    Viewing as Nested Transactions

      A nested set of operations is captured as linked dependency events as described above.   We can drill into any span/event and visualize it and its nested or parent operations. 

      Here we see the overall timing for our speed check and the contribution to that time from each of the internal operations that were captured in their own spans.

      Additional Filtering by span/dependency

      We can filter by specific operation/dependency names or other attributes like spans over a certain duration.  Here we filter on the measure_download span


      Then we can just click on any one of those and it will show us that span/dependency and any that it is related to.  The timing on the right is everything around the measure_download we drilled into.


      Additional Integrations

      You can add additional 3rd party library integrations that will automatically create outer spans for inbound and outbound web and other requests.

      Related

      • https://joe.blog.freemansoft.com/2022/11/querying-python-transactions-and-spans.html
      • https://joe.blog.freemansoft.com/2021/03/querying-python-logs-azure-application.html
      • https://joe.blog.freemansoft.com/2021/03/querying-python-metrics-custom-tags-as.html
      • https://joe.blog.freemansoft.com/2021/03/displaying-python-metrics-in-azure.html
      • https://joe.blog.freemansoft.com/2021/03/monitor-internet-broadband-service-with.html

      Modification History

      Created 2022 10

      Comments

      Popular posts from this blog

      Installing the RNDIS driver on Windows 11 to use USB Raspberry Pi as network attached

      Understanding your WSL2 RAM and swap - Changing the default 50%-25%

      Almost PaaS Document Parsing with Tika and AWS Elastic Beanstalk