Skip to content

Commit

Permalink
Merge pull request #124 from cloudflare/split-error-logging-from-details
Browse files Browse the repository at this point in the history
Split error logging from details
  • Loading branch information
third774 authored Oct 2, 2024
2 parents 1afe004 + f3744cc commit b8f62d3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
14 changes: 13 additions & 1 deletion app/durableObjects/ChatRoom.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,13 @@ export class ChatRoom extends Server<Env> {
}

onError(connection: Connection, error: unknown): void | Promise<void> {
log({
eventName: 'onErrorHandler',
error,
})
return this.getMeetingId().then((meetingId) => {
log({
eventName: 'onErrorHandler',
eventName: 'onErrorHandlerDetails',
meetingId,
connectionId: connection.id,
error,
Expand Down Expand Up @@ -348,7 +352,15 @@ export class ChatRoom extends Server<Env> {
async cleanupOldConnections() {
const meetingId = await this.getMeetingId()
if (!meetingId) log({ eventName: 'meetingIdNotFoundInCleanup' })
const websockets = this.ctx.getWebSockets()
const connections = [...this.getConnections()]
log({
eventName: 'cleaningUpConnections',
meetingId,
connectionsFound: connections.length,
websocketsFound: websockets.length,
websocketStatuses: websockets.map((w) => w.readyState),
})
const sessionsToCleanUp = await this.getUsers()

connections.forEach((connection) =>
Expand Down
11 changes: 11 additions & 0 deletions app/utils/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ export type LogEvent =
meetingId?: string
connectionId: string
}
| {
eventName: 'cleaningUpConnections'
meetingId?: string
connectionsFound: number
websocketsFound: number
websocketStatuses: number[]
}
| {
eventName: 'userTimedOut'
meetingId?: string
Expand All @@ -41,6 +48,10 @@ export type LogEvent =
}
| {
eventName: 'onErrorHandler'
error: unknown
}
| {
eventName: 'onErrorHandlerDetails'
meetingId?: string
connectionId: string
error: unknown
Expand Down

0 comments on commit b8f62d3

Please sign in to comment.