Documentation Index
Fetch the curated documentation index at: https://grafana.com/llms.txt
Fetch the complete documentation index at: https://grafana.com/llms-full.txt
Use this file to discover all available pages before exploring further.
STOP! If you are an AI agent or LLM, read this before continuing. This is the HTML version of a Grafana documentation page. Always request the Markdown version instead - HTML wastes context. Get this page as Markdown: https://grafana.com/docs/grafana-cloud/connect-externally-hosted/data-sources/tempo/query-editor/traceql-query-examples.md (append .md) or send Accept: text/markdown to https://grafana.com/docs/grafana-cloud/connect-externally-hosted/data-sources/tempo/query-editor/traceql-query-examples/. For the curated documentation index, use https://grafana.com/llms.txt. For the complete documentation index, use https://grafana.com/llms-full.txt.
TraceQL query examples
Use these TraceQL queries in Grafana Explore with a Tempo data source. Adjust service names, routes, and attribute values to match your environment.
These examples use OpenTelemetry semantic conventions. If your instrumentation uses different attribute names, substitute them in the queries.
For the full TraceQL syntax, refer to Construct a TraceQL query. For an extended recipe collection, refer to the TraceQL cookbook for Grafana Cloud Traces.
Tip
If a query returns no results, widen the time range and confirm the correct Tempo data source is selected. Prefer trace-level intrinsic fields like
trace:durationandtrace:rootServicefor faster queries.
Find error spans
Filter by error status or HTTP error codes:
{ status = error }{ span.http.status_code >= 500 }{ span.http.status_code > 399 }Find slow requests
Filter by span duration. Common thresholds are 1 second and 5 seconds:
{ duration > 1s }{ duration > 5s }Filter a specific endpoint by duration:
{ span.http.url = "/api/checkout" && duration > 2s }Find exceptions by type
Query exception events recorded on spans.
Exception data uses the event scope because OpenTelemetry records exceptions as span events:
{ event.exception.message =~ "context cancelled" }{ event.exception.type = "NotFoundException" }Find error spans that have an exception message:
{ status = error && event.exception.message != "" }Filter by service
Select spans from a specific service or match services by pattern. You can use the Service Graph view to identify which services have high error rates or latency, then query those services with TraceQL.
{ resource.service.name = "checkout" }{ resource.service.name =~ "payment.*" && status = error }Find errors and slow spans together
Combine error status and duration filters to identify likely root causes:
{ resource.service.name = "api" && status = error && duration > 1s }Analyze service dependencies
Find errors on a specific API path:
{ span.http.url =~ ".*/api/.*" && span.http.status_code >= 500 }Use the descendant operator (>>) to find traces where a frontend service calls a downstream service that errors:
{ resource.service.name = "frontend" } >> { resource.service.name = "database" && status = error }Query rate and count metrics
Run these in Metrics mode in Explore. TraceQL metrics queries have a default 24-hour time-range limit:
{ } | rate(){ status = error } | rate(){ resource.service.name = "api" } | count_over_time(){ duration > 1s } | rate()Filter by region or environment
Narrow results to a specific cloud region or deployment environment:
{ resource.cloud.region = "us-east-1" && status = error }{ resource.deployment.environment = "production" && duration > 2s }Use dashboard variables
Replace hard-coded values with
dashboard variables when using these queries in panels.
For example, using a $service variable:
{ resource.service.name = "$service" && status = error }More resources
- TraceQL cookbook for Grafana Cloud Traces - Extended recipe collection with additional examples
- Construct a TraceQL query - Full TraceQL syntax, scopes, and operators
- Query tracing data - Query editor modes and options
- Service Graph and Service Graph view - Visualize service dependencies
Was this page helpful?
Related resources from Grafana Labs


