about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAlan Pearce2023-09-25 14:03:41 +0200
committerAlan Pearce2023-09-25 14:03:41 +0200
commit5b37033b1623ad5c3b8fd89b1ee85b04b1811609 (patch)
treed72a80d55076273d7850f55b3572302c0c4fba5a
parent59867fca4c1a377aea90eb89f86d3ad01083b7c4 (diff)
downloadwebsite-5b37033b1623ad5c3b8fd89b1ee85b04b1811609.tar.lz
website-5b37033b1623ad5c3b8fd89b1ee85b04b1811609.tar.zst
website-5b37033b1623ad5c3b8fd89b1ee85b04b1811609.zip
Send content_encoding metrics to prometheus instead of sentry
-rw-r--r--src/app.ts39
1 files 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 });