File tree Expand file tree Collapse file tree 3 files changed +15
-0
lines changed
packages/workers-shared/router-worker/src Expand file tree Collapse file tree 3 files changed +15
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @cloudflare/workers-shared " : patch
3+ ---
4+
5+ Adds metrics for time-to-dispatch to Router Worker
Original file line number Diff line number Diff line change @@ -37,6 +37,8 @@ type Data = {
3737 abuseMitigationBlocked ?: boolean ;
3838 // double8 - User worker invocation denied due to free tier limiting
3939 userWorkerFreeTierLimiting ?: boolean ;
40+ // double9 - The time it takes for the request to be handed off the Asset Worker or user Worker in milliseconds
41+ timeToDispatch ?: number ;
4042
4143 // -- Blobs --
4244 // blob1 - Hostname of the request
@@ -96,6 +98,7 @@ export class Analytics {
9698 this . data . staticRoutingDecision ?? STATIC_ROUTING_DECISION . NOT_PROVIDED , // double6
9799 this . data . abuseMitigationBlocked ? 1 : 0 , // double7
98100 this . data . userWorkerFreeTierLimiting ? 1 : 0 , // double8
101+ this . data . timeToDispatch ?? - 1 , // double9
99102 ] ,
100103 blobs : [
101104 this . data . hostname ?. substring ( 0 , 256 ) , // blob1 - trim to 256 bytes
Original file line number Diff line number Diff line change @@ -130,6 +130,10 @@ export default {
130130 }
131131 }
132132
133+ analytics . setData ( {
134+ timeToDispatch : performance . now ( ) - startTimeMs ,
135+ } ) ;
136+
133137 if ( shouldBlockNonImageResponse ) {
134138 const resp = await env . USER_WORKER . fetch ( maybeSecondRequest ) ;
135139 const isImage = resp . headers
@@ -160,6 +164,9 @@ export default {
160164 dispatchType : DISPATCH_TYPE . ASSETS ,
161165 } ) ;
162166
167+ analytics . setData ( {
168+ timeToDispatch : performance . now ( ) - startTimeMs ,
169+ } ) ;
163170 return env . ASSET_WORKER . fetch ( maybeSecondRequest ) ;
164171 } ) ;
165172 } ;
You can’t perform that action at this time.
0 commit comments