Skip to content

fix(collector): use Telemetry API event time as metric timestamp#2288

Open
dmedovich wants to merge 1 commit into
open-telemetry:mainfrom
dmedovich:fix/telemetryapireceiver-metric-event-time
Open

fix(collector): use Telemetry API event time as metric timestamp#2288
dmedovich wants to merge 1 commit into
open-telemetry:mainfrom
dmedovich:fix/telemetryapireceiver-metric-event-time

Conversation

@dmedovich
Copy link
Copy Markdown

  • Track the latest Telemetry API event time observed in recordMetrics on the receiver (lastEventTime).
  • Use lastEventTime as the data point timestamp in flushMetricsLocked, falling back to time.Now() only when no event has been observed yet (in which case AppendDataPoints exports nothing anyway).
  • Access is serialized by the existing r.mu, which already protects both recordMetrics and flushMetricsLocked.

This mirrors the behavior of the log pipeline and resolves the metric/log timestamp divergence described in the linked issue.

Testing

  • Added TestMetricTimestampMatchesEventTime, which records events with a fixed RFC3339 time, performs a delayed flush, and asserts every Sum/Histogram data point's Timestamp() matches the event time rather than wall-clock time.Now().
  • go test ./... and go vet ./... pass for the package.

Fixes #2263

@dmedovich dmedovich requested a review from a team as a code owner May 11, 2026 18:12
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented May 11, 2026

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

  • ✅ login: dmedovich / name: Daniil Bee (a65afb2)

@dmedovich
Copy link
Copy Markdown
Author

@wpessers

@wpessers
Copy link
Copy Markdown
Member

Thank you for working on this @dmedovich! I will take some time tomorrow to take a closer look at your changes!

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.

telemetryapi: Metric timestamps are delayed - set via date.Now() on lambda thaw

2 participants