Skip to content

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

docs: move integration guide to log drains page (#28694)

Ziinc375aacf7e962
diff --git a/apps/docs/content/guides/functions/compression.mdx b/apps/docs/content/guides/functions/compression.mdx
new file mode 100644
index 00000000000..77964769461
--- /dev/null
+++ b/apps/docs/content/guides/functions/compression.mdx
@@ -0,0 +1,50 @@
+---
+id: 'functions-compression'
+title: 'Handling Compressed Requests'
+description: 'Handling Gzip compressed requests.'
+subtitle: 'Handling Gzip compressed requests.'
+---
+
+To decompress Gzip bodies, you can use `gunzipSync` from the `node:zlib` API to decompress and then read the body.
+
+```ts
+import { gunzipSync } from 'node:zlib'
+
+Deno.serve(async (req) => {
+ try {
+ // Check if the request body is gzip compressed
+ const contentEncoding = req.headers.get('content-encoding')
+ if (contentEncoding !== 'gzip') {
+ return new Response('Request body is not gzip compressed', {
+ status: 400,
+ })
+ }
+
+ // Read the compressed body
+ const compressedBody = await req.arrayBuffer()
+
+ // Decompress the body
+ const decompressedBody = gunzipSync(new Uint8Array(compressedBody))
+
+ // Convert the decompressed body to a string
+ const decompressedString = new TextDecoder().decode(decompressedBody)
+ const data = JSON.parse(decompressedString)
+
+ // Process the decompressed body as needed
+ console.log(`Received: ${JSON.stringify(data)}`)
+
+ return new Response('ok', {
+ headers: { 'Content-Type': 'text/plain' },
+ })
+ } catch (error) {
+ console.error('Error:', error)
+ return new Response('Error processing request', { status: 500 })
+ }
+})
+```
+
+<Admonition type="warning">
+
+Edge functions have a runtime memory limit of 150MB. Overly large compressed payloads may result in an out-of-memory error.
+
+</Admonition>
diff --git a/apps/docs/content/guides/functions/log-drains.mdx b/apps/docs/content/guides/functions/log-drains.mdx
deleted file mode 100644
index a2b36af1e49..00000000000
--- a/apps/docs/content/guides/functions/log-drains.mdx
+++ /dev/null
@@ -1,102 +0,0 @@
----
-id: 'functions-log-drains'
-title: 'Integrating with Log Drains'
-description: 'Integrating an Edge Function with a HTTP Endpoint Drain.'
-subtitle: 'Integrating an Edge Function with a HTTP Endpoint Drain.'
----
-
-This guide will provide a walkthrough to integrate Edge Functions with a HTTP Endpoint Log Drain.
-
-<Admonition type="note">
-
-Log Drains on Supabase Platform is currently only available Team and Enterprise customers.
-
-</Admonition>
-
-## Setup Steps
-
-### Create and deploy the edge function
-
-Generate a new edge function template and update it to log out the received JSON payload. For simplicity, we will accept any request with an Anon Key.
-
-```bash
-supabase functions new hello-world
-```
-
-You can use this example snippet as an illustration of how the received request will be like.
-
-```ts
-import 'jsr:@supabase/functions-js/edge-runtime.d.ts'
-
-Deno.serve(async (req) => {
- const data = await req.json()
-
- console.log(`Received ${data.length} logs, first log:\n ${JSON.stringify(data[0])}`)
- return new Response(JSON.stringify({ message: 'ok' }), {
- headers: { 'Content-Type': 'application/json' },
- })
-})
-```
-
-And then deploy it with:
-
-```bash
-supabase functions deploy hello-world --project-ref [PROJECT REF]
-```
-
-<Admonition type="warning">
-
-This will create an infinite loop, as we are generating an additional log event that will eventually trigger a new request to this edge function. However, due to the batching nature of how Log Drain events are dispatched, the rate of edge function triggers will not increase greatly and will have an upper bound.
-
-</Admonition>
-
-### Configure the HTTP Drain
-
-Create a HTTP drain under the [Project Settings > Log Drains](https://supabase.com/dashboard/project/_/settings/log-drains).
-
-- Disable the Gzip, as we want to receive the payload without compression.
-- Under URL, set it to your edge function URL `https://[PROJECT REF].supabase.co/functions/v1/hello-world`
-- Under Headers, set the `Authorization: Bearer [ANON KEY]`
-
-<ProjectConfigVariables variable="anonKey" />
-
-## Enabling Gzip
-
-To send compressed requests and reduce egress costs, adjusting the edge function to support Gzip can be achieved using native in-built APIs:
-
-```ts
-import { gunzipSync } from 'node:zlib'
-
-Deno.serve(async (req) => {
- try {
- // Check if the request body is gzip compressed
- const contentEncoding = req.headers.get('content-encoding')
- if (contentEncoding !== 'gzip') {
- return new Response('Request body is not gzip compressed', {
- status: 400,
- })
- }
-
- // Read the compressed body
- const compressedBody = await req.arrayBuffer()
-
- // Decompress the body
- const decompressedBody = gunzipSync(new Uint8Array(compressedBody))
-
- // Convert the decompressed body to a string
- const decompressedString = new TextDecoder().decode(decompressedBody)
- const data = JSON.parse(decompressedString)
- // Process the decompressed body as needed
- console.log(`Received: ${data.length} logs.`)
-
- return new Response('ok', {
- headers: { 'Content-Type': 'text/plain' },
- })
- } catch (error) {
- console.error('Error:', error)
- return new Response('Error processing request', { status: 500 })
- }
-})
-```
-
-After deployment, re-configure the HTTP Endpoint by turning on the Gzip option to send gzipped payloads to the edge function.
diff --git a/apps/docs/content/guides/platform/log-drains.mdx b/apps/docs/content/guides/platform/log-drains.mdx
index 78381929ca3..c41ba440744 100644
--- a/apps/docs/content/guides/platform/log-drains.mdx
+++ b/apps/docs/content/guides/platform/log-drains.mdx
@@ -4,17 +4,11 @@ title: 'Log Drains'
description: 'Getting started with Supabase Log Drains'
---
-Log drains will send all logs of the Supabase stack to one or more desired destinations. It is only available for customers on Team and Enterprise Plans.
+Log drains will send all logs of the Supabase stack to one or more desired destinations. It is only available for customers on Team and Enterprise Plans. Log drains is available in the dashboard under [Project Settings > Log Drains](https://supabase.com/dashboard/project/_/settings/log-drains).
-<Admonition type="note">
-
-Log drains is in **Private Alpha**, and is not available in the dashboard yet. [Reach out to us](https://forms.supabase.com/logdrains) to get log drains enabled for your project.
-
-You can read about the initial announcement [here](https://github.com/orgs/supabase/discussions/26650).
+You can read about the intiial announcement [here](https://supabase.com/blog/log-drains) and vote for your preferred drains in [this discussion](https://github.com/orgs/supabase/discussions/28324?sort=top).
-</Admonition>
-
-## Supported Destinations
+# Supported Destinations
The following table lists the supported destinations and the required setup configuration:
@@ -25,7 +19,7 @@ The following table lists the supported destinations and the required setup conf
HTTP requests are batched with a max of 250 logs or 1 second intervals, whichever happens first. Logs are compressed via Gzip if the destination supports it.
-### Generic HTTP endpoint
+## Generic HTTP Endpoint
Logs are sent as a POST request with a JSON body. Both HTTP/1 and HTTP/2 protocols are supported.
Custom headers can optionally be configured for all requests.
@@ -36,7 +30,109 @@ Note that requests are **unsigned**.
Unsigned requests to HTTP endpoints are temporary and all requests will signed in the near future.
</Admonition>
-### Datadog
+<Accordion
+ type="default"
+ openBehaviour="multiple"
+>
+ <AccordionItem
+ header="Edge Function Walkthrough (Uncompressed)"
+ id="uncompressed"
+ >
+
+1. Create and deploy the edge function
+
+Generate a new edge function template and update it to log out the received JSON payload. For simplicity, we will accept any request with an Anon Key.
+
+```bash
+supabase functions new hello-world
+```
+
+You can use this example snippet as an illustration of how the received request will be like.
+
+```ts
+import 'jsr:@supabase/functions-js/edge-runtime.d.ts'
+
+Deno.serve(async (req) => {
+ const data = await req.json()
+
+ console.log(`Received ${data.length} logs, first log:\n ${JSON.stringify(data[0])}`)
+ return new Response(JSON.stringify({ message: 'ok' }), {
+ headers: { 'Content-Type': 'application/json' },
+ })
+})
+```
+
+And then deploy it with:
+
+```bash
+supabase functions deploy hello-world --project-ref [PROJECT REF]
+```
+
+<Admonition type="warning">
+
+This will create an infinite loop, as we are generating an additional log event that will eventually trigger a new request to this edge function. However, due to the batching nature of how Log Drain events are dispatched, the rate of edge function triggers will not increase greatly and will have an upper bound.
+
+</Admonition>
+
+2. Configure the HTTP Drain
+
+Create a HTTP drain under the [Project Settings > Log Drains](https://supabase.com/dashboard/project/_/settings/log-drains).
+
+- Disable the Gzip, as we want to receive the payload without compression.
+- Under URL, set it to your edge function URL `https://[PROJECT REF].supabase.co/functions/v1/hello-world`
+- Under Headers, set the `Authorization: Bearer [ANON KEY]`
+
+<ProjectConfigVariables variable="anonKey" />
+
+ </AccordionItem>
+
+ <AccordionItem
+ header="Edge Function Gzip Example"
+ id="gzip"
+ >
+
+Gzip payloads can be decompressed using native in-built APIs. Refer to the Edge Function [compression guide](https://supabase.com/docs/guides/functions/compression)
+
+```ts
+import { gunzipSync } from 'node:zlib'
+
+Deno.serve(async (req) => {
+ try {
+ // Check if the request body is gzip compressed
+ const contentEncoding = req.headers.get('content-encoding')
+ if (contentEncoding !== 'gzip') {
+ return new Response('Request body is not gzip compressed', {
+ status: 400,
+ })
+ }
+
+ // Read the compressed body
+ const compressedBody = await req.arrayBuffer()
+
+ // Decompress the body
+ const decompressedBody = gunzipSync(new Uint8Array(compressedBody))
+
+ // Convert the decompressed body to a string
+ const decompressedString = new TextDecoder().decode(decompressedBody)
+ const data = JSON.parse(decompressedString)
+ // Process the decompressed body as needed
+ console.log(`Received: ${data.length} logs.`)
+
+ return new Response('ok', {
+ headers: { 'Content-Type': 'text/plain' },
+ })
+ } catch (error) {
+ console.error('Error:', error)
+ return new Response('Error processing request', { status: 500 })
+ }
+})
+```
+
+ </AccordionItem>
+
+</Accordion>
+
+## Datadog Logs
Logs sent to Datadog have the name of the log source set on the `service` field of the event and the source set to `Supabase`. Logs are gzipped before they are sent to Datadog.
@@ -79,10 +175,6 @@ To setup Datadog log drain, generate a Datadog API key [here](https://app.datado
metadata.parsed.error_severity, metadata.level
```
- [Remapper](https://docs.datadoghq.com/service_management/events/pipelines_and_processors/remapper) for setting the log event message.
- ```
- event_message
- ```
</AccordionItem>
</Accordion>
diff --git a/apps/www/_blog/2024-08-15-log-drains.mdx b/apps/www/_blog/2024-08-15-log-drains.mdx
index 8c0b40a76dc..11f581daae6 100644
--- a/apps/www/_blog/2024-08-15-log-drains.mdx
+++ b/apps/www/_blog/2024-08-15-log-drains.mdx
@@ -50,7 +50,7 @@ Popular destinations like Datadog are supported out of the box. More detailed se
<Img alt="Datadog Logs drain" src="/images/blog/lw12/day-4/datadog-example.png" />
-For the providers that are not natively supported yet, the HTTP Endpoint drain can be used to send logs to any destination that supports ingestion via HTTP POST requests. For example, you can send logs to an Edge Function, filter, or restructure the logs, and then dispatch them to an external provider. In the following example, we perform a simple `console.log` of the received JSON payload. Detailed setup guide is available under the [Edge Functions guide](https://supabase.com/docs/guides/functions/log-drains).
+For the providers that are not natively supported yet, the HTTP Endpoint drain can be used to send logs to any destination that supports ingestion via HTTP POST requests. For example, you can send logs to an Edge Function, filter, or restructure the logs, and then dispatch them to an external provider. In the following example, we perform a simple `console.log` of the received JSON payload. Detailed setup guide is available under the [Edge Functions guide](https://supabase.com/docs/guides/platform/log-drain#generic-http-endpoints).
<Img
alt="HTTP Endpoint drain to Supabase Edge Functions"
diff --git a/apps/www/lib/redirects.js b/apps/www/lib/redirects.js
index f1ced8aac57..7b762821596 100644
--- a/apps/www/lib/redirects.js
+++ b/apps/www/lib/redirects.js
@@ -2543,6 +2543,11 @@ module.exports = [
source: '/docs/guides/functions/debugging',
destination: '/docs/functions/logging',
},
+ {
+ permanent: true,
+ source: '/docs/guides/functions/log-drains',
+ destination: '/docs/platform/log-drains',
+ },
{
permanent: true,
source: '/docs/guides/functions/functions-headers',