import { O as OnErrorHook } from '../_dts-chunks/on-error.d-DGMUFaZB.d.ts'; export { g as getGlobalOnError, s as setGlobalOnError } from '../_dts-chunks/on-error.d-DGMUFaZB.d.ts'; import '../_dts-chunks/nextly-error.d-WlStqaV9.d.ts'; import '../_dts-chunks/error-codes.d-CbwkO1ux.d.ts'; /** * Structured logger seam used by nextly. * * The default implementation writes JSON to console.{error,warn,info,debug}. * Works on every serverless and edge runtime without setup. Developers swap * it for Pino/Winston/Bunyan/etc. via `setNextlyLogger`. * * Full observability design (dev-vs-prod formatting, scrub list, audit log, */ interface NextlyLogger { error(payload: object): void; warn(payload: object): void; info(payload: object): void; debug(payload: object): void; } /** * Replace the active logger. Pass `undefined` to restore the default JSON-to-console implementation. * * Typical use lives in `app/instrumentation.ts` via `createNextlyInstrumentation({ logger })`, * but this setter is exposed for direct wiring or testing. */ declare function setNextlyLogger(logger: NextlyLogger | undefined): void; /** The currently registered logger. Used internally by withErrorHandler / withAction / instrumentation. */ declare function getNextlyLogger(): NextlyLogger; type InstrumentationOptions = { /** Process-wide observability hook (Sentry/Datadog/OTEL wiring). */ onError?: OnErrorHook; /** Replace the default JSON-to-console logger. */ logger?: NextlyLogger; }; type RequestSummary = { path: string; method: string; headers: Headers; }; type RouteContext = { routerKind: string; routePath: string; routeType: string; }; /** * Helper for the developer's `app/instrumentation.ts`. Registers the logger * and global onError hook, and returns an `onRequestError` to re-export * from instrumentation so Next.js's framework-level error capture * (Server Components, middleware, Pages Router) flows through the unified * pipeline and pairs `error.digest` with our `requestId`. * * **Idempotency:** calling this twice in the same runtime overwrites the * prior logger / onError registration. In practice `instrumentation.ts` * runs once per Next.js runtime (Node and Edge get their own module graph), * so this is fine — but later calls win. * * **Framework-kind error wrapping:** when the global onError hook fires * with `kind: "framework"`, the `err` is always a NextlyError. If the * original framework error wasn't already a NextlyError, it gets wrapped * via `NextlyError.internal({ cause })`. Sentry-style handlers should read * `err.cause ?? err` to surface the original. * * Typical usage: * * ```ts * // app/instrumentation.ts * import { createNextlyInstrumentation } from "nextly/observability"; * import * as Sentry from "@sentry/nextjs"; * * const nextly = createNextlyInstrumentation({ * onError: (err, ctx) => * Sentry.captureException(err.cause ?? err, { * tags: { code: err.code, kind: ctx.kind }, * extra: { requestId: ctx.requestId, ...err.logContext }, * }), * }); * * export const onRequestError = nextly.onRequestError; * ``` */ declare function createNextlyInstrumentation(opts?: InstrumentationOptions): { onRequestError: (error: unknown, request: RequestSummary, context: RouteContext) => Promise; }; export { OnErrorHook, createNextlyInstrumentation, getNextlyLogger, setNextlyLogger }; export type { NextlyLogger };