@loglayer/transport-sentry
v2.0.2
Published
Sentry transport for the LogLayer logging library.
Maintainers
Readme
@loglayer/transport-sentry
Sentry transport for the LogLayer logging library. This transport sends structured logs to Sentry using any Sentry logger instance.
Installation
npm install @loglayer/transport-sentry serialize-error <sentry-sdk>yarn add @loglayer/transport-sentry serialize-error <sentry-sdk>pnpm add @loglayer/transport-sentry serialize-error <sentry-sdk>Replace <sentry-sdk> with the appropriate Sentry SDK for your platform:
- Browser: @sentry/browser
- Next.js: @sentry/nextjs
- Bun: @sentry/bun
- Deno: @sentry/deno
- Node.js: @sentry/node
Usage
import { LogLayer } from "loglayer";
import { SentryTransport } from "@loglayer/transport-sentry";
import { serializeError } from "serialize-error";
// node.js example, but most of the JS-based SDKs follow this pattern
import * as Sentry from "@sentry/node";
// 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
Sentry.init({
dsn: "YOUR_SENTRY_DSN",
enableLogs: true,
});
const log = new LogLayer({
errorSerializer: serializeError,
transport: [
new SentryTransport({
logger: Sentry.logger,
}),
],
});
// Use LogLayer as normal
log.withMetadata({ userId: 123 }).info("User logged in");
log.withError(new Error("Something went wrong")).error("Operation failed");Documentation
For more detailed documentation, visit the LogLayer website.
