Skip to content

Commit b54db79

Browse files
authored
Define MetricProducer as a third-party provider of metric data to MetricReaders (#2951)
1 parent a87fb8c commit b54db79

File tree

2 files changed

+90
-8
lines changed

2 files changed

+90
-8
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ release.
1313

1414
### Metrics
1515

16+
- Define Experimental MetricProducer as a third-party provider of metric data to MetricReaders.
17+
([#2951](https://github.com/open-telemetry/opentelemetry-specification/pull/2951))
18+
1619
### Logs
1720

1821
- Move `event.domain` from InstrumentationScope attributes to LogRecord

specification/metrics/sdk.md

+87-8
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ linkTitle: SDK
3737
* [Exemplar defaults](#exemplar-defaults)
3838
- [MetricReader](#metricreader)
3939
* [MetricReader operations](#metricreader-operations)
40+
+ [RegisterProducer(metricProducer)](#registerproducermetricproducer)
4041
+ [Collect](#collect)
4142
+ [Shutdown](#shutdown-1)
4243
* [Periodic exporting MetricReader](#periodic-exporting-metricreader)
@@ -47,6 +48,9 @@ linkTitle: SDK
4748
- [ForceFlush()](#forceflush)
4849
- [Shutdown()](#shutdown)
4950
* [Pull Metric Exporter](#pull-metric-exporter)
51+
- [MetricProducer](#metricproducer)
52+
* [Interface Definition](#interface-definition-1)
53+
+ [Produce() batch](#produce-batch)
5054
- [Defaults and configuration](#defaults-and-configuration)
5155
- [Numerical limits handling](#numerical-limits-handling)
5256
- [Compatibility requirements](#compatibility-requirements)
@@ -753,7 +757,9 @@ measurements using the equivalent of the following naive algorithm:
753757
common configurable aspects of the OpenTelemetry Metrics SDK and
754758
determines the following capabilities:
755759

756-
* Collecting metrics from the SDK on demand.
760+
* Registering [MetricProducer](#metricproducer)(s)
761+
* Collecting metrics from the SDK and any registered
762+
[MetricProducers](#metricproducer) on demand.
757763
* Handling the [ForceFlush](#forceflush) and [Shutdown](#shutdown) signals from
758764
the SDK.
759765

@@ -770,15 +776,20 @@ used with pull-based metrics collection. A common sub-class of
770776
`MetricReader`, the periodic exporting `MetricReader` SHOULD be provided
771777
to be used typically with push-based metrics collection.
772778

773-
The `MetricReader` MUST ensure that data points are output in the
774-
configured aggregation temporality for each instrument kind. For
775-
synchronous instruments being output with Cumulative temporality, this
776-
means converting [Delta to Cumulative](supplementary-guidelines.md#synchronous-example-cumulative-aggregation-temporality)
779+
The `MetricReader` MUST ensure that data points from OpenTelemetry
780+
[instruments](./api.md#instrument) are output in the configured aggregation
781+
temporality for each instrument kind. For synchronous instruments being output
782+
with Cumulative temporality, this means converting [Delta to Cumulative](supplementary-guidelines.md#synchronous-example-cumulative-aggregation-temporality)
777783
aggregation temporality. For asynchronous instruments being output
778784
with Delta temporality, this means converting [Cumulative to
779785
Delta](supplementary-guidelines.md#asynchronous-example-delta-temporality) aggregation
780786
temporality.
781787

788+
The `MetricReader` is not required to ensure data points from a non-SDK
789+
[MetricProducer](#metricproducer) are output in the configured aggregation
790+
temporality, as these data points are not collected using OpenTelemetry
791+
instruments.
792+
782793
The SDK MUST support multiple `MetricReader` instances to be registered on the
783794
same `MeterProvider`, and the [MetricReader.Collect](#collect) invocation on one
784795
`MetricReader` instance SHOULD NOT introduce side-effects to other `MetricReader`
@@ -813,11 +824,27 @@ functions.
813824

814825
### MetricReader operations
815826

827+
#### RegisterProducer(metricProducer)
828+
829+
**Status**: [Experimental](../document-status.md)
830+
831+
RegisterProducer causes the MetricReader to use the provided
832+
[MetricProducer](#metricproducer) as a source of aggregated metric data in
833+
subsequent invocations of Collect. RegisterProducer is expected to be called
834+
during initialization, but MAY be invoked later. Multiple registrations
835+
of the same MetricProducer MAY result in duplicate metric data being collected.
836+
837+
If the [MeterProvider](#meterprovider) is an instance of
838+
[MetricProducer](#metricproducer), this MAY be used to register the
839+
MeterProvider, but MUST NOT allow multiple [MeterProviders](#meterprovider)
840+
to be registered with the same MetricReader.
841+
816842
#### Collect
817843

818-
Collects the metrics from the SDK. If there are [asynchronous
819-
Instruments](./api.md#asynchronous-instrument-api) involved, their callback
820-
functions will be triggered.
844+
Collects the metrics from the SDK and any registered
845+
[MetricProducers](#metricproducer). If there are
846+
[asynchronous SDK Instruments](./api.md#asynchronous-instrument-api) involved,
847+
their callback functions will be triggered.
821848

822849
`Collect` SHOULD provide a way to let the caller know whether it succeeded,
823850
failed or timed out. When the `Collect` operation fails or times out on
@@ -1087,6 +1114,58 @@ modeled to interact with other components in the SDK:
10871114
+-----------------------------+
10881115
```
10891116

1117+
## MetricProducer
1118+
1119+
**Status**: [Experimental](../document-status.md)
1120+
1121+
`MetricProducer` defines the interface which bridges to third-party metric
1122+
sources MUST implement so they can be plugged into an OpenTelemetry
1123+
[MetricReader](#metricreader) as a source of aggregated metric data. The SDK's
1124+
in-memory state MAY implement the `MetricProducer` interface for convenience.
1125+
1126+
`MetricProducer` implementations SHOULD accept configuration for the
1127+
`AggregationTemporality` of produced metrics. SDK authors MAY provide utility
1128+
libraries to facilitate conversion between delta and cumulative temporalities.
1129+
1130+
If the batch of [Metric points](./data-model.md#metric-points) returned by
1131+
`Produce()` includes a [Resource](../resource/sdk.md), the `MetricProducer` MUST
1132+
accept configuration for the [Resource](../resource/sdk.md).
1133+
1134+
```text
1135+
+-----------------+ +--------------+
1136+
| | Metrics... | |
1137+
| In-memory state +------------> MetricReader |
1138+
| | | |
1139+
+-----------------+ | |
1140+
| |
1141+
+-----------------+ | |
1142+
| | Metrics... | |
1143+
| MetricProducer +------------> |
1144+
| | | |
1145+
+-----------------+ +--------------+
1146+
```
1147+
1148+
### Interface Definition
1149+
1150+
A `MetricProducer` MUST support the following functions:
1151+
1152+
#### Produce() batch
1153+
1154+
`Produce` provides metrics from the MetricProducer to the caller. `Produce`
1155+
MUST return a batch of [Metric points](./data-model.md#metric-points).
1156+
`Produce` does not have any required parameters, however, [OpenTelemetry
1157+
SDK](../overview.md#sdk) authors MAY choose to add parameters (e.g. timeout).
1158+
1159+
`Produce` SHOULD provide a way to let the caller know whether it succeeded,
1160+
failed or timed out. When the `Produce` operation fails, the `MetricProducer`
1161+
MAY return successfully collected results and a failed reasons list to the
1162+
caller.
1163+
1164+
If a batch of [Metric points](./data-model.md#metric-points) can include
1165+
[`InstrumentationScope`](../glossary.md#instrumentation-scope) information,
1166+
`Produce` SHOULD include a single InstrumentationScope which identifies the
1167+
`MetricProducer`.
1168+
10901169
## Defaults and configuration
10911170

10921171
The SDK MUST provide configuration according to the [SDK environment

0 commit comments

Comments
 (0)