mirror of
https://github.com/supabase/supabase.git
synced 2026-06-21 00:06:04 +08:00
Add a Query Performance page implementation powered by [supamonitor](https://github.com/supabase/supamonitor). [Context](https://linear.app/supabase/project/build-extension-for-supabase-query-insights-df4fb145352c/overview) This looks largely the same as the pg_stat_monitor implementation: <img width="2556" height="960" alt="Screenshot 2026-02-12 at 7 35 47 PM" src="https://github.com/user-attachments/assets/bf37466e-f7af-41f2-b4f2-cf8eb6a8c76f" /> Only available on projects on custom AMI - existing users are unaffected <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Supamonitor-based query performance view: charts, aggregated metrics, date-range controls, and export/download. * Added "Application" column for per-application tracking. * Interactive Supamonitor grid: sorting, filtering, keyboard navigation, selection, retry/error handling. * Automatic per-project Supamonitor detection with toggleable UI integration. * **Bug Fixes** * Chart latency calculation prefers histogram data for more accurate p95. * **Documentation** * Minor blog formatting fix. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: kemal <hello@kemal.earth> Co-authored-by: Ali Waseem <waseema393@gmail.com>
74 lines
2.0 KiB
TypeScript
74 lines
2.0 KiB
TypeScript
import * as Sentry from '@sentry/nextjs'
|
|
import dayjs from 'dayjs'
|
|
import duration from 'dayjs/plugin/duration'
|
|
|
|
import { getErrorMessage } from 'lib/get-error-message'
|
|
|
|
dayjs.extend(duration)
|
|
|
|
export const formatDuration = (milliseconds: number) => {
|
|
const duration = dayjs.duration(milliseconds, 'milliseconds')
|
|
|
|
const days = Math.floor(duration.asDays())
|
|
const hours = duration.hours()
|
|
const minutes = duration.minutes()
|
|
const seconds = duration.seconds()
|
|
const totalSeconds = duration.asSeconds()
|
|
|
|
if (totalSeconds < 60) {
|
|
return `${totalSeconds.toFixed(2)}s`
|
|
}
|
|
|
|
const parts = []
|
|
if (days > 0) parts.push(`${days}d`)
|
|
if (hours > 0) parts.push(`${hours}h`)
|
|
if (minutes > 0) parts.push(`${minutes}m`)
|
|
if (seconds > 0) parts.push(`${seconds}s`)
|
|
|
|
return parts.length > 0 ? parts.join(' ') : '0s'
|
|
}
|
|
|
|
export type QueryPerformanceErrorContext = {
|
|
projectRef?: string
|
|
databaseIdentifier?: string
|
|
queryPreset?: string
|
|
queryType?: 'hitRate' | 'metrics' | 'mainQuery' | 'slowQueriesCount' | 'supamonitor'
|
|
sql?: string
|
|
errorMessage?: string
|
|
postgresVersion?: string
|
|
databaseType?: 'primary' | 'read-replica'
|
|
}
|
|
|
|
export function captureQueryPerformanceError(
|
|
error: unknown,
|
|
context: QueryPerformanceErrorContext
|
|
) {
|
|
Sentry.withScope((scope) => {
|
|
scope.setTag('query-performance', 'true')
|
|
|
|
scope.setContext('query-performance', {
|
|
projectRef: context.projectRef,
|
|
databaseIdentifier: context.databaseIdentifier,
|
|
queryPreset: context.queryPreset,
|
|
queryType: context.queryType,
|
|
postgresVersion: context.postgresVersion,
|
|
databaseType: context.databaseType,
|
|
errorMessage: context.errorMessage,
|
|
})
|
|
|
|
if (error instanceof Error) {
|
|
Sentry.captureException(error)
|
|
return
|
|
}
|
|
|
|
const errorMessage = getErrorMessage(error)
|
|
const errorToCapture = new Error(errorMessage || 'Query performance error')
|
|
|
|
if (error !== null && error !== undefined) {
|
|
errorToCapture.cause = error
|
|
}
|
|
|
|
Sentry.captureException(errorToCapture)
|
|
})
|
|
}
|