Skip to content

Support temporality selectors in InMemoryMetricExporter - #8993

Open
trask wants to merge 4 commits into
open-telemetry:mainfrom
trask:trask-in-memory-temporality-selector
Open

trask wants to merge 4 commits into
open-telemetry:mainfrom
trask:trask-in-memory-temporality-selector

Conversation

@trask

@trask trask commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Add InMemoryMetricExporter.builder() with a temporality selector so tests can select temporality by instrument type without a custom exporter wrapper.

InMemoryMetricExporter exporter =
    InMemoryMetricExporter.builder()
        .setAggregationTemporalitySelector(AggregationTemporalitySelector.deltaPreferred())
        .build();

This uses delta temporality for counters and histograms while keeping up-down counters cumulative.

Existing factories retain their behavior: create() uses cumulative temporality for all instruments, and create(AggregationTemporality) applies the given temporality to every instrument type.

Related to open-telemetry/opentelemetry-java-instrumentation#21111.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@otelbot otelbot Bot added the api-change Changes to public API surface area label Oct 31, 2026
@otelbot

otelbot Bot commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

⚠️ API changes detected — additional maintainer review required

@jack-berg @jkwatson

This PR modifies the public API surface area of the following module(s):

  • opentelemetry-sdk-testing

Please review the changes in docs/apidiffs/current_vs_latest/ carefully before approving.

@trask
trask requested a balanced review from Copilot October 31, 2026 20:25
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on the author · refreshed 2026-11-04 00:49 UTC

Investigate required status check failures.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Should this be with reviewers? Comment /dashboard route:reviewers to route it to them.
  • Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block the temporality-selector factory change.

No open issues 🎉

What changed in this PR

Adds instrument-specific temporality selection to InMemoryMetricExporter, allowing tests to use selectors such as deltaPreferred() without a custom exporter wrapper.

Changes:

  • Adds a selector-based factory while preserving the behavior of existing factories.
  • Expands tests for temporality selection, null-selector rejection, metric collection, and exported-data preservation.
  • Updates the API compatibility report to record the new overload.
File Description
sdk/​testing/​src/​test/​java/​io/​opentelemetry/​sdk/​testing/​exporter/​InMemoryMetricExporterTest.java Tests selector behavior and preserves coverage of existing factories.
sdk/​testing/​src/​main/​java/​io/​opentelemetry/​sdk/​testing/​exporter/​InMemoryMetricExporter.java Adds the selector factory and delegates temporality selection to it.
docs/​apidiffs/​current_vs_latest/​opentelemetry-sdk-testing.txt Records the new public factory overload.

Review effort: Balanced

@codecov

codecov Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.37%. Comparing base (1acb73a) to head (38e1cec).

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8993      +/-   ##
============================================
- Coverage     90.37%   90.37%   -0.01%     
- Complexity    11012    11016       +4     
============================================
  Files          1020     1021       +1     
  Lines         30119    30127       +8     
  Branches       3932     3932              
============================================
+ Hits          27219    27226       +7     
  Misses         1941     1941              
- Partials        959      960       +1     

☔ View full report in Codecov by Harness.
📢 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.

* @param aggregationTemporalitySelector selects the aggregation temporality for each instrument
* type
*/
public static InMemoryMetricExporter create(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

InMemoryMetricReader started with just create() methods, but expanded to a builder because the configuration footprint expanded to include setAggregationTemporalitySelector, setDefaultAggregationSelector, setMemoryMode. I see InMemoryMetricExporter going the same way so let's just jump to the builder now anticipating the setMemoryMode and setDefaultAggregationSeletor configuration options.

trask and others added 3 commits November 3, 2026 15:25
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-change Changes to public API surface area

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants