Colocate bitdrift in logger, use logger for transport (#7868)
* Colocate bitdrift in logger, use logger for transport (cherry picked from commitcdd6941fd7) * Fix mocks, format (cherry picked from commit9de88660c6) * Ok I guess mocks dir doesn't work (cherry picked from commit9f37e52011)
This commit is contained in:
@@ -1,30 +0,0 @@
|
||||
import {init, SessionStrategy} from '@bitdrift/react-native'
|
||||
import {Statsig} from 'statsig-react-native-expo'
|
||||
|
||||
import {initPromise} from './statsig/statsig'
|
||||
|
||||
export {debug, error, info, warn} from '@bitdrift/react-native'
|
||||
|
||||
const BITDRIFT_API_KEY = process.env.BITDRIFT_API_KEY
|
||||
|
||||
initPromise.then(() => {
|
||||
let isEnabled = false
|
||||
let isNetworkEnabled = false
|
||||
try {
|
||||
if (Statsig.checkGate('enable_bitdrift_v2')) {
|
||||
isEnabled = true
|
||||
}
|
||||
if (Statsig.checkGate('enable_bitdrift_v2_networking')) {
|
||||
isNetworkEnabled = true
|
||||
}
|
||||
} catch (e) {
|
||||
// Statsig may complain about it being called too early.
|
||||
}
|
||||
if (isEnabled && BITDRIFT_API_KEY) {
|
||||
init(BITDRIFT_API_KEY, SessionStrategy.Activity, {
|
||||
url: 'https://api-bsky.bitdrift.io',
|
||||
// Only effects iOS, Android instrumentation is set via Gradle Plugin
|
||||
enableNetworkInstrumentation: isNetworkEnabled,
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -1,4 +0,0 @@
|
||||
export function debug() {}
|
||||
export function error() {}
|
||||
export function info() {}
|
||||
export function warn() {}
|
||||
@@ -4,7 +4,6 @@ import {AppState, AppStateStatus} from 'react-native'
|
||||
import {Statsig, StatsigProvider} from 'statsig-react-native-expo'
|
||||
|
||||
import {BUNDLE_DATE, BUNDLE_IDENTIFIER, IS_TESTFLIGHT} from '#/lib/app-info'
|
||||
import * as bitdrift from '#/lib/bitdrift'
|
||||
import {logger} from '#/logger'
|
||||
import {isWeb} from '#/platform/detection'
|
||||
import * as persisted from '#/state/persisted'
|
||||
@@ -102,11 +101,7 @@ export function logEvent<E extends keyof LogEvents>(
|
||||
if (Statsig.initializeCalled()) {
|
||||
Statsig.logEvent(eventName, null, fullMetadata)
|
||||
}
|
||||
// Intentionally bypass the logger abstraction to log rich objects.
|
||||
console.groupCollapsed(eventName)
|
||||
console.log(fullMetadata)
|
||||
console.groupEnd()
|
||||
bitdrift.info(eventName, fullMetadata)
|
||||
logger.info(eventName, fullMetadata)
|
||||
} catch (e) {
|
||||
// A log should never interrupt the calling code, whatever happens.
|
||||
logger.error('Failed to log an event', {message: e})
|
||||
|
||||
Reference in New Issue
Block a user