Clean up some logging

This commit is contained in:
Eric Bailey
2026-01-19 13:49:16 -06:00
parent 7c4258f8a8
commit 0281a0e160
13 changed files with 39 additions and 318 deletions
+4 -3
View File
@@ -1,5 +1,4 @@
import '#/logger/sentry/setup'
import '#/logger/bitdrift/setup'
import '#/view/icons'
import React, {useEffect, useState} from 'react'
@@ -66,8 +65,10 @@ import {Provider as PolicyUpdateOverlayProvider} from '#/components/PolicyUpdate
import {Provider as PortalProvider} from '#/components/Portal'
import {Provider as VideoVolumeProvider} from '#/components/Post/Embed/VideoEmbed/VideoVolumeContext'
import {ToastOutlet} from '#/components/Toast'
import {Provider as AgeAssuranceV2Provider} from '#/ageAssurance'
import {prefetchAgeAssuranceConfig} from '#/ageAssurance'
import {
prefetchAgeAssuranceConfig,
Provider as AgeAssuranceV2Provider,
} from '#/ageAssurance'
import {IS_ANDROID, IS_IOS} from '#/env'
import {
prefetchLiveEvents,
-1
View File
@@ -1 +0,0 @@
export {debug, error, info, warn} from '@bitdrift/react-native'
-4
View File
@@ -1,4 +0,0 @@
export function debug() {}
export function error() {}
export function info() {}
export function warn() {}
-27
View File
@@ -1,27 +0,0 @@
import {init, SessionStrategy} from '@bitdrift/react-native'
import {Statsig} from 'statsig-react-native-expo'
import {initPromise} from '#/lib/statsig/statsig'
import {BITDRIFT_API_KEY} from '#/env'
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 -5
View File
@@ -3,7 +3,6 @@ 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 {
@@ -13,7 +12,6 @@ import {
type Transport,
} from '#/logger/types'
import {enabledLogLevels} from '#/logger/util'
import {IS_NATIVE} from '#/env'
import {ENV} from '#/env'
export {type MetricEvents as Metrics} from '#/logger/metrics'
@@ -21,9 +19,7 @@ export {type MetricEvents as Metrics} from '#/logger/metrics'
const TRANSPORTS: Transport[] = (function configureTransports() {
switch (ENV) {
case 'production': {
return [sentryTransport, IS_NATIVE && bitdriftTransport].filter(
Boolean,
) as Transport[]
return [sentryTransport].filter(Boolean)
}
case 'test': {
return []
-24
View File
@@ -1,24 +0,0 @@
import {debug, error, info, warn} from '#/logger/bitdrift/lib'
import {LogLevel, type Transport} from '#/logger/types'
import {prepareMetadata} from '#/logger/util'
const logFunctions = {
[LogLevel.Debug]: debug,
[LogLevel.Info]: info,
[LogLevel.Log]: info,
[LogLevel.Warn]: warn,
[LogLevel.Error]: error,
} as const
export const bitdriftTransport: Transport = (
level,
context,
message,
metadata,
) => {
const log = logFunctions[level]
log(message.toString(), {
__context__: context,
...prepareMetadata(metadata),
})
}
+6 -92
View File
@@ -1,8 +1,5 @@
import {type AtpSessionData, type AtpSessionEvent} from '@atproto/api'
import {sha256} from 'js-sha256'
import {Statsig} from 'statsig-react-native-expo'
import {IS_INTERNAL} from '#/env'
import {type Schema} from '../persisted'
import {type Action, type State} from './reducer'
import {type SessionAccount} from './types'
@@ -68,92 +65,9 @@ export function wrapSessionReducerForLogging(reducer: Reducer): Reducer {
}
}
let nextMessageIndex = 0
const MAX_SLICE_LENGTH = 1000
// Not gated.
export function addSessionErrorLog(did: string, event: AtpSessionEvent) {
try {
if (!Statsig.initializeCalled() || !Statsig.getStableID()) {
return
}
const stack = (new Error().stack ?? '').slice(0, MAX_SLICE_LENGTH)
Statsig.logEvent('session:error', null, {
did,
event,
stack,
})
} catch (e) {
console.error(e)
}
}
export function addSessionDebugLog(log: Log) {
try {
if (!Statsig.initializeCalled() || !Statsig.getStableID()) {
// Drop these logs for now.
return
}
// DISABLING THIS GATE DUE TO EME @TODO EME-GATE
if (!IS_INTERNAL) {
return
}
// if (!Statsig.checkGate('debug_session')) {
// return
// }
const messageIndex = nextMessageIndex++
const {type, ...content} = log
let payload = JSON.stringify(content, replacer)
let nextSliceIndex = 0
while (payload.length > 0) {
const sliceIndex = nextSliceIndex++
const slice = payload.slice(0, MAX_SLICE_LENGTH)
payload = payload.slice(MAX_SLICE_LENGTH)
Statsig.logEvent('session:debug', null, {
realmId,
messageIndex: String(messageIndex),
messageType: type,
sliceIndex: String(sliceIndex),
slice,
})
}
} catch (e) {
console.error(e)
}
}
let agentIds = new WeakMap<object, string>()
let realmId = Math.random().toString(36).slice(2)
let nextAgentId = 1
function getAgentId(agent: object) {
let id = agentIds.get(agent)
if (id === undefined) {
id = realmId + '::' + nextAgentId++
agentIds.set(agent, id)
}
return id
}
function replacer(key: string, value: unknown) {
if (typeof value === 'object' && value != null && 'api' in value) {
return getAgentId(value)
}
if (
key === 'service' ||
key === 'email' ||
key === 'emailConfirmed' ||
key === 'emailAuthFactor' ||
key === 'pdsUrl'
) {
return undefined
}
if (
typeof value === 'string' &&
(key === 'refreshJwt' || key === 'accessJwt')
) {
return sha256(value)
}
return value
}
/**
* Stubs, previously used to log session errors to Statsig. We may revive this
* using Sentry or Bitdrift in the future.
*/
export function addSessionErrorLog(_did: string, _event: AtpSessionEvent) {}
export function addSessionDebugLog(_log: Log) {}