Inspecting Distributed Tracing with Application Insights
This lesson explains how traces connect services, and how to use them to find a cause.
Learning outcomes
After completing this lesson, you will be able to:
- Define traces and spans.
- Explain how trace context propagates.
- Use Application Map.
- Read an end-to-end transaction view.
Why tracing is needed
In a monolith, a stack trace shows what went wrong. In a distributed application, one request may touch a gateway, three services, a queue and a database, each on different machines. Logs from each service exist, but nothing joins them. Distributed tracing joins them by giving each request an identifier that travels with it.
How it works
A trace is the whole journey of one request. A span is one step in it, such as a database call, with a start time and duration. Spans have parent and child relationships, so the whole can be drawn as a tree.
Context travels between services in the W3C Trace Context headers, chiefly traceparent, which holds a trace ID and the current span ID. OpenTelemetry and Application Insights both use this standard, and they propagate it automatically for common libraries. In Application Insights, the trace ID appears as the operation ID, which is stored as OperationId in workspace tables. All telemetry items for one request share it.
Tracing works only where all services are instrumented. If one service in the chain is not, its part of the journey is missing, and the trace may seem broken. Asynchronous work through a queue needs the context to be passed in the message.
Traces, spans and context
Application Map
Application Map draws components and their dependencies, as discovered from telemetry. Each node shows request rate, failures and duration, and each connecting line shows calls between them, so a red node or line is a good place to begin. Selecting a component opens its failures and performance. The cloud role name sets how a service is labelled, and each service needs its own name, otherwise different services merge into a single node.
The map shows the structure of a system across all requests, whereas the next view shows just one.
End-to-end transaction details
The end-to-end transaction details view, or transaction diagnostics, shows one transaction as a Gantt chart. Each row is a span, its position shows when it started, and its length shows how long it took. Failed rows are marked, and details and exceptions appear alongside.
Reading the chart is straightforward. A long bar that contains a long child bar means that the time was spent in the child. A long bar with no children means that the time was spent in that component's own code, or in an uninstrumented call. Many short sequential bars to one database suggest an N+1 query problem, in which code makes one call per item in a loop.
The following diagram sketches the Gantt chart of a slow checkout transaction in Application Insights.

Reading the Gantt chart
A method for investigating
-
Find the symptom
Use the Failures or Performance view to find the affected operation.
-
Locate the component
Use Application Map to see where failures or latency are concentrated.
-
Pick a sample
Select a slow or failed example request.
-
Read the trace
Use the Gantt chart to find the span responsible.
-
Go to the logs
Query logs by operation ID to see the detail.
The final step uses KQL, which the next lesson teaches. The following query lists everything recorded for one request.
union AppRequests, AppDependencies, AppExceptions, AppTraces
| where OperationId == "5f1b2c7a9e0d4d13a7c2b18e6f4d9a30"
| order by TimeGenerated ascInvestigating a slow request
Finding a slow dependency
Users report that checkout takes 8 seconds. Host metrics for the checkout service are normal. Which tool should you use, and what would you expect to find?
Use the end-to-end transaction details for a slow checkout request. Healthy hosts suggest that the time goes to a dependency, and the Gantt chart would show a long span, perhaps a call to a payment API or a database. Application Map would help to find the likely component first. Scaling the service would not help with a slow dependency, and VM insights would only confirm what the host metrics already show.
Two services appear as one node on Application Map. What is the likely cause?
Show answer
They share a cloud role name, so each service needs its own.
Exam Tips
Remember for the exam
- A trace is a whole request; a span is one step.
- Operation ID links all telemetry for a request.
- Application Map shows components, failures and latency.
- The end-to-end transaction view shows a Gantt chart of one request.
- Each service needs instrumentation and its own cloud role name.