Skip to content

Add support for batching in PeriodicMetricReader#8296

Open
psx95 wants to merge 53 commits intoopen-telemetry:mainfrom
psx95:issue-8245
Open

Add support for batching in PeriodicMetricReader#8296
psx95 wants to merge 53 commits intoopen-telemetry:mainfrom
psx95:issue-8245

Conversation

@psx95
Copy link
Copy Markdown
Contributor

@psx95 psx95 commented Apr 15, 2026

This PR adds support for configuring setMaxExportBatchSize on the PeriodicMetricReader that sets the maximum number of metric data points to be sent in a single export call.

If the number of metric data points (across Collection<MetricData>) scheduled to be export exceeds the maxExportBatchSize, the data points organized in batches and sent over multiple export calls.

These changes do not modify the current timeout behavior, which is still per export call.

Fix #8245

@otelbot otelbot Bot added the api-change Changes to public API surface area label Apr 15, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 15, 2026

Codecov Report

❌ Patch coverage is 90.90909% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.31%. Comparing base (fdb8194) to head (79adac4).
⚠️ Report is 17 commits behind head on main.

Files with missing lines Patch % Lines
...try/sdk/metrics/internal/SdkMeterProviderUtil.java 0.00% 8 Missing ⚠️
...emetry/sdk/metrics/export/MetricExportBatcher.java 97.00% 1 Missing and 2 partials ⚠️
...metry/sdk/metrics/export/PeriodicMetricReader.java 93.54% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8296      +/-   ##
============================================
+ Coverage     90.27%   90.31%   +0.03%     
- Complexity     7693     7743      +50     
============================================
  Files           850      851       +1     
  Lines         23207    23398     +191     
  Branches       2356     2376      +20     
============================================
+ Hits          20951    21132     +181     
- Misses         1530     1537       +7     
- Partials        726      729       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@psx95 psx95 marked this pull request as ready for review April 15, 2026 18:42
@psx95 psx95 requested a review from a team as a code owner April 15, 2026 18:42
Collection<MetricData> currentBatch = new ArrayList<>(maxExportBatchSize);

// Fill active batch and split overlapping metric points if needed
for (MetricData metricData : metrics) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: i expected prepareExportBatches to take the Collection so that all of the batching logic is contained within the batcher (and we don't have to pass + update currentBatch).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we are not technically updating the currentBatch in this loop - the contents within the currentBatch is updated by the prepareExportBatches.

My intention behind the prepareExportBatches was a function that splits a given MetricData into appropriate export batches. Since the batches need to be completely filled (except the last one), this function requires the currentBatch as well.

Maybe if the function was renamed to splitMetricData it would make more sense?

This comment was marked as outdated.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

zeitlinger and others added 5 commits April 27, 2026 07:49
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
# Conflicts:
#	sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/export/MetricExportBatcher.java
…ropagation' into lane-a-pr-8296

# Conflicts:
#	sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/export/PeriodicMetricReaderTest.java
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
…propagation

Fix batched forceFlush failure and make batching linear
Copy link
Copy Markdown
Member

@jack-berg jack-berg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of comments, but looks pretty good!

@otelbot otelbot Bot removed the api-change Changes to public API surface area label Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement PeriodicMetricREader#maxExportBatchSize

5 participants