File tree Expand file tree Collapse file tree 4 files changed +19
-9
lines changed Expand file tree Collapse file tree 4 files changed +19
-9
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @cloudflare/workers-shared " : minor
3+ ---
4+
5+ Fixes bug where indexId was never set for router-worker and asset-worker
Original file line number Diff line number Diff line change @@ -48,15 +48,15 @@ export class Analytics {
4848 return this . data [ key ] ;
4949 }
5050
51- write ( hostname ?: string ) {
51+ write ( ) {
5252 if ( ! this . readyAnalytics ) {
5353 return ;
5454 }
5555
5656 this . readyAnalytics . logEvent ( {
5757 version : VERSION ,
5858 accountId : 0 , // TODO: need to plumb through
59- indexId : hostname ,
59+ indexId : this . data . hostname ?. substring ( 0 , 96 ) ,
6060 doubles : [
6161 this . data . requestTime ?? - 1 , // double1
6262 this . data . coloId ?? - 1 , // double2
Original file line number Diff line number Diff line change 1- import type { Environment , ReadyAnalytics } from "./types" ;
1+ import type { ReadyAnalytics } from "./types" ;
22
33// This will allow us to make breaking changes to the analytic schema
44const VERSION = 1 ;
@@ -35,6 +35,11 @@ type Data = {
3535
3636export class Analytics {
3737 private data : Data = { } ;
38+ private readyAnalytics ?: ReadyAnalytics ;
39+
40+ constructor ( readyAnalytics ?: ReadyAnalytics ) {
41+ this . readyAnalytics = readyAnalytics ;
42+ }
3843
3944 setData ( newData : Partial < Data > ) {
4045 this . data = { ...this . data , ...newData } ;
@@ -44,15 +49,15 @@ export class Analytics {
4449 return this . data [ key ] ;
4550 }
4651
47- write ( env : Environment , readyAnalytics ?: ReadyAnalytics , hostname ?: string ) {
48- if ( ! readyAnalytics ) {
52+ write ( ) {
53+ if ( ! this . readyAnalytics ) {
4954 return ;
5055 }
5156
52- readyAnalytics . logEvent ( {
57+ this . readyAnalytics . logEvent ( {
5358 version : VERSION ,
5459 accountId : 0 , // TODO: need to plumb through
55- indexId : hostname ,
60+ indexId : this . data . hostname ?. substring ( 0 , 96 ) ,
5661 doubles : [
5762 this . data . requestTime ?? - 1 , // double1
5863 this . data . coloId ?? - 1 , // double2
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ interface Env {
2424export default {
2525 async fetch ( request : Request , env : Env , ctx : ExecutionContext ) {
2626 let sentry : ReturnType < typeof setupSentry > | undefined ;
27- const analytics = new Analytics ( ) ;
27+ const analytics = new Analytics ( env . ANALYTICS ) ;
2828 const performance = new PerformanceTimer ( env . UNSAFE_PERFORMANCE ) ;
2929 const startTimeMs = performance . now ( ) ;
3030
@@ -80,7 +80,7 @@ export default {
8080 throw err ;
8181 } finally {
8282 analytics . setData ( { requestTime : performance . now ( ) - startTimeMs } ) ;
83- analytics . write ( env . ENVIRONMENT , env . ANALYTICS ) ;
83+ analytics . write ( ) ;
8484 }
8585 } ,
8686} ;
You can’t perform that action at this time.
0 commit comments