From 7a476568168fa897d3dc9fcae3c1f77d4363366e Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 9 Jul 2024 21:13:32 +0100 Subject: [PATCH] Log session events unconditionally (#4758) --- src/state/session/agent.ts | 2 ++ src/state/session/logging.ts | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/state/session/agent.ts b/src/state/session/agent.ts index 4bcb4c11..d31b5588 100644 --- a/src/state/session/agent.ts +++ b/src/state/session/agent.ts @@ -12,6 +12,7 @@ import {tryFetchGates} from '#/lib/statsig/statsig' import {getAge} from '#/lib/strings/time' import {logger} from '#/logger' import {snoozeEmailConfirmationPrompt} from '#/state/shell/reminders' +import {addSessionEventLog} from './logging' import { configureModerationForAccount, configureModerationForGuest, @@ -194,6 +195,7 @@ async function prepareAgent( const account = agentToSessionAccountOrThrow(agent) agent.setPersistSessionHandler(event => { onSessionChange(agent, account.did, event) + addSessionEventLog(account.did, event) }) return {agent, account} } diff --git a/src/state/session/logging.ts b/src/state/session/logging.ts index 16aa66fe..ab67785c 100644 --- a/src/state/session/logging.ts +++ b/src/state/session/logging.ts @@ -1,4 +1,4 @@ -import {AtpSessionData} from '@atproto/api' +import {AtpSessionData, AtpSessionEvent} from '@atproto/api' import {sha256} from 'js-sha256' import {Statsig} from 'statsig-react-native-expo' @@ -70,6 +70,18 @@ export function wrapSessionReducerForLogging(reducer: Reducer): Reducer { let nextMessageIndex = 0 const MAX_SLICE_LENGTH = 1000 +// Not gated. +export function addSessionEventLog(did: string, event: AtpSessionEvent) { + try { + if (!Statsig.initializeCalled() || !Statsig.getStableID()) { + return + } + Statsig.logEvent('session:event', null, {did, event}) + } catch (e) { + console.error(e) + } +} + export function addSessionDebugLog(log: Log) { try { if (!Statsig.initializeCalled() || !Statsig.getStableID()) {