From 5b37033b1623ad5c3b8fd89b1ee85b04b1811609 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Mon, 25 Sep 2023 14:03:41 +0200 Subject: Send content_encoding metrics to prometheus instead of sentry --- src/app.ts | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/src/app.ts b/src/app.ts index 61e62bc..e33bc72 100644 --- a/src/app.ts +++ b/src/app.ts @@ -33,7 +33,7 @@ const metrics = { requests: new prom.Counter({ name: "homestead_requests", help: "Number of requests by path, status code, and method", - labelNames: ["path", "status_code", "method"], + labelNames: ["path", "status_code", "method", "content_encoding"], }), requestDuration: new prom.Histogram({ name: "homestead_request_duration_seconds", @@ -156,38 +156,53 @@ export const server = { transaction.setHttpStatus(304); return new Response("", { status: 304, headers: defaultHeaders }); } - metrics.requests.inc({ - method: request.method, - path: pathname, - status_code: 200, - }); const encodings = (request.headers.get("accept-encoding") || "") .split(",") .map((x) => x.trim().toLowerCase()); if (encodings.includes("br") && files.has(pathname + ".br")) { transaction.setHttpStatus(200); - transaction.setTag("http.content-encoding", "br"); + metrics.requests.inc({ + method: request.method, + path: pathname, + status_code: 200, + content_encoding: "br", + }); return serveFile(files.get(pathname + ".br"), 200, { "content-encoding": "br", "content-type": file.type, }); } else if (encodings.includes("zstd") && files.has(pathname + ".zst")) { transaction.setHttpStatus(200); - transaction.setTag("http.content-encoding", "zstd"); + metrics.requests.inc({ + method: request.method, + path: pathname, + status_code: 200, + content_encoding: "zst", + }); return serveFile(files.get(pathname + ".zst"), 200, { "content-encoding": "zstd", "content-type": file.type, }); } else if (encodings.includes("gzip") && files.has(pathname + ".gz")) { transaction.setHttpStatus(200); - transaction.setTag("http.content-encoding", "gzip"); + metrics.requests.inc({ + method: request.method, + path: pathname, + status_code: 200, + content_encoding: "gzip", + }); return serveFile(files.get(pathname + ".gz"), 200, { "content-encoding": "gzip", "content-type": file.type, }); } transaction.setHttpStatus(200); - transaction.setTag("http.content-encoding", "identity"); + metrics.requests.inc({ + method: request.method, + path: pathname, + status_code: 200, + content_encoding: "identity", + }); return serveFile(file, 200, { "content-type": file.type, }); @@ -208,9 +223,9 @@ export const server = { method: request.method, path: pathname, status_code: 404, + content_encoding: "identity", }); transaction.setHttpStatus(404); - transaction.setTag("http.content-encoding", "identity"); const notfound = files.get("/404.html"); if (notfound) { return serveFile(notfound, 404, { @@ -225,12 +240,12 @@ export const server = { } } } catch (error) { - transaction.setTag("http.content-encoding", "identity"); transaction.setHttpStatus(503); metrics.requests.inc({ method: request.method, path: pathname, status_code: 503, + content_encoding: "identity", }); Sentry.captureException(error); return new Response("Something went wrong", { status: 503 }); -- cgit 1.4.1