Compare commits

...

10 Commits

Author SHA1 Message Date
Dan Abramov 6be6fa4ab4 Revert "Bump the limit"
This reverts commit afa4254e01.
2024-07-10 00:39:50 +01:00
Dan Abramov dbaa793ed4 Merge branch 'session-error-stack' into session-stress 2024-07-10 00:29:12 +01:00
Dan Abramov afa4254e01 Bump the limit 2024-07-10 00:28:58 +01:00
Dan Abramov c9ca15e815 [Session] Include stack with the debug event 2024-07-10 00:25:30 +01:00
Dan Abramov c291045f42 Merge branch 'main' into session-stress 2024-07-10 00:16:25 +01:00
Dan Abramov f382efcbab Merge branch 'session-event-twk' into session-stress 2024-07-09 22:56:28 +01:00
Dan Abramov 2cd98e9ee8 Rename session event, scope to errors 2024-07-09 22:54:42 +01:00
Dan Abramov 3432868a2d Merge branch 'log-session-events' into session-stress 2024-07-09 20:08:08 +01:00
Dan Abramov 1d8e954eff Log session events unconditionally 2024-07-09 20:07:37 +01:00
Dan Abramov 551e68439c stress test 2024-07-09 19:43:32 +01:00
5 changed files with 82 additions and 6 deletions
+4 -1
View File
@@ -51,7 +51,10 @@ async function fetchHandler(
const res = await fetch(reqUri, {
method: reqMethod,
headers: reqHeaders,
headers: {
...reqHeaders,
'x-bsky-entryway': 'short-session'
},
body: reqBody,
signal: controller.signal,
})
+67 -1
View File
@@ -1,3 +1,69 @@
import {BskyAgent, jsonToLex, stringifyLex} from '@atproto/api'
const GET_TIMEOUT = 15e3 // 15s
const POST_TIMEOUT = 60e3 // 60s
export function doPolyfill() {
// no polyfill is needed on web
BskyAgent.configure({fetch: fetchHandler})
}
interface FetchHandlerResponse {
status: number
headers: Record<string, string>
body: any
}
async function fetchHandler(
reqUri: string,
reqMethod: string,
reqHeaders: Record<string, string>,
reqBody: any,
): Promise<FetchHandlerResponse> {
const reqMimeType = reqHeaders['Content-Type'] || reqHeaders['content-type']
if (reqMimeType && reqMimeType.startsWith('application/json')) {
reqBody = stringifyLex(reqBody)
}
const controller = new AbortController()
const to = setTimeout(
() => controller.abort(),
reqMethod === 'post' ? POST_TIMEOUT : GET_TIMEOUT,
)
const res = await fetch(reqUri, {
method: reqMethod,
headers: {
...reqHeaders,
'x-bsky-entryway': 'short-session'
},
body: reqBody,
signal: controller.signal,
})
const resStatus = res.status
const resHeaders: Record<string, string> = {}
res.headers.forEach((value: string, key: string) => {
resHeaders[key] = value
})
const resMimeType = resHeaders['Content-Type'] || resHeaders['content-type']
let resBody
if (resMimeType) {
if (resMimeType.startsWith('application/json')) {
resBody = jsonToLex(await res.json())
} else if (resMimeType.startsWith('text/')) {
resBody = await res.text()
} else if (resMimeType === 'application/vnd.ipld.car') {
resBody = await res.arrayBuffer()
} else {
throw new Error('Non-supported mime type')
}
}
clearTimeout(to)
return {
status: resStatus,
headers: resHeaders,
body: resBody,
}
}
+3 -2
View File
@@ -37,7 +37,7 @@ export function useFeedFeedback(feed: FeedDescriptor, hasSession: boolean) {
const aggregatedStats = React.useRef<AggregatedStats | null>(null)
const throttledFlushAggregatedStats = React.useMemo(
() =>
throttle(() => flushToStatsig(aggregatedStats.current), 45e3, {
throttle(() => flushToStatsig(aggregatedStats.current), 5e3, {
leading: true, // The outer call is already throttled somewhat.
trailing: true,
}),
@@ -71,6 +71,7 @@ export function useFeedFeedback(feed: FeedDescriptor, hasSession: boolean) {
// TODO when we start sending to other feeds, we need to grab their DID -prf
'did:web:discover.bsky.app',
) as BskyAgent
proxyAgent.app.bsky.feed
.sendInteractions({interactions})
.catch((e: any) => {
@@ -88,7 +89,7 @@ export function useFeedFeedback(feed: FeedDescriptor, hasSession: boolean) {
const sendToFeed = React.useMemo(
() =>
throttle(sendToFeedNoDelay, 15e3, {
throttle(sendToFeedNoDelay, 1e3, {
leading: false,
trailing: true,
}),
+7 -1
View File
@@ -76,13 +76,19 @@ export function addSessionErrorLog(did: string, event: AtpSessionEvent) {
if (!Statsig.initializeCalled() || !Statsig.getStableID()) {
return
}
Statsig.logEvent('session:error', null, {did, event})
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) {
console.log(new Date(), log)
try {
if (!Statsig.initializeCalled() || !Statsig.getStableID()) {
// Drop these logs for now.
+1 -1
View File
@@ -31,7 +31,7 @@ export type ListProps<ItemT> = Omit<
}
export type ListRef = React.MutableRefObject<any | null> // TODO: Better types.
const ON_ITEM_SEEN_WAIT_DURATION = 1.5e3 // when we consider post to be "seen"
const ON_ITEM_SEEN_WAIT_DURATION = 100 // when we consider post to be "seen"
const ON_ITEM_SEEN_INTERSECTION_OPTS = {
rootMargin: '-200px 0px -200px 0px',
} // post must be 200px visible to be "seen"