Skip to content

ref(metrics): Add internal metric timestamp parameter - #9442

Draft
itaybre wants to merge 1 commit into
mainfrom
ref/metrics-timestamp
Draft

itaybre wants to merge 1 commit into
mainfrom
ref/metrics-timestamp

Conversation

@itaybre

@itaybre itaybre commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

Let SDK integrations record a metric for a moment in the past. The metrics API always stamped metrics with the current time, but MetricKit metric payloads (#9269) describe a reporting interval of up to a day before they are delivered.

Internal overloads

SentryMetricsApi+Internal.swift adds count, distribution and gauge overloads that take a timestamp: Date. They live on the internal SentryMetricsApi struct, not on the public SentryMetricsApiProtocol that SentrySDK.metrics is typed as, so the public API and its snapshots are unchanged. Metrics recorded without a timestamp keep using the current date.

let metrics = SentryMetricsApi(dependencies: SentryDependencyContainer.sharedInstance())
metrics.distribution(key: "metrickit.launch.time_to_first_draw", value: 1.2, unit: .second, timestamp: intervalStart)

Timestamp age

The SDK sends the timestamp as is. Relay rejects trace metrics older than the organization's trace metric retention and corrects timestamps for client clock drift (relay-server/src/processing/utils/normalize.rs), so ingestion owns the limit and a day-old MetricKit payload is well within it.

The trace ID is still taken from the scope when the metric is recorded. Whether past metrics should carry it is left to #9269.

Fixes #9268

#skip-changelog

The metrics API always stamps a metric with the current time, so SDK
integrations cannot report a metric for a moment in the past. MetricKit
metric payloads describe a reporting interval of up to a day before
they are delivered.

Add internal count, distribution and gauge overloads that take a
timestamp. They are not part of the public SentryMetricsApiProtocol.
The SDK sends the timestamp as is and leaves the accepted age to Relay,
which rejects trace metrics older than the retention period.

Fixes #9268
@itaybre itaybre added the run-full-ci Allows gated GitHub Action workflows to run for a labelled pull request label Oct 23, 2026
@sentry

sentry Bot commented Oct 23, 2026

Copy link
Copy Markdown

Size Analysis

1 component analyzed

iOS Builds

Name Configuration Version Download Size Install Size
SDK-Size (iOS)
io.sentry.sample.SDK-Size
Release 9.31.0 (1) 1.2 MB (+106 B) 3.1 MB (0 B)

Configure sentry-cocoa status check rules

@sentry

sentry Bot commented Oct 23, 2026

Copy link
Copy Markdown

📲 Install Builds

iOS

🔗 App Name App ID Version Configuration
SDK-Size io.sentry.sample.SDK-Size 9.31.0 (1) Release

⚙️ sentry-cocoa Build Distribution Settings

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

run-full-ci Allows gated GitHub Action workflows to run for a labelled pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a timestamp parameter to the metrics API

1 participant