[Statsig] Protect against early logEvent call crashing (#3315)
* [Statsig] Check if initialized * Never interrupt the callerzio/stable
parent
7503d83eaa
commit
55fb81867b
|
@ -46,11 +46,21 @@ export function logEvent<E extends keyof LogEvents>(
|
|||
eventName: E & string,
|
||||
rawMetadata: LogEvents[E] & FlatJSONRecord,
|
||||
) {
|
||||
const fullMetadata = {
|
||||
...rawMetadata,
|
||||
} as Record<string, string> // Statsig typings are unnecessarily strict here.
|
||||
fullMetadata.routeName = getCurrentRouteName() ?? '(Uninitialized)'
|
||||
Statsig.logEvent(eventName, null, fullMetadata)
|
||||
try {
|
||||
const fullMetadata = {
|
||||
...rawMetadata,
|
||||
} as Record<string, string> // Statsig typings are unnecessarily strict here.
|
||||
fullMetadata.routeName = getCurrentRouteName() ?? '(Uninitialized)'
|
||||
if (Statsig.initializeCalled()) {
|
||||
Statsig.logEvent(eventName, null, fullMetadata)
|
||||
}
|
||||
} catch (e) {
|
||||
// A log should never interrupt the calling code, whatever happens.
|
||||
// Rethrow on a clean stack.
|
||||
setTimeout(() => {
|
||||
throw e
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export function useGate(gateName: string) {
|
||||
|
|
Loading…
Reference in New Issue