Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Improved instrumentation around core functions #17574

Merged
merged 8 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export class SessionRecordingIngesterV2 {
public async handleEachBatch(messages: Message[]): Promise<void> {
await runInstrumentedFunction({
statsKey: `recordingingester.handleEachBatch`,
timeout: 60 * 1000,
logToConsole: true,
func: async () => {
const transaction = Sentry.startTransaction({ name: `blobIngestion_handleEachBatch` }, {})
histogramKafkaBatchSize.observe(messages.length)
Expand Down Expand Up @@ -567,12 +567,19 @@ export class SessionRecordingIngesterV2 {
// - have some sort of timeout so we don't get stuck here forever
if (this.serverConfig.SESSION_RECORDING_PARTITION_REVOKE_OPTIMIZATION) {
status.info('🔁', `blob_ingester_consumer - flushing ${sessionsToDrop.length} sessions on revoke...`)
await Promise.allSettled(
sessionsToDrop
.map(([_, x]) => x)
.sort((x) => x.buffer.oldestKafkaTimestamp ?? Infinity)
.map((x) => x.flush('partition_shutdown'))
)

await runInstrumentedFunction({
statsKey: `recordingingester.onRevokePartitions.flushSessions`,
logToConsole: true,
func: async () => {
await Promise.allSettled(
sessionsToDrop
.map(([_, x]) => x)
.sort((x) => x.buffer.oldestKafkaTimestamp ?? Infinity)
.map((x) => x.flush('partition_shutdown'))
)
},
})
}

topicPartitions.forEach((topicPartition: TopicPartition) => {
Expand Down
16 changes: 16 additions & 0 deletions plugin-server/src/main/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ interface FunctionInstrumentation<T> {
timeoutMessage?: string
timeoutContext?: () => Record<string, any>
teamId?: number
logToConsole?: boolean
}

const logTime = (startTime: number, statsKey: string, error?: any) => {
status.info('⏱️', `${statsKey} took ${Math.round(performance.now() - startTime)}ms`, {
error,
})
}

export async function runInstrumentedFunction<T>({
Expand All @@ -20,18 +27,27 @@ export async function runInstrumentedFunction<T>({
func,
statsKey,
teamId,
logToConsole = false,
benjackwhite marked this conversation as resolved.
Show resolved Hide resolved
}: FunctionInstrumentation<T>): Promise<T> {
const t = timeoutGuard(timeoutMessage ?? `Timeout warning for '${statsKey}'!`, timeoutContext, timeout)
benjackwhite marked this conversation as resolved.
Show resolved Hide resolved
const startTime = performance.now()
const end = instrumentedFunctionDuration.startTimer({
function: statsKey,
})

try {
const result = await func()
end({ success: 'true' })
if (logToConsole) {
logTime(startTime, statsKey)
}
return result
} catch (error) {
end({ success: 'false' })
status.info('🔔', error)
if (logToConsole) {
logTime(startTime, statsKey, error)
}
Sentry.captureException(error, { tags: { team_id: teamId } })
throw error
} finally {
Expand Down