Skip to content

[Bug]: Prometheus bridge replaces explicit epoch timestamps with production time #9539

Description

@pellared

Component

go.opentelemetry.io/contrib/bridges/prometheus

Describe the issue

All Prometheus-to-OTLP metric converters determine whether an explicit sample timestamp is present by checking whether m.GetTimestampMs() != 0.

TimestampMs is an optional *int64. Its generated getter returns 0 both when the field is absent and when it is explicitly set to Unix epoch (0). As a result, an explicitly supplied epoch timestamp is treated as absent and replaced with the time of Produce.

The affected converters are:

This was identified in #9099 (comment).

The OpenTelemetry Prometheus compatibility specification requires a present Prometheus sample timestamp to be converted to the OTLP data point timestamp: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/compatibility/prometheus_and_openmetrics.md#timestamps.

Expected behavior

Converters should test field presence with m.TimestampMs != nil. If the field is present, including when its value is 0, the OTLP data point time should be set with time.UnixMilli(m.GetTimestampMs()). Only an absent timestamp should use the time of Produce.

Steps to reproduce

  1. Create a Prometheus metric with an explicit epoch timestamp, for example with prometheus.NewMetricWithTimestamp(time.Unix(0, 0), metric) or with TimestampMs: proto.Int64(0) on a dto.Metric.
  2. Gather and convert the metric using the Prometheus bridge.
  3. Observe that the OTLP data point timestamp is the current production time instead of 1970-01-01T00:00:00Z.

Suggested regression coverage

Add table-driven coverage for every converter verifying:

  • absent TimestampMs uses the production time;
  • present TimestampMs equal to 0 produces Unix epoch;
  • present non-zero TimestampMs preserves that timestamp.

Environment

Observed on the current main branch and in the implementation proposed by #9099. This behavior is independent of operating system and architecture.

Metadata

Metadata

Assignees

Labels

bridge: prometheusRelated to the Prometheus bridgebugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions