From 45c7e9cfa8b82681a2429eb76b97cbcc0e8a646e Mon Sep 17 00:00:00 2001 From: Brendan J Berg Date: Thu, 30 Oct 2025 21:40:53 -0700 Subject: [PATCH] fix: normalize paths in metrics better --- plugins/setup.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/plugins/setup.ts b/plugins/setup.ts index 431a78f..4616e4f 100644 --- a/plugins/setup.ts +++ b/plugins/setup.ts @@ -11,10 +11,21 @@ import { useStorageAdapter } from '~/lib/storage' function getEndpointName(path: string): string { // Normalize dynamic routes for better metric grouping return path - .replaceAll(/\/\d+/g, '/:id') // Replace numeric IDs - .replaceAll(/\/[a-f0-9-]{36}/g, '/:uuid') // Replace UUIDs - .replaceAll(/\/[a-f0-9]{8,}/g, '/:hash') // Replace long hashes - .replace(/\/_apis\/artifactcache/, '/api/cache') // Simplify API paths + .replace(/\/_apis\/artifactcache/, '/api/cache') // Simplify API paths first + .split('/') + .map((segment) => { + if (!segment) return segment + // Numeric IDs + if (/^\d+$/.test(segment)) return ':id' + // UUIDs + if (/^[a-f0-9-]{36}$/.test(segment)) return ':uuid' + // Long hex strings (cache file names, hashes) + if (/^[a-f0-9]{32,}$/.test(segment)) return ':hash' + // Long alphanumeric strings (base64, cache keys, etc) + if (segment.length > 20 && /^[\w+/=-]+$/.test(segment)) return ':param' + return segment + }) + .join('/') } export default defineNitroPlugin(async (nitro) => {