Skip to content

Commit 59eda4a

Browse files
authored
Add status code analytics to router-worker (#8126)
1 parent 8e6ede5 commit 59eda4a

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

.changeset/odd-months-crash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudflare/workers-shared": minor
3+
---
4+
5+
chore: Add status code analytics to router-worker

packages/workers-shared/asset-worker/src/analytics.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ type Data = {
1818
metalId?: number;
1919
// double4 - Colo tier (e.g. tier 1, tier 2, tier 3)
2020
coloTier?: number;
21+
// double5 - Response status code
22+
status?: number;
2123

2224
// -- Blobs --
2325
// blob1 - Hostname of the request
@@ -66,6 +68,7 @@ export class Analytics {
6668
this.data.coloId ?? -1, // double2
6769
this.data.metalId ?? -1, // double3
6870
this.data.coloTier ?? -1, // double4
71+
this.data.status ?? -1, // double5
6972
],
7073
blobs: [
7174
this.data.hostname?.substring(0, 256), // blob1 - trim to 256 bytes

packages/workers-shared/asset-worker/src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,17 @@ export default class extends WorkerEntrypoint<Env> {
117117
version: this.env.VERSION_METADATA?.id,
118118
});
119119

120-
return handleRequest(
120+
const response = await handleRequest(
121121
request,
122122
this.env,
123123
config,
124124
this.unstable_exists.bind(this),
125125
this.unstable_getByETag.bind(this)
126126
);
127+
128+
analytics.setData({ status: response.status });
129+
130+
return response;
127131
});
128132
} catch (err) {
129133
return this.handleError(sentry, analytics, err);

0 commit comments

Comments
 (0)