Skip to content

Support time offset for metric timestamps#141

Merged
andrewh merged 1 commit into
mainfrom
claude/lucid-albattani-96b8ay
Jun 11, 2026
Merged

Support time offset for metric timestamps#141
andrewh merged 1 commit into
mainfrom
claude/lucid-albattani-96b8ay

Conversation

@andrewh

@andrewh andrewh commented Jun 10, 2026

Copy link
Copy Markdown
Owner

Closes #99

Problem

The --time-offset flag shifts trace span and log record timestamps, but metric data points were unaffected: the OTel Metrics API does not accept caller-supplied timestamps, so data points are stamped at collection time by the SDK's PeriodicReader.

Approach

As designed in the issue, this adds a custom exporter wrapper (synth.NewTimeOffsetMetricExporter) that rewrites timestamps on metricdata.ResourceMetrics before forwarding to the underlying exporter:

  • Shifts StartTime and Time on every data point across all aggregation types: Gauge, Sum, Histogram, ExponentialHistogram (both int64 and float64 variants), and Summary
  • Also shifts exemplar timestamps for consistency
  • A zero offset returns the wrapped exporter unchanged, so the wrapper is wired unconditionally into createMetricProviders

Tests

  • Unit test covering all nine aggregation type variants plus exemplars
  • End-to-end test through a PeriodicReader verifying a recorded counter's data point lands within the shifted wall-clock window
  • Verified manually: motel run --stdout --signals metrics --time-offset=-24h produces data points stamped 24 hours in the past

Also updates the stale "Metric timestamps are not shifted" section in the time-offset demo doc and the --time-offset flag help text.

https://claude.ai/code/session_01TzfXWApbD3TJcKRrChdgai


Generated by Claude Code

The OTel Metrics API does not accept caller-supplied timestamps, so
--time-offset previously had no effect on metric data points. Add an
exporter wrapper that rewrites StartTime, Time, and exemplar timestamps
on all metricdata aggregation types before forwarding to the underlying
exporter, and wire it into createMetricProviders.

Closes #99
@andrewh
andrewh merged commit 7d84857 into main Jun 11, 2026
2 checks passed
@andrewh
andrewh deleted the claude/lucid-albattani-96b8ay branch June 11, 2026 05:42
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.

Support time offset for metric timestamps

2 participants