From d5e30bc4270af1e54ba5f129c6de9eec08fc7e86 Mon Sep 17 00:00:00 2001 From: Lyna <19539165+Blooym@users.noreply.github.com> Date: Thu, 25 Sep 2025 16:58:31 +0100 Subject: [PATCH] refactor: remove events.bsky.app / sentry logging initialisation (#26) --- src/lib/statsig/statsig.tsx | 87 +++---------------------------------- src/logger/index.ts | 9 ++-- 2 files changed, 8 insertions(+), 88 deletions(-) diff --git a/src/lib/statsig/statsig.tsx b/src/lib/statsig/statsig.tsx index 860e841eb..2f18c071f 100644 --- a/src/lib/statsig/statsig.tsx +++ b/src/lib/statsig/statsig.tsx @@ -1,20 +1,15 @@ import React from 'react' -import {Platform} from 'react-native' -import {AppState, type AppStateStatus} from 'react-native' -import {Statsig, StatsigProvider} from 'statsig-react-native-expo' +import {AppState, type AppStateStatus, Platform} from 'react-native' +import {Statsig} from 'statsig-react-native-expo' import {logger} from '#/logger' import {type MetricEvents} from '#/logger/metrics' import {isWeb} from '#/platform/detection' import * as persisted from '#/state/persisted' import * as env from '#/env' -import {useSession} from '../../state/session' import {timeout} from '../async/timeout' -import {useNonReactiveCallback} from '../hooks/useNonReactiveCallback' import {type Gate} from './gates' -const SDK_KEY = 'client-SXJakO39w9vIhl3D44u8UupyzFl4oZ2qPIkjwcvuPsV' - export const initPromise = initialize() type StatsigUser = { @@ -45,25 +40,6 @@ if (isWeb && typeof window !== 'undefined') { export type {MetricEvents as LogEvents} -function createStatsigOptions(prefetchUsers: StatsigUser[]) { - return { - environment: { - tier: env.IS_DEV - ? 'development' - : env.IS_TESTFLIGHT - ? 'staging' - : 'production', - }, - // Don't block on waiting for network. The fetched config will kick in on next load. - // This ensures the UI is always consistent and doesn't update mid-session. - // Note this makes cold load (no local storage) and private mode return `false` for all gates. - initTimeoutMs: 1, - // Get fresh flags for other accounts as well, if any. - prefetchUsers, - api: 'https://events.bsky.app/v2', - } -} - type FlatJSONRecord = Record< string, | string @@ -265,63 +241,10 @@ export async function tryFetchGates( } export function initialize() { - return Statsig.initialize(SDK_KEY, null, createStatsigOptions([])) + return new Promise(() => {}) } export function Provider({children}: {children: React.ReactNode}) { - const {currentAccount, accounts} = useSession() - const did = currentAccount?.did - const currentStatsigUser = React.useMemo(() => toStatsigUser(did), [did]) - - const otherDidsConcatenated = accounts - .map(account => account.did) - .filter(accountDid => accountDid !== did) - .join(' ') // We're only interested in DID changes. - const otherStatsigUsers = React.useMemo( - () => otherDidsConcatenated.split(' ').map(toStatsigUser), - [otherDidsConcatenated], - ) - const statsigOptions = React.useMemo( - () => createStatsigOptions(otherStatsigUsers), - [otherStatsigUsers], - ) - - // Have our own cache in front of Statsig. - // This ensures the results remain stable until the active DID changes. - const [gateCache, setGateCache] = React.useState(() => new Map()) - const [prevDid, setPrevDid] = React.useState(did) - if (did !== prevDid) { - setPrevDid(did) - setGateCache(new Map()) - } - - // Periodically poll Statsig to get the current rule evaluations for all stored accounts. - // These changes are prefetched and stored, but don't get applied until the active DID changes. - // This ensures that when you switch an account, it already has fresh results by then. - const handleIntervalTick = useNonReactiveCallback(() => { - if (Statsig.initializeCalled()) { - // Note: Only first five will be taken into account by Statsig. - Statsig.prefetchUsers([currentStatsigUser, ...otherStatsigUsers]) - } - }) - React.useEffect(() => { - const id = setInterval(handleIntervalTick, 60e3 /* 1 min */) - return () => clearInterval(id) - }, [handleIntervalTick]) - - return ( - - - {children} - - - ) + const [gateCache] = React.useState(() => new Map()) + return {children} } diff --git a/src/logger/index.ts b/src/logger/index.ts index 998d02581..8ee85443b 100644 --- a/src/logger/index.ts +++ b/src/logger/index.ts @@ -3,9 +3,7 @@ import {nanoid} from 'nanoid/non-secure' import {logEvent} from '#/lib/statsig/statsig' import {add} from '#/logger/logDump' import {type MetricEvents} from '#/logger/metrics' -import {bitdriftTransport} from '#/logger/transports/bitdrift' import {consoleTransport} from '#/logger/transports/console' -import {sentryTransport} from '#/logger/transports/sentry' import { LogContext, LogLevel, @@ -13,15 +11,14 @@ import { type Transport, } from '#/logger/types' import {enabledLogLevels} from '#/logger/util' -import {isNative} from '#/platform/detection' import {ENV} from '#/env' const TRANSPORTS: Transport[] = (function configureTransports() { switch (ENV) { case 'production': { - return [sentryTransport, isNative && bitdriftTransport].filter( - Boolean, - ) as Transport[] + // return [sentryTransport, isNative && bitdriftTransport].filter( + // Boolean, + // ) as Transport[] } case 'test': { return [] -- 2.51.2