---
title: "Azure Monitor reports 0, not null, for latency in buckets with no requests"
url: "https://www.dariuszparys.com/notes/azure-monitor-reports-zero-latency-for-buckets-without-requests"
author: "Dariusz Parys"
published: 2026-11-20T00:00:00.000Z
description: "Azure Monitor returns an average of 0 for time buckets without requests, so reading the latest bucket or averaging the series records idle time as 0 ms latency."
tags:
  - "Azure"
  - "Observability"
---

# Azure Monitor reports 0, not null, for latency in buckets with no requests

## Context

When charting Azure Front Door metrics, stored latency samples all came out as 0 ms, even though the hour had responses that took several seconds.

## Insight

For an `Average` metric such as `TotalLatency`, Azure Monitor returns `average = 0` for every time bucket with no requests. It doesn't return null and doesn't leave the point out. The newest minutes of a query window also come back as zeros before their data is ingested.

So taking the latest bucket, or averaging the series naively, reads idle time as perfect latency. With append-only history, the wrong zeros then stay for the whole retention period.

## Fix

- Fetch `RequestCount` for the same buckets.
- Count latency only where the bucket has at least one request.
- Combine buckets, and dimension series such as per-endpoint splits, as a request-weighted average.
- When the window had no requests, write no sample at all, not a 0.

```python
# per bucket (and per dimension series): (avg_latency_ms, request_count)
pairs = [(lat, req) for lat, req in buckets if req and req > 0]
if pairs:
    weighted = sum(lat * req for lat, req in pairs) / sum(req for _, req in pairs)
    store(weighted)
# else: store nothing; no requests is not 0 ms latency
```
