|
37 | 37 | ) |
38 | 38 | from opentelemetry.exporter.otlp.proto.common._internal.metrics_encoder import ( |
39 | 39 | OTLPMetricExporterMixin, |
| 40 | + split_metrics_data, |
40 | 41 | ) |
41 | 42 | from opentelemetry.exporter.otlp.proto.common.metrics_encoder import ( |
42 | 43 | encode_metrics, |
@@ -116,7 +117,29 @@ def __init__( |
116 | 117 | preferred_temporality: dict[type, AggregationTemporality] |
117 | 118 | | None = None, |
118 | 119 | preferred_aggregation: dict[type, Aggregation] | None = None, |
| 120 | + max_export_batch_size: int | None = None, |
119 | 121 | ): |
| 122 | + """OTLP HTTP metrics exporter |
| 123 | +
|
| 124 | + Args: |
| 125 | + endpoint: Target URL to which the exporter is going to send metrics |
| 126 | + certificate_file: Path to the certificate file to use for any TLS |
| 127 | + client_key_file: Path to the client key file to use for any TLS |
| 128 | + client_certificate_file: Path to the client certificate file to use for any TLS |
| 129 | + headers: Headers to be sent with HTTP requests at export |
| 130 | + timeout: Timeout in seconds for export |
| 131 | + compression: Compression to use; one of none, gzip, deflate |
| 132 | + session: Requests session to use at export |
| 133 | + preferred_temporality: Map of preferred temporality for each metric type. |
| 134 | + See `opentelemetry.sdk.metrics.export.MetricReader` for more details on what |
| 135 | + preferred temporality is. |
| 136 | + preferred_aggregation: Map of preferred aggregation for each metric type. |
| 137 | + See `opentelemetry.sdk.metrics.export.MetricReader` for more details on what |
| 138 | + preferred aggregation is. |
| 139 | + max_export_batch_size: Maximum number of data points to export in a single request. |
| 140 | + If not set there is no limit to the number of data points in a request. |
| 141 | + If it is set and the number of data points exceeds the max, the request will be split. |
| 142 | + """ |
120 | 143 | self._endpoint = endpoint or environ.get( |
121 | 144 | OTEL_EXPORTER_OTLP_METRICS_ENDPOINT, |
122 | 145 | _append_metrics_path( |
@@ -166,6 +189,8 @@ def __init__( |
166 | 189 | preferred_temporality, preferred_aggregation |
167 | 190 | ) |
168 | 191 |
|
| 192 | + self._max_export_batch_size: int | None = max_export_batch_size |
| 193 | + |
169 | 194 | def _export(self, serialized_data: bytes): |
170 | 195 | data = serialized_data |
171 | 196 | if self._compression == Compression.Gzip: |
@@ -240,6 +265,15 @@ def export( |
240 | 265 | return MetricExportResult.FAILURE |
241 | 266 | return MetricExportResult.FAILURE |
242 | 267 |
|
| 268 | + def _split_metrics_data( |
| 269 | + self, |
| 270 | + metrics_data: MetricsData, |
| 271 | + ) -> Iterable[MetricsData]: |
| 272 | + return split_metrics_data( |
| 273 | + metrics_data, |
| 274 | + self._max_export_batch_size, |
| 275 | + ) |
| 276 | + |
243 | 277 | def shutdown(self, timeout_millis: float = 30_000, **kwargs) -> None: |
244 | 278 | pass |
245 | 279 |
|
|
0 commit comments