The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix: update queries for local edge function and cron logs (#39388)
Han Qiao6026a824a325
diff --git a/apps/studio/components/interfaces/Settings/Logs/Logs.constants.ts b/apps/studio/components/interfaces/Settings/Logs/Logs.constants.tsindex b07b68e0c1d..1309f266ec1 100644--- a/apps/studio/components/interfaces/Settings/Logs/Logs.constants.ts+++ b/apps/studio/components/interfaces/Settings/Logs/Logs.constants.ts@@ -2,6 +2,7 @@ import dayjs from 'dayjs'import { DOCS_URL } from 'lib/constants'import type { DatetimeHelper, FilterTableSet, LogTemplate } from './Logs.types'+import { IS_PLATFORM } from 'common'export const LOGS_EXPLORER_DOCS_URL = `${DOCS_URL}/guides/platform/logs#querying-with-the-logs-explorer`@@ -538,29 +539,33 @@ export const FILTER_OPTIONS: FilterTableSet = {},},// function_edge_logs- function_edge_logs: {- status_code: {- label: 'Status',- key: 'status_code',- options: [- {- key: 'error',- label: 'Error',- description: '500 error codes',- },- {- key: 'success',- label: 'Success',- description: '200 codes',- },- {- key: 'warning',- label: 'Warning',- description: '400 codes',- },- ],- },- },+ ...(IS_PLATFORM+ ? {+ function_edge_logs: {+ status_code: {+ label: 'Status',+ key: 'status_code',+ options: [+ {+ key: 'error',+ label: 'Error',+ description: '500 error codes',+ },+ {+ key: 'success',+ label: 'Success',+ description: '200 codes',+ },+ {+ key: 'warning',+ label: 'Warning',+ description: '400 codes',+ },+ ],+ },+ },+ }+ : {}),// function_logsfunction_logs: {severity: {diff --git a/apps/studio/components/interfaces/Settings/Logs/Logs.utils.ts b/apps/studio/components/interfaces/Settings/Logs/Logs.utils.tsindex 8f26529dc49..b08cb3ce1f1 100644--- a/apps/studio/components/interfaces/Settings/Logs/Logs.utils.ts+++ b/apps/studio/components/interfaces/Settings/Logs/Logs.utils.ts@@ -1,6 +1,6 @@import { useMonaco } from '@monaco-editor/react'import dayjs, { Dayjs } from 'dayjs'-import { get, isEqual } from 'lodash'+import { get } from 'lodash'import uniqBy from 'lodash/uniqBy'import { useEffect } from 'react'@@ -142,7 +142,7 @@ export const genDefaultQuery = (table: LogsTableName, filters: Filters, limit: nswitch (table) {case 'edge_logs':- if (IS_PLATFORM === false) {+ if (!IS_PLATFORM) {return `-- local dev edge_logs queryselect id, edge_logs.timestamp, event_message, request.method, request.path, request.search, response.status_code@@ -162,7 +162,7 @@ limit ${limit};`case 'postgres_logs':- if (IS_PLATFORM === false) {+ if (!IS_PLATFORM) {return `select postgres_logs.timestamp, id, event_message, parsed.error_severity, parsed.detail, parsed.hintfrom postgres_logs@@ -196,6 +196,14 @@ limit ${limit}`case 'function_edge_logs':+ if (!IS_PLATFORM) {+ return `+select id, function_edge_logs.timestamp, event_message+from function_edge_logs+${orderBy}+limit ${limit}+`+ }return `select id, ${table}.timestamp, event_message, response.status_code, request.method, m.function_id, m.execution_time_ms, m.deployment_id, m.version from ${table}${joins}${where}@@ -216,11 +224,9 @@ limit ${limit}`case 'pg_cron_logs':- const baseWhere = `where (parsed.application_name = 'pg_cron' OR event_message LIKE '%cron job%')`-- const pgCronWhere = where ? `${baseWhere} AND ${where.substring(6)}` : baseWhere+ const pgCronWhere = where ? `${basePgCronWhere} AND ${where.substring(6)}` : basePgCronWhere- return `select identifier, postgres_logs.timestamp, id, event_message, parsed.error_severity, parsed.query+ return `select id, postgres_logs.timestamp, event_message, parsed.error_severity, parsed.queryfrom postgres_logscross join unnest(metadata) as mcross join unnest(m.parsed) as parsed@@ -242,6 +248,7 @@ const genCrossJoinUnnests = (table: LogsTableName) => {cross join unnest(m.request) as requestcross join unnest(m.response) as response`+ case 'pg_cron_logs':case 'postgres_logs':return `cross join unnest(metadata) as mcross join unnest(m.parsed) as parsed`@@ -313,6 +320,7 @@ const calcChartStart = (params: Partial<LogsEndpointParams>): [Dayjs, string] =>return [its.add(-extendValue, trunc), trunc]}+const basePgCronWhere = `where ( parsed.application_name = 'pg_cron' or regexp_contains(event_message, 'cron job') )`/**** generates log event chart query@@ -331,7 +339,7 @@ export const genChartQuery = (// to calculate the chart, we need to query postgres logsif (table === LogsTableName.PG_CRON) {table = LogsTableName.POSTGRES- where = `where (parsed.application_name = 'pg_cron' OR event_message LIKE '%cron job%')`+ where = basePgCronWhere}let joins = genCrossJoinUnnests(table)diff --git a/docker/docker-compose.yml b/docker/docker-compose.ymlindex 9f484246be6..0f470f2fa30 100644--- a/docker/docker-compose.yml+++ b/docker/docker-compose.yml@@ -343,7 +343,7 @@ services:analytics:container_name: supabase-analytics- image: supabase/logflare:1.22.4+ image: supabase/logflare:1.22.6restart: unless-stoppedports:- 4000:4000diff --git a/docker/volumes/logs/vector.yml b/docker/volumes/logs/vector.ymlindex 1c438a8ecdd..3493e9b3f8e 100644--- a/docker/volumes/logs/vector.yml+++ b/docker/volumes/logs/vector.yml@@ -35,7 +35,7 @@ transforms:rest: '.appname == "supabase-rest"'realtime: '.appname == "supabase-realtime"'storage: '.appname == "supabase-storage"'- functions: '.appname == "supabase-functions"'+ functions: '.appname == "supabase-edge-functions"'db: '.appname == "supabase-db"'# Ignores non nginx errors since they are related with kong booting upkong_logs:@@ -117,6 +117,13 @@ transforms:.event_message = parsed.msg.metadata.level = parsed.level}+ # Function logs are unstructured messages on stderr+ functions_logs:+ type: remap+ inputs:+ - router.functions+ source: |-+ .metadata.project_ref = del(.project)# Storage logs may contain json objects so we parse them for completenessstorage_logs:type: remap@@ -210,7 +217,7 @@ sinks:logflare_functions:type: 'http'inputs:- - router.functions+ - functions_logsencoding:codec: 'json'method: 'post'diff --git a/scripts/generateLocalEnv.js b/scripts/generateLocalEnv.jsindex d4134e5d539..a09b81a161f 100644--- a/scripts/generateLocalEnv.js+++ b/scripts/generateLocalEnv.js@@ -23,8 +23,8 @@ const defaultEnv = {STUDIO_PG_META_URL: '$API_URL/pg',SUPABASE_PUBLIC_URL: '$API_URL',SENTRY_IGNORE_API_RESOLUTION_ERROR: '1',- LOGFLARE_URL: 'http://localhost:54329',- LOGFLARE_API_KEY: 'api-key',+ LOGFLARE_URL: 'http://127.0.0.1:54327',+ LOGFLARE_PRIVATE_ACCESS_TOKEN: 'api-key',NEXT_PUBLIC_SITE_URL: 'http://localhost:8082',NEXT_PUBLIC_GOTRUE_URL: '$SUPABASE_PUBLIC_URL/auth/v1',NEXT_PUBLIC_HCAPTCHA_SITE_KEY: '10000000-ffff-ffff-ffff-000000000001',