1. Span selectors #
Empty braces are valid, but expensive.
Attributes and scopes #
{ resource.service.name = "checkout" } # attribut de ressource
{ span.http.status_code = 500 } # attribut de span
{ .http.status_code = 500 } # portée implicite (span puis ressource)
{ name = "POST /payer" } # nom du span
{ status = error } # statut : error | ok | unset
{ kind = server } # kind : server, client, producer...
{ duration > 2s } # durée du span
{ traceDuration > 5s } # durée de la trace complète
{ resource.service.name =~ "api-.*" && span.http.method != "GET" } # regex, &&, ||Good practice: Use qualified attribute names (span./resource.): searches are faster and unambiguous.
2. Structural operators #
Linking spans together.
Parent, child and descendant #
# Appels de paiement en erreur sous le service checkout (descendant)
{ resource.service.name = "checkout" } >> { resource.service.name = "payment" && status = error }
# Enfant direct
{ resource.service.name = "frontend" } > { resource.service.name = "checkout" }
# Spans frères (sibling)
{ span.db.system = "postgresql" } ~ { span.db.system = "redis" }
# Remontée : trouver l'ancêtre d'un span lent
{ duration > 1s } << { resource.service.name = "gateway" }| Operator | Meaning |
|---|---|
>> | A is an ancestor of B |
> | A is the direct parent of B |
~ | A and B are siblings |
<< / < | Reversed versions |
3. Aggregations and selection #
Analyzing the result.
TraceQL pipeline #
# Traces avec plus de 10 requêtes SQL (problème N+1 probable)
{ span.db.system = "postgresql" } | count() > 10
# Traces dont la durée moyenne des spans HTTP dépasse 500 ms
{ span.http.method != "" } | avg(duration) > 500ms
# Afficher uniquement certains attributs dans les résultats
{ status = error } | select(span.http.url, resource.service.name, span.exception.message)
# Regrouper
{ resource.service.name = "api" } | by(span.http.route) | count() > 5Through the API and the Tempo CLI #
curl -G -s http://localhost:3200/api/search \
--data-urlencode 'q={ resource.service.name = "checkout" && status = error }' \
--data-urlencode 'limit=20' --data-urlencode 'start='$(date -d '1 hour ago' +%s) --data-urlencode 'end='$(date +%s) | jq '.traces[].traceID'
curl -s http://localhost:3200/api/search/tags | jq # attributs disponibles
curl -s http://localhost:3200/api/search/tag/service.name/values | jq4. Ready-to-use diagnostic queries #
A small catalog.
Catalog #
| Goal | TraceQL query |
|---|---|
| Recent errors of a service | { resource.service.name = "checkout" && status = error } |
| Slow requests (> 2 s) | { kind = server && duration > 2s } |
| Outgoing HTTP 5xx calls | { kind = client && span.http.status_code >= 500 } |
| Excessive retries | { name = "http.retry" } | count() > 3 |
| Traces for one user | { span.user.id = "42" } |
