Repository navigation
fix(blocks): collapse CMS content slugs in normalizePath - #447
Merged
Merged
Conversation
`normalizePath` already states the rule it exists to enforce — "a raw path is
unbounded cardinality (one histogram series per URL) and must never reach a
metric attribute" — and collapses hex ids, numeric ids and `/:slug/p` product
pages to placeholders.
It does not catch CMS content slugs, which carry no digits, no hex id and no
`/p` suffix, so each CMS page passes through as its own literal path:
/mochila-de-couro
/moveis/quarto-infantil
/granado/eau-de-toilette-spritz-100ml
/moveis/quarto-adulto/cabeceiras-mesa-de-cabeceiras
Measured on the production ClickHouse, `http.route` reached 20,714 distinct
values across only 6 tenants — roughly 9,900 series per tenant, against ~390
for the legacy runtime's equivalent. It sits on
`http.server.request.duration`, the highest-volume metric in the pipeline
(19,055,009 rows in 3h), and `otel_metrics_histogram` holds 149.65 GB.
Every other attribute on that metric is already well behaved: `url.path` is 1
distinct value, `deco.http.status_class` 4, `http.response.status_code` 20,
`user_agent.original` 1. `http.route` carries essentially all of the
cardinality.
The fix collapses any hyphenated path segment to `:slug`. A hyphen is the
discriminator: CMS slugs are hyphenated by construction, while framework and
API segments are single words (`api`, `sessions`, `deco`, `invoke`, `loaders`,
`render`), so those keep their meaning and stay individually visible. Dotfile
segments such as `.well-known` are excluded.
Routes that arrive with an explicit `route_pattern` are untouched — this only
affects the fallback branch, which is exactly where the unbounded values were
coming from.
What is lost: per-page latency breakdown for CMS pages. That was never a real
capability — it was 20,714 series impersonating a dimension — but "how slow is
this specific product page" now has to come from spans or logs rather than
this metric. The top-level section is preserved (`/moveis/:slug`,
`/granado/:slug`), so "are furniture listings slow" still answers.
This is a heuristic, and it is the one judgement call in the change: a
single-word CMS slug with no hyphen would still pass through. Tests cover the
real paths measured in production.
Verified: tsc --noEmit clean, 659/659 tests pass across 50 files.
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.2 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
nicacioliveira
pushed a commit
that referenced
this pull request
Aug 13, 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]>
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.
Closes #428.
Problem
normalizePathalready states the rule it exists to enforce — "a raw path is unbounded cardinality (one histogram series per URL) and must never reach a metric attribute" — and collapses hex ids, numeric ids and/:slug/pproduct pages.It does not catch CMS content slugs. They carry no digits, no hex id and no
/psuffix, so nothing matches and each CMS page passes through as its own literal path:Measured
http.routereached 20,714 distinct values across only 6 tenants — ~9,900 series per tenant, against ~390 for the legacy runtime's equivalent.It sits on
http.server.request.duration, the highest-volume metric in the pipeline (19,055,009 rows in 3h), andotel_metrics_histogramholds 149.65 GB.Every other attribute on that metric is already well behaved:
url.pathdeco.http.status_classhttp.response.status_codeuser_agent.originalhttp.routeSo
http.routecarries essentially all of the cardinality on the biggest metric we have.Fix
Collapse any hyphenated path segment to
:slug.A hyphen is the discriminator: CMS slugs are hyphenated by construction, while framework and API segments are single words (
api,sessions,deco,invoke,loaders,render) and keep their meaning. Dotfile segments like.well-knownare excluded.Routes arriving with an explicit
route_patternare untouched — this only changes the fallback branch, which is exactly where the unbounded values came from.What is lost, and the judgement call
Per-page latency breakdown for CMS pages. That was never a real capability — it was 20,714 series impersonating a dimension — but "how slow is this specific product page" now has to come from spans or logs rather than this metric. The top-level section survives (
/moveis/:slug), so "are furniture listings slow" still answers.The hyphen heuristic is the one judgement call here. A single-word CMS slug with no hyphen still passes through. I picked it because it is simple, needs no route registry, and covers every path actually observed in production — but if you would rather key off something authoritative (the matched page id, or omitting
http.routeentirely when there is no template, per semconv), say so and I will reshape it.Verification
tsc --noEmitcleanvitest run packages/blocks/→ 659 passed / 50 files (4 new tests covering the real production paths)🤖 Generated with Claude Code
Summary by cubic
Collapses CMS slug segments in
normalizePathto boundhttp.routeand stop unbounded series onhttp.server.request.duration. Reduces metric cardinality and storage while keeping API/framework routes intact.:slug; keep.well-knownreadable and non-hyphenated segments unchanged.route_patternis present.Written for commit b9e45a9. Summary will update on new commits.