[Statsig] Protect against early logEvent call crashing (#3315)
* [Statsig] Check if initialized * Never interrupt the callerzio/stable
parent
7503d83eaa
commit
55fb81867b
|
@ -46,12 +46,22 @@ export function logEvent<E extends keyof LogEvents>(
|
|||
eventName: E & string,
|
||||
rawMetadata: LogEvents[E] & FlatJSONRecord,
|
||||
) {
|
||||
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) {
|
||||
const {isLoading, value} = useStatsigGate(gateName)
|
||||
|
|
Loading…
Reference in New Issue