Skip to content

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

add metadata ip template example

TzeYiingfc67028ac570
diff --git a/studio/components/interfaces/Settings/Logs/Logs.constants.ts b/studio/components/interfaces/Settings/Logs/Logs.constants.ts
index 78b3c542e9c..dd14431a029 100644
--- a/studio/components/interfaces/Settings/Logs/Logs.constants.ts
+++ b/studio/components/interfaces/Settings/Logs/Logs.constants.ts
@@ -8,6 +8,18 @@ export const TEMPLATES: LogTemplate[] = [
searchString:
"REGEXP_CONTAINS(event_message, 'POST') OR REGEXP_CONTAINS(event_message, 'PATCH')",
},
+ {
+ label: 'Metadata IP',
+ mode: 'custom',
+ searchString:
+ `SELECT timestamp, h.x_real_ip
+FROM edge_logs
+ LEFT JOIN UNNEST(metadata) as m ON TRUE
+ LEFT JOIN UNNEST(m.request) AS r ON TRUE
+ LEFT JOIN UNNEST(r.headers) AS h ON TRUE
+WHERE h.x_real_ip IS NOT NULL
+`,
+ },
]
export const DEFAULT_QUERY = 'SELECT timestamp, event_message FROM postgres_logs;'
diff --git a/studio/pages/project/[ref]/settings/logs/[type].tsx b/studio/pages/project/[ref]/settings/logs/[type].tsx
index bb81a1ba3b0..c7ea980fd04 100644
--- a/studio/pages/project/[ref]/settings/logs/[type].tsx
+++ b/studio/pages/project/[ref]/settings/logs/[type].tsx
@@ -65,7 +65,9 @@ export const LogPage: NextPage = () => {
timestamp_end: '',
})
const title = `Logs - ${LOG_TYPE_LABEL_MAPPING[type as string]}`
- const isSelectQuery = editorValue.toLowerCase().includes('select') ? true : false
+ const checkIfSelectQuery = (value: string) =>
+ value.toLowerCase().includes('select') ? true : false
+ const isSelectQuery = checkIfSelectQuery(editorValue)
useEffect(() => {
setParams({ ...params, type: type as string })
@@ -180,8 +182,12 @@ export const LogPage: NextPage = () => {
setEditorValue(template.searchString)
setParams((prev) => ({
...prev,
- where: isSelectQuery ? '' : cleanEditorValue(template.searchString),
- sql: isSelectQuery ? cleanEditorValue(template.searchString) : '',
+ where: checkIfSelectQuery(template.searchString)
+ ? ''
+ : cleanEditorValue(template.searchString),
+ sql: checkIfSelectQuery(template.searchString)
+ ? cleanEditorValue(template.searchString)
+ : '',
search_query: '',
timestamp_end: '',
}))
@@ -228,7 +234,7 @@ export const LogPage: NextPage = () => {
setEditorValue('')
}
const cleanEditorValue = (value: string) => {
- if (typeof value !== "string") return value
+ if (typeof value !== 'string') return value
return value.replace(/\n/g, ' ')
}
return (