Skip to content

Commit

Permalink
Add fallback UUID for instance ID in analytics event
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeknovy committed Sep 18, 2024
1 parent f51fd69 commit 7c6f007
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/server/utils/analytics/anyltics-event.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { analytics } from "../analytics"
import { db } from "../../../db/db"
import { logger } from "../../../logger"
import { v4 as uuidv4 } from "uuid"

let INSTANCE_ID = null
const FALLBACK_ID = uuidv4()

export class AnalyticsEvent {

Expand All @@ -11,14 +13,16 @@ export class AnalyticsEvent {
return INSTANCE_ID
}
try {
console.info("AnalyticsEvent.getInstanceId() called")
const result = await db.oneOrNone("SELECT instance FROM jtl.global")
if (result && result.instance) {
INSTANCE_ID = result.instance
return INSTANCE_ID
}
return INSTANCE_ID
return FALLBACK_ID

} catch(error) {
logger.info("Instance id could not be loaded " + error)
return FALLBACK_ID
}

}
Expand Down

0 comments on commit 7c6f007

Please sign in to comment.