Skip to content

Commit 46dad34

Browse files
[release-v2.5] [DOC] Add missing doc for metrics (#3737)
* [DOC] Add missing doc for metrics (#3726) * Add missing doc for metrics * Update docs/sources/tempo/operations/traceql-metrics.md * Apply suggestions from code review Co-authored-by: Martin Disibio <[email protected]> * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Martin Disibio <[email protected]> --------- Co-authored-by: Martin Disibio <[email protected]> (cherry picked from commit 56a0b8c) * Update docs/sources/tempo/operations/traceql-metrics.md --------- Co-authored-by: Kim Nylander <[email protected]>
1 parent 88198db commit 46dad34

File tree

2 files changed

+105
-31
lines changed

2 files changed

+105
-31
lines changed

docs/sources/tempo/operations/traceql-metrics.md

+10-31
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,41 @@
11
---
22
aliases: []
3-
title: TraceQL metrics
4-
menuTitle: TraceQL metrics
5-
description: Learn about using TraceQL metrics.
3+
title: Configure TraceQL metrics
4+
menuTitle: Configure TraceQL metrics
5+
description: Learn about configuring TraceQL metrics.
66
weight: 550
77
keywords:
88
- Prometheus
99
- TraceQL
1010
- TraceQL metrics
1111
---
1212

13-
# TraceQL metrics
13+
# Configure TraceQL metrics
1414

1515
{{< docs/experimental product="TraceQL metrics" >}}
1616

17-
Tempo 2.4 introduces the addition of metrics queries to the TraceQL language as an experimental feature.
17+
TraceQL language provides metrics queries as an experimental feature.
1818
Metric queries extend trace queries by applying a function to trace query results.
1919
This powerful feature creates metrics from traces, much in the same way that LogQL metric queries create metrics from logs.
20-
Initially, only `count_over_time` and `rate` are supported.
2120

22-
For example:
23-
```
24-
{ resource.service.name = "foo" && status = error } | rate()
25-
```
26-
27-
In this case, we are calculating the rate of the erroring spans coming from the service `foo`. Rate is a `spans/sec` quantity.
28-
Combined with the `by()` operator, this can be even more powerful!
29-
30-
```
31-
{ resource.service.name = "foo" && status = error } | rate() by (span.http.route)
32-
```
21+
For more information about available queries, refer to [TraceQL metrics queries]({{< relref "../traceql/metrics-queries" >}}).
3322

34-
Now, we are still rating the erroring spans in the service `foo` but the metrics have been broken
35-
down by HTTP endpoint. This might let you determine that `/api/sad` had a higher rate of erroring
36-
spans than `/api/happy`, for example.
37-
38-
## Enable and use TraceQL metrics
39-
40-
You can use the TraceQL metrics in Grafana with any existing or new Tempo data source.
41-
This capability is available in Grafana Cloud and Grafana (10.4 and newer).
42-
43-
![Metrics visualization in Grafana](/media/docs/tempo/metrics-explore-sample-2.4.png)
44-
45-
### Before you begin
23+
## Before you begin
4624

4725
To use the metrics generated from traces, you need to:
4826

4927
* Set the `local-blocks` processor to active in your `metrics-generator` configuration
5028
* Configure a Tempo data source configured in Grafana or Grafana Cloud
5129
* Access Grafana Cloud or Grafana 10.4
5230

53-
### Configure the `local-blocks` processor
31+
## Configure the `local-blocks` processor
5432

5533
Once the `local-blocks` processor is enabled in your `metrics-generator`
5634
configuration, you can configure it using the following block to make sure
5735
it records all spans for TraceQL metrics.
5836

5937
Here is an example configuration:
38+
6039
```yaml
6140
metrics_generator:
6241
processor:
@@ -70,7 +49,7 @@ Here is an example configuration:
7049
7150
Refer to the [metrics-generator configuration]({{< relref "../configuration#metrics-generator" >}}) documentation for more information.
7251
73-
### Evaluate query timeouts
52+
## Evaluate query timeouts
7453
7554
Because of their expensive nature, these queries can take a long time to run in different systems.
7655
As such, consider increasing the timeouts in various places of
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
title: TraceQL metrics queries
3+
menuTitle: TraceQL metrics queries
4+
description: Learn about TraceQL metrics queries
5+
weight: 600
6+
keywords:
7+
- metrics query
8+
- TraceQL metrics
9+
---
10+
11+
# TraceQL metrics queries
12+
13+
{{< docs/experimental product="TraceQL metrics" >}}
14+
15+
TraceQL metrics is an experimental feature in Grafana Tempo that creates metrics from traces.
16+
17+
Metric queries extend trace queries by applying a function to trace query results.
18+
This powerful feature allows for adhoc aggregation of any existing TraceQL query by any dimension available in your traces, much in the same way that LogQL metric queries create metrics from logs.
19+
20+
Traces are a unique observability signal that contain causal relationships between the components in your system.
21+
Do you want to know how many database calls across all systems are downstream of your application?
22+
What services beneath a given endpoint are currently failing?
23+
What services beneath an endpoint are currently slow? TraceQL metrics can answer all these questions by parsing your traces in aggregate.
24+
25+
![Metrics visualization in Grafana](/media/docs/tempo/metrics-explore-sample-2.4.png)
26+
27+
## Enable and use TraceQL metrics
28+
29+
You can use the TraceQL metrics in Grafana with any existing or new Tempo data source.
30+
This capability is available in Grafana Cloud and Grafana (10.4 and newer).
31+
32+
To enable TraceQL metrics, refer to [Configure TraceQL metrics](https://grafana.com/docs/tempo/latest/operations/traceql-metrics/) for more information.
33+
34+
## Functions
35+
36+
TraceQL supports include `rate`, `count_over_time`, `quantile_over_time`, and `histogram_over_time` functions.
37+
These functions can be added as an operator at the end of any TraceQL query.
38+
39+
`rate`
40+
: calculates the number of matching spans per second
41+
42+
`count_over_time`
43+
: counts the number of matching spans per time interval (see the `step` API parameter)
44+
45+
`quantile_over_time`
46+
: the quantile of the values in the specified interval
47+
48+
`histogram_over_time`
49+
: evaluate frequency distribution over time. Example: `histogram_over_time(duration) by (span.foo)`
50+
51+
## The `rate` function
52+
53+
The following query shows the rate of errors by service and span name.
54+
55+
```
56+
{ status = error } | rate() by (resource.service.name, name)
57+
```
58+
59+
This example calculates the rate of the erroring spans coming from the service `foo`. Rate is a `spans/sec` quantity.
60+
61+
```
62+
{ resource.service.name = "foo" && status = error } | rate()
63+
```
64+
65+
Combined with the `by()` operator, this can be even more powerful.
66+
67+
```
68+
{ resource.service.name = "foo" && status = error } | rate() by (span.http.route)
69+
```
70+
71+
This example still rates the erroring spans in the service `foo` but the metrics have been broken
72+
down by HTTP route. This might let you determine that `/api/sad` had a higher rate of erroring
73+
spans than `/api/happy`, for example.
74+
75+
### The `quantile_over_time` and `histogram_over_time` functions
76+
77+
The `quantile_over_time()` and `histogram_over_time()` functions let you aggregate numerical values, such as the all important span duration. Notice that you can specify multiple quantiles in the same query.
78+
79+
```
80+
{ name = "GET /:endpoint" } | quantile_over_time(duration, .99, .9, .5)`
81+
```
82+
83+
You can group by any span or resource attribute.
84+
85+
```
86+
{ name = "GET /:endpoint" } | quantile_over_time(duration, .99) by (span.http.target)
87+
```
88+
89+
Quantiles aren't limited to span duration.
90+
Any numerical attribute on the span is fair game.
91+
To demonstrate this flexibility, consider this nonsensical quantile on `span.http.status_code`:
92+
93+
```
94+
{ name = "GET /:endpoint" } | quantile_over_time(span.http.status_code, .99, .9, .5)
95+
```

0 commit comments

Comments
 (0)