The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
added advanced filtering page to log docs (#28233)
TheOtherBrian1ee35e989d9c1
diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.tsindex 32f871da9f8..fd5443347ff 100644--- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts+++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts@@ -1768,6 +1768,7 @@ export const platform: NavMenuConstant = {url: undefined,items: [{ name: 'Logging', url: '/guides/platform/logs' },+ { name: 'Advanced Log Filtering', url: '/guides/platform/advanced-log-filtering' },{ name: 'Log Drains', url: '/guides/platform/log-drains' },{ name: 'Metrics', url: '/guides/platform/metrics' },{ name: 'Monitoring with Sentry', url: '/guides/platform/sentry-monitoring' },diff --git a/apps/docs/content/guides/platform/advanced-log-filtering.mdx b/apps/docs/content/guides/platform/advanced-log-filtering.mdxnew file mode 100644index 00000000000..670f5f958d6--- /dev/null+++ b/apps/docs/content/guides/platform/advanced-log-filtering.mdx@@ -0,0 +1,193 @@+---+title: 'Advanced Log Filtering'+description: 'Filter logs with regular expressions'+---++# Querying the logs++## Understanding field references++The log tables are queried with subset of BigQuery SQL syntax. They all have three columns: `event_message`, `timestamp`, and `metadata`.++| column | description |+| ------------- | --------------------------- |+| timestamp | time event was recorded |+| event_message | the log's message |+| metadata | information about the event |++The `metadata` column is an array of JSON objects that stores important details about each recorded event. For example, in the postgres table, the `metadata.parsed.error_severity` field indicates the error level of an event. To work with its values, you need to `unnest` them using a `cross join`.++This approach is commonly used with JSON and array columns, so it might look a bit unfamiliar if you're not used to working with these data types.++```sql+select+ event_message,+ parsed.error_severity,+ parsed.user_name+from+ postgres_logs+ -- extract first layer+ cross join unnest(postgres_logs.metadata) as metadata+ -- extract second layer+ cross join unnest(metadata.parsed) as parsed;+```++## Expanding results++Logs returned by queries may be difficult to read in table format. A row can be double-clicked to expand the results into more readable JSON:++++## Filtering with [regular expressions](https://en.wikipedia.org/wiki/Regular_expression)++The Logs use BigQuery Style regular expressions with the [regexp_contains function](https://cloud.google.com/bigquery/docs/reference/standard-sql/string_functions#regexp_contains). In its most basic form, it will check if a string is present in a specified column.++```sql+select+ cast(timestamp as datetime) as timestamp,+ event_message,+ metadata+from postgres_logs+where regexp_contains(event_message, 'is present');+```++There are multiple operators that you should consider using:++### Find messages that start with a phrase++`^` only looks for values at the start of a string++```sql+-- find only messages that start with connection+regexp_contains(event_message, '^connection')+```++### Find messages that end with a phrase:++`$` only looks for values at the end of the string++```sql+-- find only messages that ends with port=12345+regexp_contains(event_message, '$port=12345')+```++### Ignore case sensitivity:++`(?i)` ignores capitalization for all proceeding characters++```sql+-- find all event_messages with the word "connection"+regexp_contains(event_message, '(?i)COnnecTion')+```++### Wildcards:++`.` can represent any string of characters++```sql+-- find event_messages like "hello<anything>world"+regexp_contains(event_message, 'hello.world')+```++### Alphanumeric ranges:++`[1-9a-zA-Z]` finds any strings with only numbers and letters++```sql+-- find event_messages that contain a number between 1 and 5 (inclusive)+regexp_contains(event_message, '[1-5]')+```++### Repeated values:++`x*` zero or more x+`x+` one or more x+`x?` zero or one x+`x{4,}` four or more x+`x{3}` exactly 3 x++```sql+-- find event_messages that contains any sequence of 3 digits+regexp_contains(event_message, '[0-9]{3}')+```++### Escaping reserved characters:++`\.` interpreted as period `.` instead of as a wildcard++```sql+-- escapes .+regexp_contains(event_message, 'hello world\.')+```++### `or` statements:++`x|y` any string with `x` or `y` present++```sql+-- find event_messages that have the word 'started' followed by either the word "host" or "authenticated"+regexp_contains(event_message, 'started host|authenticated')+```++### and/or/not statements in SQL:++`and`, `or`, and `not` are all native terms in SQL and can be used in conjunction with regular expressions to filter results++```sql+select+ cast(timestamp as datetime) as timestamp,+ event_message,+ metadata+from postgres_logs+where+ (regexp_contains(event_message, 'connection') and regexp_contains(event_message, 'host'))+ or not regexp_contains(event_message, 'received');+```++### Filtering and unnesting example++**Filter for Postgres**++```sql+select+ cast(postgres_logs.timestamp as datetime) as timestamp,+ parsed.error_severity,+ parsed.user_name,+ event_message+from+ postgres_logs+ cross join unnest(metadata) as metadata+ cross join unnest(metadata.parsed) as parsed+where regexp_contains(parsed.error_severity, 'ERROR|FATAL|PANIC')+order by timestamp desc+limit 100;+```++## Limitations++### Log tables cannot be joined together++Each product table operates independently without the ability to join with other log tables. This may change in the future.++### The `with` keyword and subqueries are not supported++The parser does not yet support `with` and subquery statements.++### The `ilike` and `similar to` keywords are not supported++Although `like` and other comparison operators can be used, `ilike` and `similar to` are incompatible with BigQuery's variant of SQL. `regexp_contains` can be used as an alternative.++### The wildcard operator `*` to select columns is not supported++The log parser is not able to parse the `*` operator for column selection. Instead, you can access all fields from the `metadata` column:++```sql+select+ cast(postgres_logs.timestamp as datetime) as timestamp,+ event_message,+ metadata+from+ <log_table_name>+order by timestamp desc+limit 100;+```diff --git a/apps/docs/public/img/guides/platform/expanded-log-results.png b/apps/docs/public/img/guides/platform/expanded-log-results.pngnew file mode 100644index 00000000000..7c83625a8a1Binary files /dev/null and b/apps/docs/public/img/guides/platform/expanded-log-results.png differdiff --git a/vale/styles/config/vocabularies/Supabase/accept.txt b/vale/styles/config/vocabularies/Supabase/accept.txtindex 0aab093205a..2d56cae94d8 100644--- a/vale/styles/config/vocabularies/Supabase/accept.txt+++ b/vale/styles/config/vocabularies/Supabase/accept.txt@@ -18,6 +18,7 @@ Deno[Dd]otenv[Ee]nv[Ee]nums?+event_messageFirestoreHashicorp[Gg]eospatial@@ -56,6 +57,7 @@ plpgsqlPrisma[Rr]ealtimeRefine's+regexp_contains[Rr]eindex(ed|es|ing)?repoRESTful@@ -68,12 +70,16 @@ Roboflow[Ss]ignouts?[Ss]ignups?SQLAlchemy+subquery+subqueries[Ss]upabaseSnapletSupavisor[Ss]upersets?Terraform[Tt]odos?+unnesting+unnested[Uu]npaus(e|es|ed|ing)[Uu]psert(s|ed|ing)?[Uu]pvot(es|ed|ing)