@logtape/sentry
Version:
LogTape Sentry sink
120 lines (118 loc) • 3.67 kB
text/typescript
import { LogRecord, Sink } from "@logtape/logtape";
import { SeverityLevel } from "@sentry/core";
//#region src/mod.d.ts
/**
* A Sentry client instance type (used for v1.1.x backward compatibility).
*
* Client instances only support `captureMessage` and `captureException`.
* For scope operations (breadcrumbs, user context, traces), the sink always
* uses global functions from `@sentry/core`.
*
* @deprecated This is only used for backward compatibility with v1.1.x.
* New code should use `getSentrySink()` without parameters, which automatically
* uses Sentry's global functions.
*
* @since 1.3.0
*/
interface SentryInstance {
captureMessage: (message: string, captureContext?: SeverityLevel | unknown) => string;
captureException: (exception: unknown, hint?: unknown) => string;
}
/**
* Options for configuring the Sentry sink.
* @since 1.3.0
*/
interface SentrySinkOptions {
/**
* Enable automatic breadcrumb creation for log events.
*
* When enabled, all logs become breadcrumbs in Sentry's isolation scope,
* providing a complete context trail when errors occur. Breadcrumbs are
* lightweight and only appear in error reports for debugging.
*
* @default false
* @since 1.3.0
*/
enableBreadcrumbs?: boolean;
/**
* Optional hook to transform or filter records before sending to Sentry.
* Return `null` to drop the record.
*
* @since 1.3.0
*/
beforeSend?: (record: LogRecord) => LogRecord | null;
}
/**
* Gets a LogTape sink that sends logs to Sentry.
*
* This sink uses Sentry's global capture functions from `@sentry/core`,
* following Sentry v8+ best practices. Simply call `Sentry.init()` before
* creating the sink, and it will automatically use your initialized client.
*
* @param optionsOrClient Optional configuration. Can be:
* - Omitted: Uses global Sentry functions (recommended)
* - Object with options: Configure sink behavior
* - Sentry client instance: Backward compatibility (deprecated)
* @returns A LogTape sink that sends logs to Sentry.
*
* @example Recommended usage - no parameters
* ```typescript
* import { configure } from "@logtape/logtape";
* import { getSentrySink } from "@logtape/sentry";
* import * as Sentry from "@sentry/node";
*
* Sentry.init({ dsn: process.env.SENTRY_DSN });
*
* await configure({
* sinks: {
* sentry: getSentrySink(), // That's it!
* },
* loggers: [
* { category: [], sinks: ["sentry"], lowestLevel: "error" },
* ],
* });
* ```
*
* @example With options
* ```typescript
* import * as Sentry from "@sentry/node";
* Sentry.init({ dsn: process.env.SENTRY_DSN });
*
* await configure({
* sinks: {
* sentry: getSentrySink({
* enableBreadcrumbs: true,
* }),
* },
* loggers: [
* { category: [], sinks: ["sentry"], lowestLevel: "info" },
* ],
* });
* ```
*
* @example Edge functions - must flush before termination
* ```typescript
* // Cloudflare Workers
* export default {
* async fetch(request, env, ctx) {
* logger.error("Something happened");
* ctx.waitUntil(Sentry.flush(2000)); // Don't block response
* return new Response("OK");
* }
* };
* ```
*
* @example Legacy usage (v1.1.x - deprecated)
* ```typescript
* import { getClient } from "@sentry/node";
* const client = getClient();
* getSentrySink(client); // Still works but shows deprecation warning
* ```
*
* @since 1.0.0
*/
declare function getSentrySink(optionsOrClient?: SentrySinkOptions | SentryInstance): Sink;
//# sourceMappingURL=mod.d.ts.map
//#endregion
export { SentryInstance, SentrySinkOptions, getSentrySink };
//# sourceMappingURL=mod.d.cts.map