Skip to content

receiver/azuremonitor: fix StartTimestamp > Timestamp in batch API path#47749

Open
Sanil2108 wants to merge 1 commit intoopen-telemetry:mainfrom
Sanil2108:fix/azuremonitor-batch-start-timestamp
Open

receiver/azuremonitor: fix StartTimestamp > Timestamp in batch API path#47749
Sanil2108 wants to merge 1 commit intoopen-telemetry:mainfrom
Sanil2108:fix/azuremonitor-batch-start-timestamp

Conversation

@Sanil2108
Copy link
Copy Markdown

Fixes #47705

Problem

When use_batch_api: true, processQueryTimeseriesData in scraper_batch.go sets the data point timestamp (ts) from metricValue.TimeStamp — Azure's aggregation window end time, which can be up to an hour in the past.

However, AddDataPoint in internal/metadata/metrics.go was calling:

dp.SetStartTimestamp(mb.startTime)  // scrape time (now)
dp.SetTimestamp(ts)                 // Azure aggregation time (past)

This results in StartTimestamp > Timestamp, which violates the OTel data model requirement that StartTimestamp <= Timestamp. Downstream consumers such as Prometheus remote-write reject these data points.

Fix

Use ts for StartTimestamp so it always equals Timestamp:

dp.SetStartTimestamp(ts)
dp.SetTimestamp(ts)

For the non-batch scraper, ts = time.Now() so the behaviour is unchanged (StartTimestamp ≈ Timestamp ≈ now). For the batch scraper, StartTimestamp now correctly equals the aggregation window timestamp instead of the scrape time.

Testing

  • All 95 existing tests pass.
  • Added an assertion in metrics_test.go that explicitly verifies StartTimestamp == Timestamp (the existing tests used IgnoreStartTimestamp() and did not catch this regression).

In the use_batch_api path, ts comes from metricValue.TimeStamp (Azure's
aggregation window end time, potentially hours in the past). However,
AddDataPoint was setting dp.SetStartTimestamp(mb.startTime) where
mb.startTime is the scrape time (now), resulting in StartTimestamp >
Timestamp which violates the OTel data model.

Fix by using ts for StartTimestamp so it is always equal to Timestamp.
This ensures the constraint StartTimestamp <= Timestamp is always met.

The existing tests used IgnoreStartTimestamp() and did not catch this.
A new assertion is added to metrics_test.go to explicitly verify that
StartTimestamp equals the data point Timestamp, not mb.startTime.

Fixes open-telemetry#47705
@Sanil2108 Sanil2108 requested a review from a team as a code owner April 19, 2026 04:58
@Sanil2108 Sanil2108 requested a review from bogdandrutu April 19, 2026 04:58
@github-actions github-actions bot added the first-time contributor PRs made by new contributors label Apr 19, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Welcome, contributor! Thank you for your contribution to opentelemetry-collector-contrib.

Important reminders:

A maintainer will review your pull request soon. Thank you for helping make OpenTelemetry better!

Copy link
Copy Markdown
Member

@celian-garcia celian-garcia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh thank you for referencing the data model spec. Reading it I'm realising that it makes no sense in that case to ever have a separate start timestamp indeed. Azure Monitor metrics are all gauges. No counters, no histograms,...

We could even remove it but I think I like to see it explicitly.

@celian-garcia
Copy link
Copy Markdown
Member

I don't have the right to approve the workflow but I know already that it won't pass. This should contain a changelog. This is described on the contributing guidelines, can you have a look ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[receiver/azuremonitor] Problem with StartTimestamp and timestamp For BatchApi

3 participants