import { LogRecord, Sink } from "@logtape/logtape"; import { LogSeverityLevel, ParameterizedString, 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; } /** * A Sentry SDK namespace object. * * Pass the namespace imported by your application when *@logtape/sentry* should * use the same Sentry module instance that initialized your app, for example * `import * as Sentry from "@sentry/node"`. * * @since 2.2.0 */ interface SentryNamespace { /** * Captures a message event and sends it to Sentry. */ captureMessage(message: ParameterizedString, captureContext?: SeverityLevel | unknown): string; /** * Captures an exception event and sends it to Sentry. */ captureException(exception: unknown, hint?: unknown): string; /** * Gets the currently active span, if any. */ getActiveSpan(): { spanContext: () => { traceId: string; spanId: string; parentSpanId?: string; }; } | undefined; /** * Gets the currently active Sentry client, if any. */ getClient(): { getOptions: () => { enableLogs?: boolean; _experiments?: { enableLogs?: boolean; }; }; } | undefined; /** * Gets the current isolation scope. */ getIsolationScope(): { addBreadcrumb: (breadcrumb: { category: string; level: SeverityLevel; message: string; timestamp: number; data: Record; }) => void; } | undefined; /** * Sentry's structured logging API, available in Sentry SDK 9.41.0+. */ logger?: Partial) => void>>; } /** * Options for configuring the Sentry sink. * @since 1.3.0 */ interface SentrySinkOptions { /** * Sentry SDK namespace to use for capture, scope, span, and structured log * APIs. * * This is useful when your application initializes Sentry through a framework * SDK such as `@sentry/nextjs` or `@sentry/react-native`, and * *@logtape/sentry* resolves a different `@sentry/core` module instance. * * @example * ```typescript * import * as Sentry from "@sentry/node"; * * getSentrySink({ sentry: Sentry }); * ``` * * @default `@sentry/core` * @since 2.2.0 */ sentry?: SentryNamespace; /** * 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` by * default, following Sentry v8+ best practices. Simply call `Sentry.init()` * before creating the sink, and it will automatically use your initialized * client when both packages resolve the same Sentry module instance. * * @param optionsOrClient Optional configuration. Can be: * - Omitted: Uses global Sentry functions (recommended) * - Object with options: Configure sink behavior * - Object with `sentry`: Use an application-provided Sentry SDK namespace * - 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 an application-provided Sentry namespace * ```typescript * import { configure } from "@logtape/logtape"; * import { getSentrySink } from "@logtape/sentry"; * import * as Sentry from "@sentry/nextjs"; * * Sentry.init({ dsn: process.env.SENTRY_DSN }); * * await configure({ * sinks: { * sentry: getSentrySink({ sentry: Sentry }), * }, * 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, SentryNamespace, SentrySinkOptions, getSentrySink }; //# sourceMappingURL=mod.d.ts.map