Repository navigation
fix(blocks): declare second-scale bucket boundaries for duration histograms - #427
Merged
Merged
Conversation
…ograms The record helpers divide by 1000, so every duration metric is emitted in seconds — correct per SemConv, and METRIC_METADATA already declares unit: "s". But the buckets are configured somewhere else entirely: adapters wire up `histogramRecord` themselves, and the reference implementation in this file's own docblock called `createHistogram(name)` with no advice. That inherits the OTel SDK defaults, `[0, 5, 10, 25, 50, 75, 100, 250, 500, 1000]`, which are milliseconds. Unit and buckets had drifted apart, and nothing in the type system connected them. Measured on the production ClickHouse before this change: metric avg (s) first bucket http.server.request.duration 0.251 99.92% deco.cms.resolve.duration 0.485 99.82% http.client.request.duration 0.458 99.93% deco.loader.duration 0.142 99.95% 78.7M observations/hour on http.server.request.duration alone, essentially all of them in bucket 1. Every quantile read back as ~0, so the latency dashboards fell back to `otel_traces` — which is tail-sampled at ~1.7%, meaning a p95 over a short window was often just the second-slowest sampled request. That cost us a live misdiagnosis: a p95 of 66s computed from 124 sampled spans looked like a regression and wasn't. For contrast, the `deno` scope gets this right for seconds today (`0.005, 0.01, 0.025, 0.05, ...`), and the legacy deco-cx/deco runtime is fine because it records milliseconds into millisecond buckets. Changes: - Export DURATION_BUCKET_BOUNDARIES_SECONDS, the SemConv-recommended defaults for HTTP duration histograms. - Add an optional `boundaries` field to METRIC_METADATA and set it on all four second-valued metrics. The map is already exported and already consulted for unit/description, so adapters pick this up at histogram creation — including deco.cms.resolve.duration, which has no record call site in this file. - Update the docblock's reference adapter to forward `boundaries` to `advice`, and say plainly that it is required rather than optional. - Add three regression tests asserting every unit: "s" metric declares boundaries and that they are second-scaled, so the next duration metric that ships without them fails here instead of in a dashboard months later. Only new data is affected; existing histogram rows stay unusable for quantiles. Verified: tsc --noEmit clean, 629/629 tests pass across 46 files. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
hugo-ccabral
previously approved these changes
Aug 6, 2026
Conflict was in observability.test.ts only: both sides appended a new describe block at the end of the file (#447's normalizePath cardinality cases and this PR's METRIC_METADATA bucket guards), so git overlapped the two regions. Kept both, and merged the import list. observability.ts auto-merged cleanly. Verified semantically, not just textually: main added SWR cache instrumentation, so the guard in this PR ("every metric with unit 's' must declare boundaries") could have started failing. All 4 second-scale metrics in the merged METRIC_METADATA carry DURATION_BUCKET_BOUNDARIES_SECONDS. Gates: 673 tests pass (51 files), blocks typecheck clean. biome lint diagnostics on these two files are identical to main's baseline; the resolution also fixes the import-sort error main currently carries. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
hugo-ccabral
approved these changes
Aug 13, 2026
|
🎉 This PR is included in version 7.37.5 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Every duration metric here is recorded in seconds — the record helpers divide by 1000, and
METRIC_METADATAalready declaresunit: "s". That part is correct per SemConv.The buckets, though, are configured somewhere else entirely. Adapters wire up
histogramRecordthemselves, and the reference implementation in this file's own docblock calledcreateHistogram(name)with noadvice. That inherits the OTel SDK defaults —[0, 5, 10, 25, 50, 75, 100, 250, 500, 1000]— which are milliseconds.Unit and buckets had drifted apart, and nothing in the type system connected them.
Measured impact
Production ClickHouse, before this change:
http.server.request.durationdeco.cms.resolve.durationhttp.client.request.durationdeco.loader.duration78.7M observations/hour on
http.server.request.durationalone, essentially all of them in bucket 1. Every quantile reads back as ~0.The consequence is not theoretical: the latency dashboards fall back to
otel_traces, which is tail-sampled at ~1.7%. A p95 over a short window is then often just the second-slowest sampled request. That produced a live misdiagnosis yesterday — a p95 of 66s computed from 124 sampled spans looked like a regression and wasn't.For contrast, the
denoscope already gets this right for seconds (0.005, 0.01, 0.025, 0.05, …), and the legacydeco-cx/decoruntime is fine because it records milliseconds into millisecond buckets (6% and 54% in the first bucket, spread properly).Changes
DURATION_BUCKET_BOUNDARIES_SECONDS— the SemConv-recommended defaults for HTTP duration histograms.boundariesfield toMETRIC_METADATA, set on all four second-valued metrics. The map is already exported and already consulted forunit/description, so adapters pick this up at histogram creation — includingdeco.cms.resolve.duration, which has no record call site in this file. That is why the fix lives in the metadata map rather than in an extrahistogramRecordargument.boundariesintoadvice, and state that it is required rather than optional.unit: "s"metric must declare boundaries, they must be second-scaled (first boundary< 1— a millisecond set starts at 5), sorted and deduped, and must cover both the observed average range and the 10s+ tail.MeterAdapteris unchanged, so no adapter breaks.Scope
Only new data is affected. Existing histogram rows stay unusable for quantiles — dashboards reading history will need the time range moved past the deploy.
Adapters that never consult
METRIC_METADATAwill keep inheriting SDK defaults. The docblock now shows the correct wiring, but if there is an in-repo adapter that should be updated in the same change, point me at it and I will add it here.Verification
tsc --noEmitcleanvitest run packages/blocks/→ 629 passed / 46 files🤖 Generated with Claude Code
Summary by cubic
Fixes seconds-valued duration histograms by declaring second-scale bucket boundaries and wiring them through
METRIC_METADATA, restoring accurate quantiles; previously, millisecond defaults put ~100% of traffic in the first bucket.Exported
DURATION_BUCKET_BOUNDARIES_SECONDS(SemConv HTTP duration defaults).Added optional
boundariestoMETRIC_METADATAand set it forhttp.server.request.duration,http.client.request.duration,deco.cms.resolve.duration, anddeco.loader.duration.Updated the docblock’s reference adapter to pass
boundariesto histogramadvice(required to avoid millisecond defaults).Added tests ensuring all
unit: "s"metrics declare second-scale boundaries that are sorted, deduped, and span sub-50ms to 10s+. Mergedmainwithout changing this guard.Migration
METRIC_METADATA.boundariesto histogramadviceto avoid millisecond default buckets.Written for commit 310ffdf. Summary will update on new commits.