Skip to content

ref(metrics): Deprecate MetricsUnit in favor of MeasurementUnit - #6086

Closed
runningcode wants to merge 3 commits into
mainfrom
no/ref-deprecate-metrics-unit
Closed

runningcode wants to merge 3 commits into
mainfrom
no/ref-deprecate-metrics-unit

Conversation

@runningcode

@runningcode runningcode commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

📜 Description

io.sentry.metrics.MetricsUnit duplicated, as String constants, every unit that
io.sentry.MeasurementUnit already defines — the same 8 durations, 14 information sizes and 2
fractions, with byte-identical values.

This deprecates MetricsUnit and moves every call site onto MeasurementUnit:

  • MetricsUnit and its three nested classes are @Deprecated, pointing at the MeasurementUnit
    equivalents.
  • The 16 sample MetricControllers pass MeasurementUnit.<Kind>.<UNIT>.apiName().

IMetricsApi is untouched — it keeps taking a String unit, so sentry.api is byte-identical to
main and there is no new public API to review. SentryMetricsEvent.unit likewise stays a String,
since units arriving off the wire are free-form and cannot be mapped back to an enum.

One thing worth a reviewer's opinion: MeasurementUnit.apiName() is annotated
@ApiStatus.Internal, so the samples in this PR — and any user following them — now call a method the
SDK marks as internal. The alternatives are to drop that annotation and commit to apiName() as
public API, or to add MeasurementUnit overloads to IMetricsApi that call apiName() internally.
Both were considered and deliberately not taken here; say the word if you'd rather have one.

💡 Motivation and Context

Two parallel sets of the same units is an easy trap for users: pick the wrong one and the compiler is
happy, but the typed measurement API and the metrics API read differently for no reason.
MeasurementUnit is the older, more capable of the two — it carries apiName() and a Custom
escape hatch — so it is the one to keep.

💚 How did you test it?

ScopesTest's existing metrics tests cover the converted call sites.

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

🔮 Next steps

  • docs/guides/metrics.mdx in sentry-docs still imports io.sentry.metrics.MetricsUnit in its Java
    and Kotlin snippets and needs a follow-up PR there.
  • MetricsUnit can be deleted in v9.

runningcode and others added 3 commits September 10, 2026 09:51
MetricsUnit restated, as string constants, every unit MeasurementUnit
already defines, because the metrics API only accepted a String unit and
the string form of a MeasurementUnit is only reachable through the
internal apiName().

Add MeasurementUnit overloads to IMetricsApi as default methods that
delegate to the existing String overloads, so apiName() stays internal,
and deprecate MetricsUnit.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…rloads

Drop the MeasurementUnit overloads from IMetricsApi. Callers reach the
string form through apiName(), so the metrics API surface is unchanged.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@sentry

sentry Bot commented Sep 10, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.56.0 (1) release

⚙️ sentry-android Build Distribution Settings

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.

1 participant