Skip to content

Commit 8871d86

Browse files
Clarify metric view measurement processing (open-telemetry#3842)
1 parent c0016a0 commit 8871d86

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

specification/metrics/sdk.md

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,15 @@ made with an Instrument:
380380
according to the [MetricReader](#metricreader) instance's
381381
`aggregation` property.
382382
* If the `MeterProvider` has one or more `View`(s) registered:
383-
* For each View, if the Instrument could match the instrument selection
384-
criteria:
385-
* Try to apply the View's stream configuration. If applying the View
386-
results in [conflicting metric
387-
identities](./data-model.md#opentelemetry-protocol-data-model-producer-recommendations)
383+
* If the Instrument could match the instrument selection criteria, for each
384+
View:
385+
* Try to apply the View's stream configuration independently of any other
386+
Views registered for the same matching Instrument (i.e. Views are not
387+
merged). This may result in [conflicting metric identities](./data-model.md#opentelemetry-protocol-data-model-producer-recommendations)
388+
even if stream configurations specify non-overlapping properties (e.g.
389+
one View setting `aggregation` and another View setting `attribute_keys`,
390+
both leaving the stream `name` as the default configured by the
391+
Instrument). If applying the View results in conflicting metric identities
388392
the implementation SHOULD apply the View and emit a warning. If it is not
389393
possible to apply the View without producing semantic errors (e.g. the
390394
View sets an asynchronous instrument to use the [Explicit bucket
@@ -445,15 +449,26 @@ meter_provider
445449
```
446450

447451
```python
448-
# Counter X will be exported as delta sum
449-
# Histogram Y and Gauge Z will be exported with 2 attributes (a and b)
452+
# Counter X will be exported as a delta sum and the default attributes
453+
# Counter X, Histogram Y, and Gauge Z will be exported with 2 attributes (a and b)
454+
# A warning will be emitted for conflicting metric identities on Counter X (as two Views matching that Instrument
455+
# are configured with the same default name X) and streams from both views will be exported
450456
meter_provider
451457
.add_view("X", aggregation=SumAggregation())
452-
.add_view("*", attribute_keys=["a", "b"])
458+
.add_view("*", attribute_keys=["a", "b"]) # wildcard view matches everything, including X
453459
.add_metric_reader(PeriodicExportingMetricReader(ConsoleExporter()),
454460
temporality=lambda kind: Delta if kind in [Counter, AsyncCounter, Histogram] else Cumulative)
455461
```
456462

463+
```python
464+
# Only Counter X will be exported, with the default configuration (match-all drop aggregation does not result in
465+
# conflicting metric identities)
466+
meter_provider
467+
.add_view("X")
468+
.add_view("*", aggregation=DropAggregation()) # a wildcard view to disable all instruments
469+
.add_metric_reader(PeriodicExportingMetricReader(ConsoleExporter()))
470+
```
471+
457472
### Aggregation
458473

459474
An `Aggregation`, as configured via the [View](./sdk.md#view),

0 commit comments

Comments
 (0)