mirror of
https://github.com/hanzoai/traces.git
synced 2026-10-30 18:20:41 +00:00
* Support span:childCount intrinsic with new column in vp5 * Fix tests, update build image and re-gen traceql * changelog
4.5 KiB
4.5 KiB
TraceQL Basic Query Documentation
Overview
TraceQL is a query language for searching and filtering traces. Queries are expressions evaluated on one trace at a time, structured as a set of chained expressions called a pipeline. TraceQL selection can not answer broad questions about trace data. It can only find specific traces. Use metrics for broader questions.
Query Structure
TraceQL queries use curly brackets {} to select spans from traces. Each query expression filters spans based on conditions.
Basic Syntax
{ <conditions> }
Pipeline Structure
{ <span_selection> } | <aggregator> | <condition>
Scopes and Attributes
TraceQL differentiates between intrinsics (fundamental to spans) and attributes (customizable key-value pairs).
Intrinsic Fields
Intrinsic fields use colon notation <scope>::
span:status- Status: error, ok, or unsetspan:statusMessage- Optional text accompanying span statusspan:duration- End - start time of the spanspan:name- Operation or span namespan:kind- Kind: server, client, producer, consumer, internal, unspecifiedspan:id- Span ID using hex stringspan:parentID- Parent span ID using hex stringspan:childCount- Number of direct children of the spantrace:duration- Max(end) - min(start) time of spans in tracetrace:rootName- Name of the root span (if it exists)trace:rootService- Service name of the root span (if it exists)trace:id- Trace ID using hex stringevent:name- Name of eventevent:timeSinceStart- Time of event relative to span startlink:spanID- Link span ID using hex stringlink:traceID- Link trace ID using hex stringinstrumentation:name- Instrumentation scope nameinstrumentation:version- Instrumentation scope version
Attribute Fields
Attributes use dot notation <scope>.:
span.- Span attributesresource.- Resource attributesevent.- Event attributeslink.- Link attributesinstrumentation.- Instrumentation scope attributes
Comparison Operators
=- Equality!=- Inequality>- Greater than>=- Greater than or equal<- Less than<=- Less than or equal=~- Regular expression match (fully anchored)!~- Negated regular expression match
Regular Expression Notes
- All regex patterns are fully anchored (treated as
^pattern$) - Use
.*pattern.*for unanchored matching - TraceQL uses Golang regular expressions
Logical Operators
&&- AND (all conditions must be true on the same span)||- OR (either condition can be true)
Spanset Operators
Spanset operators allow conditions to be asserted on different spans within a trace. Also see strutural operators.
{condA} && {condB}- Both conditions found matches{condA} || {condB}- Either condition found matches
Common Examples
Find traces of a specific operation
{ resource.service.name = "frontend" && span:name = "POST /api/orders" }
Find traces with environment and service specification
{
resource.service.namespace = "ecommerce" &&
resource.service.name = "frontend" &&
resource.deployment.environment = "production" &&
span:name = "POST /api/orders"
}
Find traces with errors
{ resource.service.name = "frontend" && span:name = "POST /api/orders" && span:status = error }
Find traces with HTTP 5xx errors
{ resource.service.name = "frontend" && span:name = "POST /api/orders" && span.http.status_code >= 500 }
Find traces with specific behavior patterns
{ resource.service.name = "frontend" && span:name = "GET /api/products/{id}" } && { span.db.system = "postgresql" }
Find traces going through multiple environments
{ resource.deployment.environment = "production" } && { resource.deployment.environment = "staging" }
Find traces with arrays
{ span.foo = "bar" }
{ span.http.request.header.Accept =~ "application.*" }
Field expressions with combined conditions
{ span.http.status_code >= 200 && span.http.status_code < 300 }
{ span.http.method = "DELETE" && span:status != ok }
Check attribute existence
{ span.any_attribute != nil }
Using quoted attribute names
{ span."attribute name with space" = "value" }
{ span.attribute."attribute name with space" = "value" }
Performance Tips
- Use trace-level intrinsics (
trace:duration,trace:rootName,trace:rootService) when possible for better performance - Use appropriate scopes to limit data scanning
- Use specific span selections to reduce data processing