opentelemetry-rust icon indicating copy to clipboard operation
opentelemetry-rust copied to clipboard

feat: Redesigns the `InMemoryMetricExporter`

Open emadpres opened this issue 4 weeks ago • 2 comments

Redesigned InMemoryMetricExporter

Fixes #2725.

Changes

Updates InMemoryMetricExporter (similar to what was suggested in #2649) to accept and use a user-specified data collection to store the metrics data, rather than creating one internally and returning it eventually. This makes the exporter more consistent with the 'production' exporters, which are given their sink by the user (e.g., by being passed a gRPC channel to write to) - rather than owning where the data goes. This also means we no longer need to be able to clone the exporter simply to access the data back out in unit tests.

If we are happy with this approach, we can extend it to the other in memory exporters - InMemoryLogExporter and InMemorySpanExporter.

API Changes

  • The InMemoryMetricExporter now must be instanciated through InMemoryMetricExporterBuilder and it no longer has Default and Clone implementations.
  • InMemoryMetricExporterBuilder has the mandatory metrics: Arc<Mutex<Vec<_>>> field to be set.

Merge requirement checklist

  • [x] CONTRIBUTING guidelines followed
  • [x] Unit tests ~~added/~~ updated
  • [x] Appropriate CHANGELOG.md files updated for non-trivial, user-facing changes
  • [ ] Changes in public API reviewed (if applicable)

emadpres avatar Nov 22 '25 14:11 emadpres

CLA Signed
The committers listed above are authorized under a signed CLA.

  • :white_check_mark: login: emadpres / name: Emad Aghajani (18a754f5972810bb850fceaa9c410c7a7b168c8f, 1b9d7bb833c44ce5ba7a838067c822a1cd8831f0, a3f5570216d06d3b88a7439369ea1109d78737aa, afbc334003a9ba83e97244f04f8ea904db842406, ba9847fd0a1adf2bc8d2f6910c051441fdc5498a, bbf0e3c2640a465b34a7a3dbf0d1f72c1214d3f7, c6832c274335ae5f4aa50de5851c23c878525924, cd397aa680820826d8b7da20360e6355f5be318a, d5b3c6613456c81889ce8872e42e65442fc02493)

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 80.9%. Comparing base (df412fe) to head (c6832c2).

Additional details and impacted files
@@           Coverage Diff           @@
##            main   #3257     +/-   ##
=======================================
+ Coverage   80.8%   80.9%   +0.1%     
=======================================
  Files        129     129             
  Lines      23203   23342    +139     
=======================================
+ Hits       18750   18892    +142     
+ Misses      4453    4450      -3     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

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

codecov[bot] avatar Nov 22 '25 14:11 codecov[bot]