[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,
|
eventName: E & string,
|
||||||
rawMetadata: LogEvents[E] & FlatJSONRecord,
|
rawMetadata: LogEvents[E] & FlatJSONRecord,
|
||||||
) {
|
) {
|
||||||
const fullMetadata = {
|
try {
|
||||||
...rawMetadata,
|
const fullMetadata = {
|
||||||
} as Record<string, string> // Statsig typings are unnecessarily strict here.
|
...rawMetadata,
|
||||||
fullMetadata.routeName = getCurrentRouteName() ?? '(Uninitialized)'
|
} as Record<string, string> // Statsig typings are unnecessarily strict here.
|
||||||
Statsig.logEvent(eventName, null, fullMetadata)
|
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) {
|
export function useGate(gateName: string) {
|
||||||
|
|
Loading…
Reference in New Issue