@@ -37,6 +37,7 @@ linkTitle: SDK
37
37
* [ Exemplar defaults] ( #exemplar-defaults )
38
38
- [ MetricReader] ( #metricreader )
39
39
* [ MetricReader operations] ( #metricreader-operations )
40
+ + [ RegisterProducer(metricProducer)] ( #registerproducermetricproducer )
40
41
+ [ Collect] ( #collect )
41
42
+ [ Shutdown] ( #shutdown-1 )
42
43
* [ Periodic exporting MetricReader] ( #periodic-exporting-metricreader )
@@ -47,6 +48,9 @@ linkTitle: SDK
47
48
- [ ForceFlush()] ( #forceflush )
48
49
- [ Shutdown()] ( #shutdown )
49
50
* [ Pull Metric Exporter] ( #pull-metric-exporter )
51
+ - [ MetricProducer] ( #metricproducer )
52
+ * [ Interface Definition] ( #interface-definition-1 )
53
+ + [ Produce() batch] ( #produce-batch )
50
54
- [ Defaults and configuration] ( #defaults-and-configuration )
51
55
- [ Numerical limits handling] ( #numerical-limits-handling )
52
56
- [ Compatibility requirements] ( #compatibility-requirements )
@@ -753,7 +757,9 @@ measurements using the equivalent of the following naive algorithm:
753
757
common configurable aspects of the OpenTelemetry Metrics SDK and
754
758
determines the following capabilities:
755
759
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.
757
763
* Handling the [ ForceFlush] ( #forceflush ) and [ Shutdown] ( #shutdown ) signals from
758
764
the SDK.
759
765
@@ -770,15 +776,20 @@ used with pull-based metrics collection. A common sub-class of
770
776
` MetricReader ` , the periodic exporting ` MetricReader ` SHOULD be provided
771
777
to be used typically with push-based metrics collection.
772
778
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 )
777
783
aggregation temporality. For asynchronous instruments being output
778
784
with Delta temporality, this means converting [ Cumulative to
779
785
Delta] ( supplementary-guidelines.md#asynchronous-example-delta-temporality ) aggregation
780
786
temporality.
781
787
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
+
782
793
The SDK MUST support multiple ` MetricReader ` instances to be registered on the
783
794
same ` MeterProvider ` , and the [ MetricReader.Collect] ( #collect ) invocation on one
784
795
` MetricReader ` instance SHOULD NOT introduce side-effects to other ` MetricReader `
@@ -813,11 +824,27 @@ functions.
813
824
814
825
### MetricReader operations
815
826
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
+
816
842
#### Collect
817
843
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.
821
848
822
849
` Collect ` SHOULD provide a way to let the caller know whether it succeeded,
823
850
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:
1087
1114
+-----------------------------+
1088
1115
```
1089
1116
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
+
1090
1169
## Defaults and configuration
1091
1170
1092
1171
The SDK MUST provide configuration according to the [ SDK environment
0 commit comments