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

# Log Export

Log export sends your functions' log lines to an outside service as they are
written, so you can keep a longer history, search it and alert on it. There is
one export with two sinks:

* **OpenTelemetry**: OTLP/HTTP logs, JSON encoded, to an OpenTelemetry
  Collector or any service that ingests OTLP logs.
* **Webhook**: one signed JSON `POST` per batch to a URL you control.

The most recent lines are also in the console's
[Logs page](https://docs.bijection.com/operate/observability/logs.md) and in `bijection list sys.logs`.

## The installation's telemetry

Separately from the exports your code declares, every installation sends
three streams of its own through one [slot](https://docs.bijection.com/operate/placement.md),
`platform.telemetry` (`otlp@1`). The platform installs the export in every
program at `platform.telemetryExport`; your code declares nothing.

* **Logs:** every log line, including the lines of refused runs with their
  refusal code, as OTLP logs of scope `bijection.logs`.
* **Audit:** every public grant's transitions (issue, revoke) in commit order,
  as OTLP logs of scope `bijection.audit`. Each record's body is the asserted
  grant, with its sequence, kind and digests as attributes. See
  [`sys.grantTransitions`](https://docs.bijection.com/database/system-tables).
* **Traces:** one span for each top-level mutation run, with a child span for
  each task it submitted, as OTLP traces. A run a task started is a child of
  that task's send span. Queries and nested calls record no span.

Only public facts leave: the export reads under a label of its own, so a line
or grant a protected label covers stays inside. Unbound, the streams go to
Bijection's hosted telemetry store, which stamps every record with your
installation and meters the `records` and `bytes` it accepts. To send them to
your own OpenTelemetry collector instead, bind the slot. `url` is the
collector's OTLP/HTTP base URL: logs and the audit go to `<url>/v1/logs`,
traces to `<url>/v1/traces`, with `credential` presented as a bearer.

```ts bindings.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { placement } from "@bijectionhq/bijection";
const { bind, bindings, otlp, platform } = placement;

export default bindings([
  bind(platform.telemetry, otlp({ url: "https://otlp.example.com", credential: "telemetry.token" })),
]);
```

A slot has one provider: to fan telemetry out to several sinks, bind your own
collector and fan out there. Log lines kept inside the installation, such as
`sys.logs`, stay whatever `platform.telemetry` is bound to.

## Configuring an export

Exports are configured in code. Place one installation of
`@bijectionhq/library-log-export` per sink in your app tree. Each call at a
path is its own installation, with its own buffer and status.

```ts bijection/app.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { app, secret } from "@bijectionhq/bijection";
import { logExport, otlp, webhook } from "@bijectionhq/library-log-export";

const otlpToken = secret();
const webhookKey = secret();

export default app({
  otlpToken,
  webhookKey,
  logs: logExport(otlp("https://otlp.example.com", { bearer: otlpToken }), {
    site: "orders.place",
    resource: { "service.name": "orders", "deployment.environment.name": "production" },
  }),
  archive: logExport(webhook("https://logs.example.com/bijection", { sign: webhookKey }), { site: "orders.place", levels: ["warn", "error"] }),
});
```

Set the values of these declarations with `bijection secret set otlpToken`
and `bijection secret set webhookKey`. For an OTLP endpoint that uses a named
header, pass `{ header: { name: "x-api-key", secret: otlpToken } }`.

| Option | Default | Meaning |
| - | - | - |
| `otlp(url, { bearer, header, headers })` | | OTLP/HTTP logs to `url`. Its path defaults to `/v1/logs`. `headers` are fixed, non-secret headers. |
| `webhook(url, { sign, headers })` | | One signed JSON `POST` per batch to `url`. |
| `site` | The installed writer site to export. | |
| `under` | a label of its own (public lines only) | The label the export reads under: it exports exactly the lines that label clears. |
| `levels` | all | The levels exported: `debug`, `info`, `log`, `warn`, `error`. |
| `resource` | `{ "service.name": "bijection" }` | Resource attributes every batch carries. |
| `every` | 5 seconds | How often new lines are taken and batches sent (at least one second). |
| `batch` | `{ lines: 256, bytes: 512 KiB }` | The most lines and bytes in one batch. |
| `buffer` | 100 000 | The most lines waiting to be sent. |
| `readers` | none | Roles that may read `status`. |

A sink must be reachable over HTTPS at a public internet address. The
installation checks the address each request connects to, including addresses
returned by DNS, and refuses loopback, private network, link-local, cloud
instance metadata, shared carrier (CGNAT) and other reserved addresses.

## What is exported

Each exported line is a [`sys.logs`](https://docs.bijection.com/operate/observability/logs) line: one
line one function logged with `console.debug`, `info`, `log`, `warn` or
`error`, whether its run committed or was refused.

### OpenTelemetry records

Each batch is one OTLP `ExportLogsServiceRequest`, with your `resource`
attributes as its resource (plus `bijection.installation`) and one scope,
`bijection.logs`. Each line is one log record:

| Field | Value |
| - | - |
| `timeUnixNano` | when the line was logged |
| `severityNumber`, `severityText` | `debug` 5, `info` 9, `log` 10, `warn` 13, `error` 17; the level in upper case |
| `body` | the message |
| `log.record.uid` | the line's identity, `<execution>:<line>` |
| `code.function.name` | the function's tree path, such as `shop.orders.place` |
| `bijection.execution`, `bijection.line` | the run, and the line's number within it |
| `bijection.refusal.code`, `bijection.refusal.reason` | present when the run was refused |

### Webhook body

```json theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
{
  "type": "bijection.logs",
  "batch": "k1x2…",
  "sequence": 42,
  "resource": { "service.name": "orders" },
  "lines": [
    {
      "id": "6f1c…:00000001",
      "execution": "6f1c…",
      "line": 1,
      "function": "orders.place",
      "level": "warn",
      "message": "'low stock'",
      "code": "Conflict",
      "at": "2026-11-26T09:30:00.123Z"
    }
  ]
}
```

`code` and `reason` are left out when the run ended ok. `sequence` numbers
the installation's batches in order.

## Securing webhooks

Every webhook request is signed as
[Standard Webhooks](https://www.standardwebhooks.com/) with the
installation's `key`. The `webhook-id` header is the batch's identity, the
same on every attempt of that batch. `webhook-timestamp` is the send time, and
`webhook-signature` is the HMAC-SHA256 signature of
`<webhook-id>.<webhook-timestamp>.<body>`. To rotate the key, make the
receiver accept both keys, set the new value with
`bijection secret set webhookKey`, then retire the old one.

Verify a request with any Standard Webhooks library before trusting its body,
and refuse a `webhook-timestamp` outside a few minutes to prevent replays:

```typescript theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { Hono } from "hono";
import { Webhook } from "standardwebhooks";

const app = new Hono();
const webhook = new Webhook(process.env.WEBHOOK_SECRET!);
const seen = new Set<string>();

app.post("/bijection", async (c) => {
  const body = await c.req.text();
  const headers = Object.fromEntries(c.req.raw.headers);
  try {
    // Checks the signature and refuses a timestamp more than five minutes off.
    webhook.verify(body, headers);
  } catch {
    c.status(401);
    return c.text("Unauthorized");
  }
  // A batch can arrive twice: deduplicate on its webhook-id.
  if (seen.has(headers["webhook-id"]!)) return c.text("Duplicate");
  seen.add(headers["webhook-id"]!);
  const { lines } = JSON.parse(body) as { lines: unknown[] };
  return c.text(`Received ${lines.length} lines`);
});

export default app;
```

## Delivery

Every tick the export reads the newest lines its label clears, takes the ones
logged since the last tick and buffers them in order. Then, while fewer than
four batches are unsettled, it sends the oldest buffered lines as one batch.

* A 2xx answer delivers the batch. An OpenTelemetry partial success
  delivers it less the records it rejects.
* Another 4xx rejects the batch, and its lines are dropped.
* A 5xx, a 408 or 429, a failed connection or a lost reply is tried again
  with the same body after a backoff (5 seconds, doubling, at most 5 minutes),
  until the batch's oldest line is a day old.

Delivery is at least once: a lost reply is sent again, so deduplicate on
`webhook-id` or `log.record.uid`. Batches can arrive out of order; use
`sequence` or the timestamps. When a sink is down, lines wait in the buffer
for up to a day. A full buffer drops new lines.

One tick reads at most 256 lines. If an installation commits more than that
between two ticks, the lines below the read are not exported, and the export
counts a gap. Shorten `every` for an installation that logs that much.

## Status

Each installation answers `status`: its sink and endpoint, the lines buffered
and in flight, the oldest unsent line (the lag), and how many lines were
delivered, rejected, refused, expired or dropped, how many gaps it counted,
its last delivery and its last error. Read it with
`bijection query logs.status`, or in the console under
**Settings → Integrations**, where the log export card shows it for the path
you name. The console shows status only; configuration stays in code.


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