Skip to content

Commit eb941af

Browse files
vibeguiclaude
andcommitted
refactor(cache): move loader observability to PR #1124
Histograms, bgRevalidation timer, and cache entry size recording now ship in the correctness+observability PR for earlier visibility. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4e3bb7b commit eb941af

File tree

1 file changed

+2
-34
lines changed

1 file changed

+2
-34
lines changed

blocks/loader.ts

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,6 @@ const stats = {
146146
unit: "ms",
147147
valueType: ValueType.DOUBLE,
148148
}),
149-
cacheEntrySize: meter.createHistogram("loader_cache_entry_size", {
150-
description: "size of cached loader responses in bytes",
151-
unit: "bytes",
152-
valueType: ValueType.DOUBLE,
153-
}),
154-
bgRevalidation: meter.createHistogram("loader_bg_revalidation", {
155-
description: "duration of background stale-while-revalidate calls",
156-
unit: "ms",
157-
valueType: ValueType.DOUBLE,
158-
}),
159149
};
160150

161151
let maybeCache: Cache | undefined;
@@ -346,35 +336,13 @@ const wrapLoader = (
346336
status = "stale";
347337
stats.cache.add(1, { status, loader });
348338

349-
// Timer lives inside the singleFlight fn so it records exactly once
350-
// per revalidation, not once per concurrent waiter on the same key.
351-
bgFlights.do(request.url, async () => {
352-
const bgStart = performance.now();
353-
try {
354-
return await callHandlerAndCache();
355-
} finally {
356-
if (OTEL_ENABLE_EXTRA_METRICS) {
357-
stats.bgRevalidation.record(
358-
performance.now() - bgStart,
359-
{ loader },
360-
);
361-
}
362-
}
363-
}).catch((error) => logger.error(`loader error ${error}`));
339+
bgFlights.do(request.url, callHandlerAndCache)
340+
.catch((error) => logger.error(`loader error ${error}`));
364341
} else {
365342
status = "hit";
366343
stats.cache.add(1, { status, loader });
367344
}
368345

369-
if (OTEL_ENABLE_EXTRA_METRICS) {
370-
const cl = parseInt(
371-
matched.headers.get("Content-Length") ?? "0",
372-
);
373-
if (cl > 0) {
374-
stats.cacheEntrySize.record(cl, { loader, status });
375-
}
376-
}
377-
378346
return await matched.json();
379347
};
380348

0 commit comments

Comments
 (0)