Skip to content

Commit 732d062

Browse files
committed
Add traceql reference
1 parent a7a1cc0 commit 732d062

File tree

4 files changed

+109
-15
lines changed

4 files changed

+109
-15
lines changed

docs/how-to-guides/observability/tracing/tempo.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Once you have traces being collected, you can visualize and query them in Grafan
1414

1515
The easiest way to get started with querying traces in Grafana Tempo is to use the query builder mode. The query builder mode is a graphical interface that helps you build LogQL queries by selecting labels and fields from your logs.
1616

17-
Start by selecting the `*-tempo` data source for the environment you want to query traces for. Then select the Search query type to open the query builder mode.
17+
Start by selecting the tempo data source for the environment you want to query traces for (one ending with `-tempo`). Then select the Search query type to open the query builder mode.
1818

1919
![Grafana Tempo Query Builder](../../../assets/grafana-tempo-query-builder.png)
2020

@@ -24,7 +24,17 @@ Bellow the query builder you will see the TraceQL query that is being built as y
2424

2525
Click the `Run query` button to run the query and see the results. You can also add the query to a dashboard by clicking the `Add to dashboard` button.
2626

27-
[:octicons-link-external-24: Learn more about Grafana Tempo query editor](https://grafana.com/docs/grafana/latest/datasources/tempo/query-editor/)
27+
[:octicons-link-external-24: Learn more about Grafana Tempo query editor on grafana.com](https://grafana.com/docs/grafana/latest/datasources/tempo/query-editor/)
28+
29+
### TraceQL query language
30+
31+
Grafana Tempo uses the TraceQL query language to query traces. TraceQL is a query language for querying trace data, and it is based on the LogQL query language used by Grafana Loki for querying logs and the PromQL query language used by Prometheus for querying metrics.
32+
33+
TraceQL provides a powerful and flexible way to query trace data, and it is designed to be easy to use and understand. You can use TraceQL to filter and aggregate trace data, and to create visualizations and alerts based on trace data.
34+
35+
<iframe title="vimeo-player" src="https://player.vimeo.com/video/796408188?h=b3e8e3257b" width="100%" height="360" frameborder="0" allowfullscreen></iframe>
36+
37+
[:bulb: Learn more about TraceQL query language](../../../reference/observability/tracing/traceql.md)
2838

2939
## Understanding trace data
3040

docs/reference/glossary.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,37 @@
22

33
## Observability
44

5-
Observability is a measure of how well internal states of a system can be inferred from knowledge of its external outputs. It is a measure of how well a system's internal states can be inferred from knowledge of its external outputs. In other words, observability is the ability to understand the internal state of a system by examining its outputs.
5+
Observability is the art of understanding how a system behaves by adding instrumentation such as logs, metrics, and traces.
66

77
### Metrics
88

9-
Metrics are a numerical measurement of something in your application. They are useful for understanding the performance of your application and is generally more scalable than logs both in terms of storage and querying since they are structured data.
9+
Metrics are a numerical measurement of something in your application such as the number of requests or the response time. Metrics are much better suited for for dashboards and alerts compared to logs.
1010

1111
### Prometheus
1212

13-
[Prometheus](https://prometheus.io/) is a time-series database that is used to store metrics. It is a very powerful tool that can be used to create alerts and dashboards. Prometheus is used by many open source projects and is the de facto standard for metrics in the cloud native world.
13+
[Prometheus](https://prometheus.io/) is a time-series database that is used to store and query metrics from Grafana.
1414

1515
### Alertmanager
1616

17-
[Alertmanager](https://prometheus.io/docs/alerting/alertmanager/) is a component of Prometheus that is used to create and manage alerts. It can send alerts to various different channels like email, Slack, PagerDuty, etc.
17+
[Alertmanager](https://prometheus.io/docs/alerting/alertmanager/) is a component of Prometheus that is used to create and manage Slack alerts based on the metrics collected by Prometheus.
1818

1919
### Grafana
2020

21-
[Grafana](https://grafana.com/) is a tool for creating dashboards and visualizing data. It is often used in combination with Prometheus to create dashboards and alerts.
21+
[Grafana](https://grafana.com/) is a tool for creating application dashboards and visualizing data such as metrics, traces, and logs in a user-friendly way.
2222

2323
### Traces
2424

25-
Traces are a record of the path a request takes through your application. They are useful for understanding how a request is processed in your application.
25+
Traces are a record of the path a request takes through your application. They are useful for understanding how a request is processed across multiple internal and external services.
2626

2727
### Span
2828

29-
A span represents a single unit of work in a trace, like a SQL query or an HTTP call to an external service.
29+
A span represents a single unit of work in a Trace, like a SQL query or an HTTP call to an API.
3030

3131
### Context
3232

3333
Each Span carries a Context that includes metadata about the trace (like a unique trace identifier and span identifier) and any other data you choose to include. This context is propagated across process boundaries, allowing all the work that's part of a single trace to be linked together, even if it spans multiple services.
3434

35-
### Grafa Tempo
35+
### Grafana Tempo
3636

3737
[Grafana Tempo](https://grafana.com/oss/tempo/) is an open-source, easy-to-use, high-scale, and cost-effective distributed tracing backend that stores and queries traces in a way that is easy to understand and use. It is fully integrated with Grafana, allowing you to visualize and query traces in the same interface as your metrics, and logs.
3838

@@ -44,7 +44,7 @@ Each Span carries a Context that includes metadata about the trace (like a uniqu
4444

4545
Logs are a record of what has happened in your application. They are useful for debugging, but due to their unstructured format they generally do not scale very well.
4646

47-
### Kiibana
47+
### Kibana
4848

4949
[Kibana](https://www.elastic.co/kibana) is a tool for visualizing logs. It is often used in combination with Elasticsearch to create dashboards and alerts.
5050

docs/reference/observability/logs/logql.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ tags: [reference, loki]
44
---
55
# LogQL Reference
66

7-
[LogQL][logql] is the query language used in Grafana Loki to query logs. It is a powerful query language that allows you to filter, aggregate, and search for logs and should be familiar to anyone who has used SQL or [PromQL](../metrics/promql.md).
7+
LogQL is the query language used in Grafana Loki to query logs. It is a powerful query language that allows you to filter, aggregate, and search for logs and should be familiar to anyone who has used SQL or [PromQL](../metrics/promql.md).
88

99
Where LogQL differs from PromQL is it's trailing pipeline syntax, or log pipeline. A log pipeline is a set of stage expressions that are chained together and applied to the selected log streams. Each expression can filter out, parse, or mutate log lines and their respective labels.
1010

11-
[logql]: https://grafana.com/docs/loki/latest/query/
12-
1311
## Syntax
1412

1513
A LogQL query is composed by two main parts: the **stream selector** (the query) and the **log pipeline** (the transformation).

docs/reference/observability/tracing/traceql.md

+87-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,90 @@ tags: [reference, tempo]
44
---
55
# TraceQL Reference
66

7-
* https://grafana.com/docs/loki/latest/query/
7+
TraceQL is the query language used in Grafana Tempo to query traces. It is a powerful query language that allows you to filter, aggregate, and search for traces and should be familiar to anyone who has used SQL or [PromQL](../metrics/promql.md).
8+
9+
Where TraceQL differs from PromQL is it's trailing pipeline syntax, or trace pipeline. A trace pipeline is a set of stage expressions that are chained together and applied to the selected trace data. Each expression can filter out, parse, or mutate trace spans and their respective labels.
10+
11+
## Syntax
12+
13+
A TraceQL query is composed by two main parts: the **trace span selector(s)** (the query) and the **trace pipeline** (aggregations).
14+
15+
```traceql
16+
{label="value"} | stage1 | stage2 | stage3
17+
```
18+
19+
### Trace Span Selector
20+
21+
The trace span selector is used to select spans based on their attributes. It is a set of key-value pairs that are used to filter spans.
22+
23+
Some span metadata are intrinsic to the span, such as `name`, `status`, `duration`, and `kind`, while others (attributes and resources) are user-defined, such as `service.name`, `db.operation`, and `http.status_code`.
24+
25+
```traceql
26+
{ span.http.status_code >= 200 && span.http.status_code < 300 }
27+
```
28+
29+
#### Comparison Operators
30+
31+
Similar to PromQL, TraceQL supports a set of operators for comparing span attributes and values. One notable difference is type coercion, where the type of the attribute is inferred from the value being compared.
32+
33+
- `=` - Equality
34+
- `!=` - Inequality
35+
- `>` - Greater than
36+
- `>=` - Greater than or equal to
37+
- `<` - Less than
38+
- `<=` - Less than or equal to
39+
- `=~` - Regular expression
40+
- `!~` - Negated regular expression
41+
42+
#### Combining spansets
43+
44+
Since a trace can be composed of multiple spans, multiple selectors can be used together to filter spans based on different attributes.
45+
46+
TraceQL supports two types of combining spansets: logical (`&&` and `||`) and structural relations (`>`, `>>`, `<<` `<`, and `~`).
47+
48+
##### Logical
49+
50+
The logical operators `&&` and `||` are used to combine spansets based on their attributes.
51+
52+
```traceql
53+
{ resource.service.name="server" } && { resource.service.name="client" }
54+
```
55+
56+
The above query will return traces where a span with the service name `server` and a differ3ent span with the service name `client` are present.
57+
58+
##### Structural
59+
60+
Structural relations are used to filter spans based on their structural relationships. The structural relations are:
61+
62+
- `>` - Direct parent of
63+
- `>>` - Ancestor of
64+
- `<<` - Descendant of
65+
- `<` - Direct child of
66+
- `~` - Sibling of
67+
68+
For example, to find a trace where a specific HTTP request interacted with a particular kafka topic, you could use the following query:
69+
70+
```traceql
71+
{ span.http.url = "/path/of/api" } >> { span.messaging.destination.name = "my-team.some-topic" }
72+
```
73+
74+
### Trace Pipeline Aggregations
75+
76+
To further refine the selected spans, a trace pipeline can be used to apply a set of aggregation functions on the selected spans.
77+
78+
- `count` - The count of spans in the spanset.
79+
- `avg` - The average of a given numeric attribute or intrinsic for a spanset.
80+
- `max` - The max value of a given numeric attribute or intrinsic for a spanset.
81+
- `min` - The min value of a given numeric attribute or intrinsic for a spanset.
82+
- `sum` - The sum value of a given numeric attribute or intrinsic for a spanset.
83+
84+
We can use the `count()` function to count the number of spans in the selected traces. In the following example, we select traces that contains more then 3 database SELECT operations:
85+
86+
```traceql
87+
{span.db.operation="SELECT"} | count() > 3
88+
```
89+
90+
## Reference
91+
92+
- [TraceQL query documentation](https://grafana.com/docs/tempo/latest/traceql/)
93+
- [Get to know TraceQL](https://grafana.com/blog/2023/02/07/get-to-know-traceql-a-powerful-new-query-language-for-distributed-tracing/)

0 commit comments

Comments
 (0)