@@ -20,8 +20,9 @@ function getRequestData(request, response, startTime, endTime) {
2020
2121function  formatRequestData ( data ,  env )  { 
2222  const  url  =  new  URL ( data . url ) ; 
23+   const  formattedUrl  =  url . toString ( ) . replaceAll ( '=' ,  '\\=' ) ; 
2324  // We're setting field value to 1 to count the number of requests 
24-   return  `${ env . INFLUX_METRIC }  ,status_code=${ data . status }  ,hostname=${ url . hostname }  ,pathname="${ url . pathname }  ",method=${ data . method }  ,cf_cache=${ data . cfCache }  ,api_key=${ data . apiKey }   value=1 ${ data . timestamp }  ` 
25+   return  `${ env . INFLUX_METRIC }  ,status_code=${ data . status }  ,url= ${ formattedUrl } , hostname=${ url . hostname }  ,pathname="${ url . pathname }  ",method=${ data . method }  ,cf_cache=${ data . cfCache }  ,api_key=${ data . apiKey }   value=1 ${ data . timestamp }  ` 
2526} 
2627
2728async  function  reportMetric ( request ,  response ,  startTime ,  endTime ,  env )  { 
@@ -53,11 +54,12 @@ export default {
5354    const  url  =  new  URL ( request . url ) ; 
5455    const  newUrl  =  `${ env . REQUEST_URL } ${ url . pathname } ${ url . search }  ` ; 
5556    // override the request with the new URL 
56-     request  =  new  Request ( newUrl ,  request ) ; 
57+     const   newRequest  =  new  Request ( newUrl ,  request ) ; 
5758    const  reqStartTime  =  Date . now ( ) ; 
58-     const  response  =  await  fetch ( request ) ; 
59+     const  response  =  await  fetch ( newRequest ) ; 
5960    const  reqEndTime  =  Date . now ( ) ; 
6061
62+     // report metrics for original request 
6163    ctx . waitUntil ( reportMetric ( request ,  response ,  reqStartTime ,  reqEndTime ,  env ) ) ; 
6264    return  response ; 
6365  } 
0 commit comments