Skip to content

Commit 2f4c72b

Browse files
Http metric exporter init with batch_size, add split_metrics_data
1 parent df6b365 commit 2f4c72b

File tree

2 files changed

+347
-0
lines changed

2 files changed

+347
-0
lines changed

exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
)
3838
from opentelemetry.exporter.otlp.proto.common._internal.metrics_encoder import (
3939
OTLPMetricExporterMixin,
40+
split_metrics_data,
4041
)
4142
from opentelemetry.exporter.otlp.proto.common.metrics_encoder import (
4243
encode_metrics,
@@ -116,7 +117,29 @@ def __init__(
116117
preferred_temporality: dict[type, AggregationTemporality]
117118
| None = None,
118119
preferred_aggregation: dict[type, Aggregation] | None = None,
120+
max_export_batch_size: int | None = None,
119121
):
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+
"""
120143
self._endpoint = endpoint or environ.get(
121144
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT,
122145
_append_metrics_path(
@@ -166,6 +189,8 @@ def __init__(
166189
preferred_temporality, preferred_aggregation
167190
)
168191

192+
self._max_export_batch_size: int | None = max_export_batch_size
193+
169194
def _export(self, serialized_data: bytes):
170195
data = serialized_data
171196
if self._compression == Compression.Gzip:
@@ -240,6 +265,15 @@ def export(
240265
return MetricExportResult.FAILURE
241266
return MetricExportResult.FAILURE
242267

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+
243277
def shutdown(self, timeout_millis: float = 30_000, **kwargs) -> None:
244278
pass
245279

0 commit comments

Comments
 (0)