> ## Documentation Index
> Fetch the complete documentation index at: https://docs.logbrew.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Supabase log drain and Edge Functions logging with LogBrew

> Send Supabase platform logs to LogBrew with a log drain, and capture logs and errors from Supabase Edge Functions with the JavaScript SDK.

You can send 2 kinds of Supabase data to LogBrew:

* A log drain sends the platform logs of your Supabase project, such as
  Postgres, Auth, Storage, and Edge Functions logs.
* The LogBrew JavaScript SDK sends the logs and errors that your own Edge
  Function code captures.

You can use one or both. Both need a project ingest key. Create a `server`
key for each use. The key kinds are in
[Project key kinds](https://docs.logbrew.co/guides/verify-setup.md#project-key-kinds).

## Send platform logs with a log drain

Supabase log drains are available on the Supabase Pro, Team, and Enterprise
plans. Supabase charges for each drain and for the events it sends. Read the
Supabase pricing before you add a drain.

**1. Open the log drain settings**

In the Supabase dashboard, open your project. Go to **Project Settings**
and then **Log Drains**.

**2. Add an OpenTelemetry destination**

Add a destination of the type **OpenTelemetry (OTLP)**. Set these values:

| Field | Value |
| - | - |
| Endpoint | `https://api.logbrew.co/v1/logs` |
| Protocol | `http/protobuf` |
| Gzip | On |
| Headers | `x-logbrew-key` with your ingest key as the value |

You can use the header `Authorization` with the value
`Bearer lbw_ingest_...` instead of `x-logbrew-key`.

**3. Save the destination**

Save the destination. Supabase starts to send logs to LogBrew.

**Checkpoint:** new Supabase logs show in the logs of your LogBrew
project. To read them from the CLI, follow
[Read your test event back](https://docs.logbrew.co/guides/verify-setup.md#verify-telemetry-arrival).

LogBrew reads the drain as OTLP logs. The `service.name` resource attribute
sets the service of each log. The other resource attributes stay in the log
metadata. LogBrew removes credentials from URLs and from attributes such as
`authorization` before it stores the log. The full mapping is in
[Send OpenTelemetry data](https://docs.logbrew.co/guides/opentelemetry.md).

If no logs arrive, check the endpoint, the protocol, and the header. The
ingest key must belong to the LogBrew project that you read.

## Capture logs and errors in Edge Functions

Supabase Edge Functions run on Deno. Use `@logbrew/node` from npm. This
setup works with Deno 2.9, `@logbrew/node` 0.1.20, and `@logbrew/sdk` 0.1.35.

**1. Save the ingest key as a function secret**

Use the Supabase CLI. Replace the placeholder with your key:

```bash theme={null}
supabase secrets set LOGBREW_SERVER_API_KEY=lbw_ingest_placeholder
```

**2. Create the client and flush before you return**

Create the client once, outside the request handler. Capture events in
the handler. Call `flush()` before you return the response, because the
function can stop after it returns.

```ts theme={null}
import { createIssueAttributesFromError, SdkError } from "npm:@logbrew/sdk@^0.1.35";
import { createLogBrewNodeClient } from "npm:@logbrew/node@^0.1.20";

const logbrew = createLogBrewNodeClient({
  serverApiKey: Deno.env.get("LOGBREW_SERVER_API_KEY"),
  captureRuntimeContext: false,
  context: {
    schemaVersion: 1,
    resource: {
      service: { name: "checkout-function", version: "checkout@1" },
      runtime: { name: "deno", version: Deno.version.deno },
    },
  },
});

Deno.serve(async (request) => {
  const occurredAt = new Date().toISOString();
  logbrew.log(crypto.randomUUID(), occurredAt, {
    message: "checkout request",
    level: "info",
    metadata: { method: request.method },
  });
  let response = new Response("ok");
  try {
    await checkout(request);
  } catch (error) {
    logbrew.issue(
      crypto.randomUUID(),
      occurredAt,
      createIssueAttributesFromError(error, { service: "checkout-function" }),
    );
    response = new Response("checkout failed", { status: 500 });
  }
  try {
    await logbrew.flush();
  } catch (error) {
    console.error(error instanceof SdkError ? error.code : "logbrew_delivery_failed");
  }
  return response;
});

async function checkout(_request: Request) {
  // Your function code.
}
```

`captureRuntimeContext: false` and the `runtime` context make LogBrew
show Deno as the runtime. Without them, the SDK reports the Node.js
version that Deno emulates.

If delivery fails, `flush()` throws an `SdkError`, for example with the
code `network_failure`. The example writes only the error code to the
function log, and the function still returns its response.

**3. Deploy and call the function**

Deploy the function with `supabase functions deploy checkout`. Call it
once.

**Checkpoint:** the `checkout request` log shows in your LogBrew project.

Do not put credentials, request bodies, or customer data in event metadata.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.