An ATproto social media client -- with an independent Appview.
7
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: remove events.bsky.app / sentry logging initialisation (#26)

authored by

Lyna and committed by
GitHub
d5e30bc4 ec21a578

+8 -88
+5 -82
src/lib/statsig/statsig.tsx
··· 1 1 import React from 'react' 2 - import {Platform} from 'react-native' 3 - import {AppState, type AppStateStatus} from 'react-native' 4 - import {Statsig, StatsigProvider} from 'statsig-react-native-expo' 2 + import {AppState, type AppStateStatus, Platform} from 'react-native' 3 + import {Statsig} from 'statsig-react-native-expo' 5 4 6 5 import {logger} from '#/logger' 7 6 import {type MetricEvents} from '#/logger/metrics' 8 7 import {isWeb} from '#/platform/detection' 9 8 import * as persisted from '#/state/persisted' 10 9 import * as env from '#/env' 11 - import {useSession} from '../../state/session' 12 10 import {timeout} from '../async/timeout' 13 - import {useNonReactiveCallback} from '../hooks/useNonReactiveCallback' 14 11 import {type Gate} from './gates' 15 - 16 - const SDK_KEY = 'client-SXJakO39w9vIhl3D44u8UupyzFl4oZ2qPIkjwcvuPsV' 17 12 18 13 export const initPromise = initialize() 19 14 ··· 44 39 } 45 40 46 41 export type {MetricEvents as LogEvents} 47 - 48 - function createStatsigOptions(prefetchUsers: StatsigUser[]) { 49 - return { 50 - environment: { 51 - tier: env.IS_DEV 52 - ? 'development' 53 - : env.IS_TESTFLIGHT 54 - ? 'staging' 55 - : 'production', 56 - }, 57 - // Don't block on waiting for network. The fetched config will kick in on next load. 58 - // This ensures the UI is always consistent and doesn't update mid-session. 59 - // Note this makes cold load (no local storage) and private mode return `false` for all gates. 60 - initTimeoutMs: 1, 61 - // Get fresh flags for other accounts as well, if any. 62 - prefetchUsers, 63 - api: 'https://events.bsky.app/v2', 64 - } 65 - } 66 42 67 43 type FlatJSONRecord = Record< 68 44 string, ··· 265 241 } 266 242 267 243 export function initialize() { 268 - return Statsig.initialize(SDK_KEY, null, createStatsigOptions([])) 244 + return new Promise(() => {}) 269 245 } 270 246 271 247 export function Provider({children}: {children: React.ReactNode}) { 272 - const {currentAccount, accounts} = useSession() 273 - const did = currentAccount?.did 274 - const currentStatsigUser = React.useMemo(() => toStatsigUser(did), [did]) 275 - 276 - const otherDidsConcatenated = accounts 277 - .map(account => account.did) 278 - .filter(accountDid => accountDid !== did) 279 - .join(' ') // We're only interested in DID changes. 280 - const otherStatsigUsers = React.useMemo( 281 - () => otherDidsConcatenated.split(' ').map(toStatsigUser), 282 - [otherDidsConcatenated], 283 - ) 284 - const statsigOptions = React.useMemo( 285 - () => createStatsigOptions(otherStatsigUsers), 286 - [otherStatsigUsers], 287 - ) 288 - 289 - // Have our own cache in front of Statsig. 290 - // This ensures the results remain stable until the active DID changes. 291 - const [gateCache, setGateCache] = React.useState(() => new Map()) 292 - const [prevDid, setPrevDid] = React.useState(did) 293 - if (did !== prevDid) { 294 - setPrevDid(did) 295 - setGateCache(new Map()) 296 - } 297 - 298 - // Periodically poll Statsig to get the current rule evaluations for all stored accounts. 299 - // These changes are prefetched and stored, but don't get applied until the active DID changes. 300 - // This ensures that when you switch an account, it already has fresh results by then. 301 - const handleIntervalTick = useNonReactiveCallback(() => { 302 - if (Statsig.initializeCalled()) { 303 - // Note: Only first five will be taken into account by Statsig. 304 - Statsig.prefetchUsers([currentStatsigUser, ...otherStatsigUsers]) 305 - } 306 - }) 307 - React.useEffect(() => { 308 - const id = setInterval(handleIntervalTick, 60e3 /* 1 min */) 309 - return () => clearInterval(id) 310 - }, [handleIntervalTick]) 311 - 312 - return ( 313 - <GateCache.Provider value={gateCache}> 314 - <StatsigProvider 315 - key={did} 316 - sdkKey={SDK_KEY} 317 - mountKey={currentStatsigUser.userID} 318 - user={currentStatsigUser} 319 - // This isn't really blocking due to short initTimeoutMs above. 320 - // However, it ensures `isLoading` is always `false`. 321 - waitForInitialization={true} 322 - options={statsigOptions}> 323 - {children} 324 - </StatsigProvider> 325 - </GateCache.Provider> 326 - ) 248 + const [gateCache] = React.useState(() => new Map()) 249 + return <GateCache.Provider value={gateCache}>{children}</GateCache.Provider> 327 250 }
+3 -6
src/logger/index.ts
··· 3 3 import {logEvent} from '#/lib/statsig/statsig' 4 4 import {add} from '#/logger/logDump' 5 5 import {type MetricEvents} from '#/logger/metrics' 6 - import {bitdriftTransport} from '#/logger/transports/bitdrift' 7 6 import {consoleTransport} from '#/logger/transports/console' 8 - import {sentryTransport} from '#/logger/transports/sentry' 9 7 import { 10 8 LogContext, 11 9 LogLevel, ··· 13 11 type Transport, 14 12 } from '#/logger/types' 15 13 import {enabledLogLevels} from '#/logger/util' 16 - import {isNative} from '#/platform/detection' 17 14 import {ENV} from '#/env' 18 15 19 16 const TRANSPORTS: Transport[] = (function configureTransports() { 20 17 switch (ENV) { 21 18 case 'production': { 22 - return [sentryTransport, isNative && bitdriftTransport].filter( 23 - Boolean, 24 - ) as Transport[] 19 + // return [sentryTransport, isNative && bitdriftTransport].filter( 20 + // Boolean, 21 + // ) as Transport[] 25 22 } 26 23 case 'test': { 27 24 return []