Colocate bitdrift in logger, use logger for transport (#7859)

* Colocate bitdrift in logger, use logger for transport

* Fix mocks, format

* Ok I guess mocks dir doesn't work
This commit is contained in:
Eric Bailey
2025-02-28 12:09:54 -06:00
committed by GitHub
parent f65866c641
commit 1617eb5d66
9 changed files with 15 additions and 23 deletions
+1
View File
@@ -0,0 +1 @@
export {debug, error, info, warn} from '@bitdrift/react-native'
+4
View File
@@ -0,0 +1,4 @@
export function debug() {}
export function error() {}
export function info() {}
export function warn() {}
+28
View File
@@ -0,0 +1,28 @@
import {init, SessionStrategy} from '@bitdrift/react-native'
import {Statsig} from 'statsig-react-native-expo'
import {initPromise} from '#/lib/statsig/statsig'
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,
})
}
})
+4 -1
View File
@@ -6,11 +6,14 @@ import {consoleTransport} from '#/logger/transports/console'
import {sentryTransport} from '#/logger/transports/sentry'
import {LogContext, LogLevel, Metadata, Transport} from '#/logger/types'
import {enabledLogLevels} from '#/logger/util'
import {isNative} from '#/platform/detection'
const TRANSPORTS: Transport[] = (function configureTransports() {
switch (process.env.NODE_ENV) {
case 'production': {
return [sentryTransport, bitdriftTransport].filter(Boolean) as Transport[]
return [sentryTransport, isNative && bitdriftTransport].filter(
Boolean,
) as Transport[]
}
case 'test': {
return []
+6 -11
View File
@@ -1,18 +1,13 @@
import {
debug as bdDebug,
error as bdError,
info as bdInfo,
warn as bdWarn,
} from '#/lib/bitdrift'
import {debug, error, info, warn} from '#/logger/bitdrift/lib'
import {LogLevel, Transport} from '#/logger/types'
import {prepareMetadata} from '#/logger/util'
const logFunctions = {
[LogLevel.Debug]: bdDebug,
[LogLevel.Info]: bdInfo,
[LogLevel.Log]: bdInfo,
[LogLevel.Warn]: bdWarn,
[LogLevel.Error]: bdError,
[LogLevel.Debug]: debug,
[LogLevel.Info]: info,
[LogLevel.Log]: info,
[LogLevel.Warn]: warn,
[LogLevel.Error]: error,
} as const
export const bitdriftTransport: Transport = (