Skip to content

Commit 580704e

Browse files
authored
Prometheus exporters omit empty resources and scopes without attributes (open-telemetry#3660)
1 parent 0675f3e commit 580704e

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ release.
8989
([#3471](https://github.com/open-telemetry/opentelemetry-specification/pull/3471))
9090
- Prometheus: Allow changing metric names by default when translating from Prometheus to OpenTelemetry.
9191
([#3679](https://github.com/open-telemetry/opentelemetry-specification/pull/3679))
92+
- Prometheus exporters omit empty resources and scopes without attributes.
93+
([#3660](https://github.com/open-telemetry/opentelemetry-specification/pull/3660))
9294

9395
### SDK Configuration
9496

specification/compatibility/prometheus_and_openmetrics.md

+24-18
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,13 @@ exemplar as attributes.
139139

140140
### Instrumentation Scope
141141

142-
Each `otel_scope_info` metric point present in a batch of metrics
143-
SHOULD be dropped from the incoming scrape, and converted to an instrumentation
144-
scope. The `otel_scope_name` and `otel_scope_version` labels, if present, MUST
145-
be converted to the Name and Version of the Instrumentation Scope. Additional
146-
labels MUST be added as scope attributes, with keys and values unaltered. Other
147-
metrics in the batch which have `otel_scope_name` and `otel_scope_version`
148-
labels that match an instrumentation scope MUST be placed within the matching
149-
instrumentation scope, and MUST remove those labels. For example, the
150-
OpenMetrics metrics:
142+
The `otel_scope_name` and `otel_scope_version` lables, if present, SHOULD be
143+
dropped from all metric points and used as the Instrumentation Scope name and
144+
version respectively. All `otel_scope_info` metrics present in a batch
145+
of metrics SHOULD be dropped from the incoming scrape. Labels on
146+
`otel_scope_info` metric points other than `otel_scope_name` and
147+
`otel_scope_version`, MUST be added as scope attributes to the scope with the
148+
matching name and version. For example, the OpenMetrics metrics:
151149

152150
```
153151
# TYPE otel_scope_info info
@@ -174,9 +172,10 @@ scope_metrics:
174172
- value: 1
175173
```
176174
177-
Metrics which are not found to be associated with an instrumentation scope MUST
178-
all be placed within an empty instrumentation scope, and MUST not have any labels
179-
removed.
175+
Metrics which do not have an `otel_scope_name` or `otel_scope_version` label
176+
MUST be assigned an instrumentation scope identifying the entity performing
177+
the translation from Prometheus to OpenTelemetry (e.g. the collector's
178+
prometheus receiver).
180179

181180
### Resource Attributes
182181

@@ -255,11 +254,11 @@ It also dictates type-specific conversion rules listed below.
255254
### Instrumentation Scope
256255

257256
Prometheus exporters SHOULD generate an [Info](https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#info)-typed
258-
metric named `otel_scope_info`. If present, Instrumentation Scope
259-
`name` and `version` MUST be added as `otel_scope_name` and
260-
`otel_scope_version` labels. Scope attributes MUST also be added as labels
261-
following the rules described in the [`Metric Attributes`](#metric-attributes)
262-
section below.
257+
metric named `otel_scope_info` for each Instrumentation Scope with non-empty
258+
scope attributes. If present, Instrumentation Scope `name` and `version` MUST
259+
be added as `otel_scope_name` and `otel_scope_version` labels. Scope attributes
260+
MUST also be added as labels following the rules described in the
261+
[`Metric Attributes`](#metric-attributes) section below.
263262

264263
Prometheus exporters MUST add the scope name as the `otel_scope_name` label and
265264
the scope version as the `otel_scope_version` label on all metric points by
@@ -384,7 +383,14 @@ OpenMetrics exemplar unless they would exceed the OpenMetrics
384383

385384
### Resource Attributes
386385

387-
In SDK Prometheus (pull) exporters, resource attributes SHOULD be converted to a single [`target_info` metric](https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#supporting-target-metadata-in-both-push-based-and-pull-based-systems); otherwise, they MUST be dropped, and MUST NOT be attached as labels to other metric families. The target_info metric MUST be an info-typed metric whose labels MUST include the resource attributes, and MUST NOT include any other labels. There MUST be at most one target_info metric exposed on an SDK Prometheus endpoint.
386+
In SDK Prometheus (pull) exporters, resource attributes SHOULD be converted to
387+
a single [`target_info` metric](https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#supporting-target-metadata-in-both-push-based-and-pull-based-systems)
388+
if the resource is not [empty](../resource/sdk.md#the-empty-resource);
389+
otherwise, they MUST be dropped, and MUST NOT be attached as labels to other
390+
metric families. The target_info metric MUST be an info-typed metric whose
391+
labels MUST include the resource attributes, and MUST NOT include any other
392+
labels. There MUST be at most one target_info metric exposed on an SDK
393+
Prometheus endpoint.
388394

389395
In the Collector's Prometheus pull and push (remote-write) exporters, it is
390396
possible for metrics from multiple targets to be sent together, so targets must

0 commit comments

Comments
 (0)