Skip to content

Commit a26b547

Browse files
pellaredjade-guiton-ddcarlosalberto
authored
prometheus: handle schema URL and scope attributes (#4505)
Fixes #4223 Prototypes: - open-telemetry/opentelemetry-go#5947 - open-telemetry/opentelemetry-go#6770 - open-telemetry/opentelemetry-java#7356 - open-telemetry/opentelemetry-collector-contrib#40060 - open-telemetry/opentelemetry-collector-contrib#40004 ## Changes Currently (before this PR) [Prometheus and OpenMetrics Compatibility](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/compatibility/prometheus_and_openmetrics.md) assumes that only scope name and scope version are identifying. However, with #4161 this is no longer true. Therefore, this PR updates the Prometheus and OpenMetrics Compatibility specification to add the scope name, version, schema URL, scope attributes to all metrics. This also removes the `otel_scope_info` as it looks that it won't be useful. See: #4223 (comment). This change important for Collector open-telemetry/opentelemetry-go#5846 (comment). It is also is necessary towards stabilization of OTel-Prom/OpenMetrics compatibility) and the Prometheus exporter. _Initially, I thought about [splitting it into a few PRs](#4223 (comment)). However, it looks like doing it in one PR would be a more complete approach (also there are not that many changes)._ --------- Co-authored-by: Jade Guiton <[email protected]> Co-authored-by: Carlos Alberto Cortez <[email protected]>
1 parent bea81b1 commit a26b547

File tree

4 files changed

+28
-29
lines changed

4 files changed

+28
-29
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ release.
1313

1414
### Metrics
1515

16+
- Prometheus receiver can expect `otel_scope_schema_url` and `otel_scope_[attribute]` labels on all metrics.
17+
([#4505](https://github.com/open-telemetry/opentelemetry-specification/pull/4505))
18+
- Prometheus receiver no longer expects `otel_scope_info` metric.
19+
([#4505](https://github.com/open-telemetry/opentelemetry-specification/pull/4505))
20+
- Prometheus exporter adds `otel_scope_schema_url` and `otel_scope_[attribute]` labels on all metrics.
21+
([#4505](https://github.com/open-telemetry/opentelemetry-specification/pull/4505))
22+
- Prometheus exporter no longer exports `otel_scope_info` metric.
23+
([#4505](https://github.com/open-telemetry/opentelemetry-specification/pull/4505))
24+
1625
### Logs
1726

1827
### Baggage

spec-compliance-matrix.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,8 @@ Disclaimer: Declarative configuration is currently in Development status - work
355355
| [HELP Metadata](specification/compatibility/prometheus_and_openmetrics.md#metric-metadata-1) | | + | + | + | + | - | - | - | + | + | + | + |
356356
| [TYPE Metadata](specification/compatibility/prometheus_and_openmetrics.md#metric-metadata-1) | | + | + | + | + | - | - | - | + | + | + | + |
357357
| [otel_scope_name and otel_scope_version labels on all Metrics](specification/compatibility/prometheus_and_openmetrics.md#instrumentation-scope-1) | | + | + | - | - | - | - | - | + | - | - | - |
358-
| [otel_scope_info metric](specification/compatibility/prometheus_and_openmetrics.md#instrumentation-scope-1) | X | + | + | - | - | - | - | - | + | - | - | - |
359-
| [otel_scope_info and labels can be disabled](specification/compatibility/prometheus_and_openmetrics.md#instrumentation-scope-1) | X | + | - | - | - | - | - | - | + | - | - | - |
358+
| [otel_scope_[attribute] labels on all Metrics](specification/compatibility/prometheus_and_openmetrics.md#instrumentation-scope-1) | | + | - | - | - | - | - | - | - | - | - | - |
359+
| [otel_scope labels can be disabled](specification/compatibility/prometheus_and_openmetrics.md#instrumentation-scope-1) | X | + | - | - | - | - | - | - | + | - | - | - |
360360
| [Gauges become Prometheus Gauges](specification/compatibility/prometheus_and_openmetrics.md#gauges-1) | | + | + | + | + | - | - | - | + | + | + | - |
361361
| [Cumulative Monotonic Sums become Prometheus Counters](specification/compatibility/prometheus_and_openmetrics.md#sums) | | + | + | + | + | - | - | - | + | + | + | + |
362362
| [Prometheus Counters have _total suffix by default](specification/compatibility/prometheus_and_openmetrics.md#sums) | | + | + | + | + | - | - | - | + | - | - | - |

specification/compatibility/prometheus_and_openmetrics.md

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,14 @@ exemplar as attributes.
166166

167167
### Instrumentation Scope
168168

169-
The `otel_scope_name` and `otel_scope_version` lables, if present, SHOULD be
170-
dropped from all metric points and used as the Instrumentation Scope name and
171-
version respectively. All `otel_scope_info` metrics present in a batch
172-
of metrics SHOULD be dropped from the incoming scrape. Labels on
173-
`otel_scope_info` metric points other than `otel_scope_name` and
174-
`otel_scope_version`, MUST be added as scope attributes to the scope with the
175-
matching name and version. For example, the OpenMetrics text-formatted metrics:
169+
Labels with `otel_scope_` prefix MUST be dropped from all metric points
170+
and used as the Instrumentation Scope name (`otel_scope_name`),
171+
version (`otel_scope_version`), schema URL (`otel_scope_schema_url`),
172+
attributes (`otel_scope_[attribute]`).
176173

177174
```
178-
# TYPE otel_scope_info info
179-
otel_scope_info{otel_scope_name="go.opentelemetry.io.contrib.instrumentation.net.http.otelhttp",otel_scope_version="v0.24.0",library_mascot="bear"} 1
180175
# TYPE http_server_duration counter
181-
http_server_duration{otel_scope_name="go.opentelemetry.io.contrib.instrumentation.net.http.otelhttp",otel_scope_version="v0.24.0"...} 1
176+
http_server_duration{otel_scope_name="go.opentelemetry.io.contrib.instrumentation.net.http.otelhttp",otel_scope_schema_url="https://opentelemetry.io/schemas/1.31.0",otel_scope_version="v0.24.0",otel_scope_library_mascot="gopher"...} 1
182177
```
183178

184179
becomes:
@@ -190,7 +185,8 @@ scope_metrics:
190185
name: go.opentelemetry.io.contrib.instrumentation.net.http.otelhttp
191186
version: v0.24.0
192187
attributes:
193-
library_mascot: bear
188+
library_mascot: gopher
189+
schema_url: https://opentelemetry.io/schemas/1.31.0
194190
metrics:
195191
- name: http_server_duration
196192
data:
@@ -199,7 +195,7 @@ scope_metrics:
199195
- value: 1
200196
```
201197
202-
Metrics which do not have an `otel_scope_name` or `otel_scope_version` label
198+
Metrics which do not have any label with `otel_scope_` prefix
203199
MUST be assigned an instrumentation scope identifying the entity performing
204200
the translation from Prometheus to OpenTelemetry (e.g. the collector's
205201
prometheus receiver).
@@ -280,19 +276,13 @@ It also dictates type-specific conversion rules listed below.
280276

281277
### Instrumentation Scope
282278

283-
Prometheus exporters SHOULD generate an [Info](https://github.com/prometheus/OpenMetrics/blob/v1.0.0/specification/OpenMetrics.md#info)-typed
284-
metric named `otel_scope_info` for each Instrumentation Scope with non-empty
285-
scope attributes. If present, Instrumentation Scope `name` and `version` MUST
286-
be added as `otel_scope_name` and `otel_scope_version` labels. Scope attributes
287-
MUST also be added as labels following the rules described in the
288-
[`Metric Attributes`](#metric-attributes) section below.
289-
290-
Prometheus exporters MUST add the scope name as the `otel_scope_name` label and
291-
the scope version as the `otel_scope_version` label on all metric points by
292-
default, based on the scope the original data point was nested in.
293-
294-
Prometheus exporters SHOULD provide a configuration option to disable the
295-
`otel_scope_info` metric and `otel_scope_` labels.
279+
Prometheus exporters MUST by default add
280+
the scope name as the `otel_scope_name` label,
281+
the scope version as the `otel_scope_version` label,
282+
the scope schema URL as the `otel_scope_schema_url` label,
283+
the scope attributes as labels with `otel_scope_` prefix and following the rules
284+
described in the [`Metric Attributes`](#metric-attributes) section below,
285+
on all metric points, based on the scope the original data point was nested in.
296286

297287
### Gauges
298288

specification/metrics/sdk_exporters/prometheus.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ or UNIT metadata. The option MAY be named `without_units`, and MUST be `false` b
6969
A Prometheus Exporter MAY support a configuration option to produce metrics without a [type suffix](../../compatibility/prometheus_and_openmetrics.md#metric-metadata).
7070
The option MAY be named `without_type_suffix`, and MUST be `false` by default.
7171

72-
A Prometheus Exporter MAY support a configuration option to produce metrics without a [scope info](../../compatibility/prometheus_and_openmetrics.md#instrumentation-scope-1)
73-
metric, or scope labels. The option MAY be named `without_scope_info`, and MUST be `false` by default.
72+
A Prometheus Exporter MAY support a configuration option to produce metrics without [scope labels](../../compatibility/prometheus_and_openmetrics.md#instrumentation-scope-1).
73+
The option MAY be named `without_scope_info`, and MUST be `false` by default.
7474

7575
A Prometheus Exporter MAY support a configuration option to produce metrics without a [target info](../../compatibility/prometheus_and_openmetrics.md#resource-attributes-1)
7676
metric. The option MAY be named `without_target_info`, and MUST be `false` by default.

0 commit comments

Comments
 (0)