Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat(logs): show edge function name in logs FE-2798 (#43967)

Jordi Enrice9d951a65cd9
diff --git a/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/FunctionsEdgeColumnRender.tsx b/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/FunctionsEdgeColumnRender.tsx
index 2e60afb1f6d..5c2ff4f15a3 100644
--- a/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/FunctionsEdgeColumnRender.tsx
+++ b/apps/studio/components/interfaces/Settings/Logs/LogColumnRenderers/FunctionsEdgeColumnRender.tsx
@@ -1,8 +1,10 @@
import { Column } from 'react-data-grid'
+import { TimestampInfo } from 'ui-patterns/TimestampInfo'
+
import type { LogData } from '../Logs.types'
+import { extractEdgeFunctionName } from '../Logs.utils'
import { ResponseCodeFormatter, RowLayout, TextFormatter } from '../LogsFormatters'
import { defaultRenderCell } from './DefaultPreviewColumnRenderer'
-import { TimestampInfo } from 'ui-patterns/TimestampInfo'
const columns: Column<LogData>[] = [
{
@@ -13,11 +15,13 @@ const columns: Column<LogData>[] = [
if (!props.row.status_code && !props.row.method) {
return defaultRenderCell(props)
}
+ const functionName = extractEdgeFunctionName(props.row.pathname)
return (
<RowLayout>
<TimestampInfo utcTimestamp={props.row.timestamp!} />
<ResponseCodeFormatter value={String(props.row.status_code)} />
<TextFormatter value={String(props.row.method)} />
+ {functionName && <TextFormatter value={functionName} />}
<TextFormatter value={String(props.row.id)} />
</RowLayout>
)
diff --git a/apps/studio/components/interfaces/Settings/Logs/Logs.utils.test.ts b/apps/studio/components/interfaces/Settings/Logs/Logs.utils.test.ts
index 8eb6de48d95..f52ec3c8a5d 100644
--- a/apps/studio/components/interfaces/Settings/Logs/Logs.utils.test.ts
+++ b/apps/studio/components/interfaces/Settings/Logs/Logs.utils.test.ts
@@ -1,7 +1,12 @@
import { describe, expect, test } from 'vitest'
import type { LogData } from './Logs.types'
-import { buildLogsPrompt, formatLogsAsJson, formatLogsAsMarkdown } from './Logs.utils'
+import {
+ buildLogsPrompt,
+ extractEdgeFunctionName,
+ formatLogsAsJson,
+ formatLogsAsMarkdown,
+} from './Logs.utils'
const createLog = (overrides: Partial<LogData> = {}): LogData => ({
id: 'test-id',
@@ -83,4 +88,31 @@ describe('Logs.utils', () => {
expect(result).toContain('1 Supabase log entry')
})
})
+
+ describe('extractEdgeFunctionName', () => {
+ test('extracts function name from full pathname', () => {
+ expect(extractEdgeFunctionName('/functions/v1/hello-world-1')).toBe('hello-world-1')
+ })
+
+ test('returns empty string for null', () => {
+ expect(extractEdgeFunctionName(null)).toBe('')
+ })
+
+ test('returns empty string for undefined', () => {
+ expect(extractEdgeFunctionName(undefined)).toBe('')
+ })
+
+ test('returns empty string for non-string values', () => {
+ expect(extractEdgeFunctionName(42)).toBe('')
+ expect(extractEdgeFunctionName({})).toBe('')
+ })
+
+ test('handles pathname with no slashes', () => {
+ expect(extractEdgeFunctionName('my-function')).toBe('my-function')
+ })
+
+ test('handles trailing slash', () => {
+ expect(extractEdgeFunctionName('/functions/v1/hello-world-1/')).toBe('hello-world-1')
+ })
+ })
})
diff --git a/apps/studio/components/interfaces/Settings/Logs/Logs.utils.ts b/apps/studio/components/interfaces/Settings/Logs/Logs.utils.ts
index 5515dd4c94b..130abc22088 100644
--- a/apps/studio/components/interfaces/Settings/Logs/Logs.utils.ts
+++ b/apps/studio/components/interfaces/Settings/Logs/Logs.utils.ts
@@ -205,7 +205,7 @@ ${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}
+ return `select id, ${table}.timestamp, event_message, response.status_code, request.method, request.pathname, m.function_id, m.execution_time_ms, m.deployment_id, m.version from ${table}
${joins}
${where}
${orderBy}
@@ -808,6 +808,12 @@ const LOG_TABLE_TO_SERVICE_LABEL: Record<string, string> = {
etl_replication_logs: 'ETL',
}
+export function extractEdgeFunctionName(pathname: unknown): string {
+ if (typeof pathname !== 'string' || !pathname) return ''
+ const parts = pathname.split('/').filter(Boolean)
+ return parts[parts.length - 1] ?? ''
+}
+
function extractServiceLabelFromSql(sql: string): string | null {
const match = sql.match(/\bfrom\s+(\w+)/i)
const tableName = match?.[1]