Skip to content

Sentry Transport Browser Server Deno Bun

npm versionTransport Source

The Sentry transport for LogLayer sends structured logs to Sentry using the Sentry SDK's logger API. This transport integrates seamlessly with Sentry's structured logging features and supports all Sentry log levels.

Installation

bash
npm install @loglayer/transport-sentry serialize-error <sentry-sdk>
bash
yarn add @loglayer/transport-sentry serialize-error <sentry-sdk>
bash
pnpm add @loglayer/transport-sentry serialize-error <sentry-sdk>

Replace <sentry-sdk> with the appropriate Sentry SDK for your platform:

Setup

First, initialize Sentry with structured logging enabled for your platform:

typescript
// Node.js example, but most of the JS-based SDKs follow this pattern
// Also in most cases, you'll want to initialize at the top-most entrypoint
// to your app so Sentry can instrument your code, such as the index.ts file
import * as Sentry from "@sentry/node";

Sentry.init({
  dsn: "YOUR_SENTRY_DSN",
  enableLogs: true,
});

Then configure LogLayer with the Sentry transport:

typescript
// logger.ts
import * as Sentry from "@sentry/node";
import { LogLayer } from "loglayer";
import { SentryTransport } from "@loglayer/transport-sentry";
import { serializeError } from "serialize-error";

const log = new LogLayer({
  errorSerializer: serializeError, 
    new SentryTransport({
      logger: Sentry.logger,
    }),
  ],
});

Configuration

Required Parameters

NameTypeDescription
loggerSentryLoggerThe Sentry logger instance to use for logging

Optional Parameters

NameTypeDefaultDescription
idstringAuto-generatedAn identifier for the transport
enabledbooleantrueIf false, the transport will not send logs to the logger
level"trace" | "debug" | "info" | "warn" | "error" | "fatal""trace"Minimum log level to process
consoleDebugbooleanfalseIf true, the transport will log to the console for debugging purposes

Changelog

View the changelog here.