Skip to content

Commit 1e726c6

Browse files
authored
Merge pull request #2512 from prometheus/arve/otlp-documentation
OTel guide: Add section on `target_info`
2 parents 4df1cb3 + 7e9f47e commit 1e726c6

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

content/docs/guides/opentelemetry.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,32 @@ otlp:
6767
- ...
6868
```
6969
70+
## Including resource attributes at query time
71+
72+
An alternative to promoting resource attributes, as described in the previous section, is to add labels from the `target_info` metric when querying.
73+
74+
This is conceptually known as a "join" query.
75+
An example of such a query can look like the following:
76+
77+
```promql
78+
rate(http_server_request_duration_seconds_count[2m])
79+
* on (job, instance) group_left (k8s_cluster_name)
80+
target_info
81+
```
82+
83+
What happens in this query is that the time series resulting from `rate(http_server_request_duration_seconds_count[2m])` are augmented with the `k8s_cluster_name` label from the `target_info` series that share the same `job` and `instance` labels.
84+
In other words, the `job` and `instance` labels are shared between `http_server_request_duration_seconds_count` and `target_info`, akin to SQL foreign keys.
85+
The `k8s_cluster_name` label, On the other hand, corresponds to the OTel resource attribute `k8s.cluster.name` (Prometheus converts dots to underscores).
86+
87+
So, what is the relation between the `target_info` metric and OTel resource attributes?
88+
When Prometheus processes an OTLP write request, and provided that contained resources include the attributes `service.instance.id` and/or `service.name`, Prometheus generates the info metric `target_info` for every (OTel) resource.
89+
It adds to each such `target_info` series the label `instance` with the value of the `service.instance.id` resource attribute, and the label `job` with the value of the `service.name` resource attribute.
90+
If the resource attribute `service.namespace` exists, it's prefixed to the `job` label value (i.e., `<service.namespace>/<service.name>`).
91+
The rest of the resource attributes are also added as labels to the `target_info` series, names converted to Prometheus format (e.g. dots converted to underscores).
92+
If a resource lacks both `service.instance.id` and `service.name` attributes, no corresponding `target_info` series is generated.
93+
94+
For each of a resource's OTel metrics, Prometheus converts it to a corresponding Prometheus time series, and (if `target_info` is generated) adds the right `instance` and `job` labels.
95+
7096
## UTF-8
7197

7298
The UTF-8 support for Prometheus is not ready yet so both the Prometheus Remote Write Exporter and the OTLP Ingestion endpoint still rely on the [Prometheus normalization translator package from OpenTelemetry](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/translator/prometheus).

0 commit comments

Comments
 (0)