Skip to Content
Docs

Log drain to Sentry

Send the logs of your workspace to Sentry Logs.

The type sentry of a log drain sends the records to the Sentry Logs of a project. It also works with self-hosted Sentry. You need an API key with the scope log_drains:write.

Make the log drain

Copy the DSN of the project from the Sentry project settings (Client Keys). Then make the log drain. Use filters to send only the errors, for example:

curl https://api.afffast.com/v1/log_drains \
  -H "Authorization: Bearer sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "type": "sentry",
    "label": "Sentry",
    "config": {},
    "credentials": { "dsn": "https://<key>@o123.ingest.sentry.io/456" },
    "sources": ["api_request", "sync_run"],
    "filters": { "api_request": { "levels": ["error"] } }
  }'
  • The DSN must use https. It must not point to a private or internal address. The API checks the address at each request, after the DNS lookup. The API does not follow a redirect.
  • The API never returns the DSN.

POST /v1/log_drains/{id}/test sends one sample record. Its body starts with [test].

What Sentry gets

The API sends one envelope with one log item for each batch (100 records or 512 KB at most) to https://<host>/api/<project ID>/envelope/. The request has the header X-Sentry-Auth with the public key of the DSN.

Record levelSentry levelSeverity number
infoinfo9
warningwarn13
errorerror17
  • body is a short line, for example API request GET /v1/links 200.
  • timestamp is the time of the event of the record.
  • The attributes are afffast.record_id, afffast.source, afffast.workspace, afffast.livemode, afffast.test and sentry.environment (live or test). The fields of data are afffast.data.<name>. Nested objects use a dot in the name. An array is JSON text. A text has 1024 bytes at most. A log has 64 attributes at most.
  • A log has a trace_id. It is a hash of the record ID, because the records have no trace.

Rate limits

The API obeys the rate limits of Sentry. On a 429 answer, and on a 200 answer that has a limit for logs (log_item or log_byte, or all categories) in the header X-Sentry-Rate-Limits, the API waits for the time that Sentry says (the header Retry-After is the second choice). It does not count this as a failure.

Errors

Answer of SentryWhat the API does
200The batch is done.
429, or a limit for logsThe API waits and tries again.
400, 401, 403, 404, 413, a redirectThe API stops the log drain at once (failing) and says the reason.
408, 5xx, other, no answerThe API tries again with a growing wait.

Delivery is at least once. Sentry does not remove duplicates, so a log can appear two times. Use the attribute afffast.record_id to find them.

On this page