Skip to content

Commit 5c02c49

Browse files
fixed test and batching logic
1 parent f20eea6 commit 5c02c49

File tree

2 files changed

+598
-284
lines changed

2 files changed

+598
-284
lines changed

opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/export/__init__.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -657,11 +657,19 @@ def _export_batch(self) -> int:
657657
token = attach(set_value(_SUPPRESS_INSTRUMENTATION_KEY, True))
658658
try:
659659
with self._export_lock:
660+
# Create a combined metrics data object with all resource_metrics from the batch
661+
batch = []
660662
for metrics_data in pending_metrics:
661-
self._exporter.export(
662-
metrics_data,
663-
timeout_millis=self._export_timeout_millis,
664-
)
663+
batch.extend(metrics_data.resource_metrics)
664+
665+
# Create a single MetricsData object with all resource_metrics
666+
combined_metrics_data = MetricsData(resource_metrics=batch)
667+
668+
# Export the combined batch
669+
self._exporter.export(
670+
combined_metrics_data,
671+
timeout_millis=self._export_timeout_millis,
672+
)
665673
except Exception: # pylint: disable=broad-exception-caught
666674
_logger.exception("Exception while exporting metrics.")
667675
finally:

0 commit comments

Comments
 (0)