--- title: "Error reporting" description: "Report Beignet HTTP, job, schedule, outbox, and task failures through ErrorReporterPort, memory tests, and Sentry providers." url: "https://www.beignetjs.com/error-reporting" markdown_url: "https://www.beignetjs.com/markdown/error-reporting.md" framework_version: "0.0.65" documentation_scope: "current-checkout" source_revision: "e5b4771b262efbdd036e3a40a514c08d1508316c" source_modified: true --- # Error reporting and alerting Beignet separates three observability concerns: - **Logging** records structured runtime facts. - **Error reporting** captures exceptions and failure context for triage. - **Alerting** turns symptoms into operator action. Use `ErrorReporterPort` when application code needs to report an unexpected failure without importing a vendor SDK. ## Capture errors Declare `errorReporter` as an app port and report unexpected failures from use cases, jobs, schedules, outbox drains, and tasks: ```typescript await ctx.ports.errorReporter.captureException(error, { level: "error", requestId: ctx.requestId, traceId: ctx.traceId, tags: { feature: "billing", }, contexts: { tenant: { id: ctx.tenant.id }, }, }); ``` Capture messages for important non-exception signals: ```typescript await ctx.ports.errorReporter.captureMessage("Payment provider degraded", { level: "warning", tags: { provider: "stripe" }, }); ``` Expected business failures such as validation failures, not-found results, denied policies, and known catalog errors usually belong in logs or audit records, not high-priority exception alerts. ## Setup with Sentry Install the Sentry provider: ```bash bun add @beignet/provider-error-reporting-sentry @sentry/node ``` Register it in `server/providers.ts`. Provider-contributed ports replace earlier bound ports during startup, so a generated app can keep its local `createNoopErrorReporter()` fallback and let this provider replace it when Sentry is installed. ```typescript import { createSentryErrorReportingProvider } from "@beignet/provider-error-reporting-sentry"; export const providers = [ createSentryErrorReportingProvider({ dsn: process.env.SENTRY_DSN, init: { environment: process.env.NODE_ENV, }, }), ]; ``` The provider contributes `ctx.ports.errorReporter` and `ctx.ports.sentry` as an escape hatch for advanced Sentry operations. With no `dsn`, `SENTRY_DSN`, or explicit `init` options, the provider contributes the port without initializing Sentry. When the app registers a separate OpenTelemetry SDK, configure Sentry for that SDK as described in [OpenTelemetry](https://www.beignetjs.com/markdown/observability.md#errors-and-sentry). ## Sentry SDK versions The provider supports `@sentry/node` **10.58+ within major 10** and **11.9+ within major 11**. The CLI installs `^11.10.0` for new Sentry integrations. Existing apps can stay on v10; upgrading Beignet does not require upgrading Sentry. Sentry 11 replaces `sendDefaultPii` with `dataCollection` and enables more automatic collection by default. When Beignet initializes v11, it applies conservative defaults: automatic user/IP data, cookies, HTTP bodies, database query parameters, queue payloads, GenAI inputs/outputs, MCP inputs/outputs, and GraphQL documents/variables are disabled. Request/response headers and URL query parameters use Sentry's documented v10-style exclusions for `forwarded`, `-ip`, `remote-`, `via`, and `-user`. Other SDK collection and filtering behavior remains in effect. Opt into only the categories your application needs: ```typescript createSentryErrorReportingProvider({ dsn: process.env.SENTRY_DSN, init: { dataCollection: { cookies: { allow: ["locale"] }, genAI: { inputs: true }, }, }, }); ``` Omitted or `undefined` settings retain Beignet's defaults, including nested fields: enabling GenAI inputs does not enable outputs or MCP collection. Sentry 11.9 is required for independent GenAI and MCP settings; earlier v11 releases reuse the GenAI settings for MCP payloads and are unsupported. Explicit header allow/deny rules replace the corresponding default rule. This policy applies to initialization through `createSentryErrorReportingProvider`; `createSentryErrorReporter` wraps an already configured client and does not change its settings. Explicit capture metadata, exception messages, and stacks still need app-owned filtering as described under [context and redaction guidance](https://www.beignetjs.com/markdown/error-reporting.md#what-context-to-send). `init` exposes the installed SDK's native options. On v10, keep using `sendDefaultPii` and, for an app-owned OpenTelemetry pipeline, `skipOpenTelemetrySetup: true`. On v11, use `dataCollection` and `enableOpenTelemetrySetup: false` with `openTelemetryIntegration()` to link errors to existing spans. See [Sentry's migration guide](https://github.com/getsentry/sentry-javascript/blob/11.10.0/MIGRATION.md#upgrading-from-10x-to-11x) for other SDK changes, including self-hosted server requirements. Use a supported Node LTS release; Sentry 11 excludes Node 23.0–23.1 and requires Bun 1.3.14+ when running on Bun. ## HTTP request errors Install `createErrorReportingHooks(...)` in `server/index.ts` to capture unexpected route, hook, response-validation, and server failures. The hook observes caught errors without changing response mapping. Use `mapUnhandledError` only to decide the response body. ```typescript import { createErrorReportingHooks, createIdempotencyHooks, } from "@beignet/core/server"; import { createNextServer, createNextServerLoader } from "@beignet/next"; import type { AppContext } from "@/app-context"; import { initialPorts } from "@/infra/port-wiring"; import { appContext } from "./context"; import { routes } from "./routes"; export const getServer = createNextServerLoader(async () => { const { providers } = await import("./providers"); return createNextServer({ ports: initialPorts, providers, hooks: [ createErrorReportingHooks(), createIdempotencyHooks(), ], context: appContext, routes, mapUnhandledError: ({ err, ctx }) => { ctx?.ports.logger.error("Unhandled API error", { error: err, requestId: ctx?.requestId, }); return { status: 500, body: { code: "INTERNAL_SERVER_ERROR", message: "Internal server error", requestId: ctx?.requestId, }, }; }, }); }); ``` By default the hook captures unexpected failures and skips expected application catalog errors, auth denials, tenant requirements, idempotency conflicts, entitlement denials, and request validation failures. Pass `shouldReport` or `reportOptions` when an app needs different alerting rules or extra tags. Reporting preparation, capture, and failure observation are independently bounded to one second so a reporting backend cannot hold an HTTP response open. Set `timeoutMs` to tune the bound. Use `timeoutMs: false` only when intentionally allowing reporting to block request completion. Callback, resolver, reporter, and timeout failures are isolated and may be observed through `onReporterError`. ## Runtime ownership Report a logical failure once at the boundary that knows it is terminal: | Boundary | Reporting owner | Default behavior | | --------------------------- | -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | | HTTP | `createErrorReportingHooks(...)` | Reports unexpected caught failures; skips catalog, auth, policy, tenancy, idempotency, entitlement, and validation outcomes. | | BullMQ jobs | `createBullMQJobWorker(...)` | Reports terminal, invalid, unknown-job, and worker infrastructure failures. Retry attempts remain instrumentation. | | Inngest jobs | `createInngestJobFunction(...)` | Reports through native `onFailure` after Inngest exhausts retries. | | Next schedule routes | `createScheduleRoute(...)` | Reports a failed invocation that the route converts to a 500 response. | | Next/CLI outbox drains | Drain adapter | Reports dead letters, lease failures, settlement failures, and drain infrastructure failures; scheduled retries are not incidents. | | CLI tasks and schedules | CLI runner | Reports terminal failures and performs a bounded flush before context shutdown. | | Registered listeners | App-owned registration provider | The canonical generated provider reports from `registerListeners(...).onError`. | | Direct core primitive calls | Calling app | Use `tryReportException(...)` at the outer boundary that decides the failure is terminal. | Do not also report inside a handler when its worker, route, or runner owns the terminal boundary; doing both creates duplicate incidents. Prefer durable failure state for work that must be retried or reconciled. Error reporting tells an operator something went wrong; it does not make the work durable. ## What context to send Attach stable identifiers, not raw payloads: | Field | Use | | ------------------------------- | --------------------------------------------------------- | | `requestId` | Correlate logs, devtools, traces, and support tickets | | `traceId` | Connect nested use case, provider, outbox, and job events | | `actorId` | Identify the user, service, or anonymous actor | | `tenantId` | Scope the failure to a tenant or workspace | | `contractName` | Identify the HTTP boundary | | `useCaseName` | Identify the application workflow | | `jobName` | Identify background work | | `outboxMessageId` | Reconcile durable delivery failures | | `resourceType` and `resourceId` | Find the affected record | Do not send request bodies, raw provider responses, access tokens, cookies, passwords, PHI, payment details, private messages, or full authorization headers unless your reporting vendor and retention policy are approved for that data. Beignet applies default sensitive-key redaction to structured Sentry metadata, but it cannot safely rewrite exception messages or infer domain-sensitive fields. `AppError.details` is not automatically redacted and is never copied by the default HTTP hook; treat manual capture of an `AppError` as an explicit data export decision. Use [Privacy lifecycle](https://www.beignetjs.com/markdown/privacy-lifecycle.md) to define which fields may leave app-owned storage and which fields must only appear as stable identifiers. ## Testing `createTestPorts(...)` includes an in-memory `errorReporter` port by default. Use it directly when testing failure paths: ```typescript const { ports, errorReporter } = createTestPorts(); await useCase.run({ ctx: { ports }, input }); expect(errorReporter.reports).toEqual([ expect.objectContaining({ type: "exception", }), ]); ``` You can also import the memory reporter directly: ```typescript import { createMemoryErrorReporter } from "@beignet/core/error-reporting"; const errorReporter = createMemoryErrorReporter(); ``` ## Devtools versus production reporting Devtools are local diagnostics. When devtools are installed before an error reporting provider, captured exceptions and messages appear under the Errors view with request and trace correlation. Use devtools locally, structured logs in production, and a production error reporter for exceptions that operators need to triage. ## Alerting Do not alert on every captured exception. Alert on symptoms that require human action: - elevated 5xx rate - repeated auth or payment provider failures - queue or outbox dead-letter growth - schedule missed-run or failure rate Start with slow, high-signal alerts and add more only when they lead to useful operator action. Every alert should have an owner, a severity, a runbook link, and enough context to find the affected tenant or resource. ## API reference - [`createSentryErrorReportingProvider`](https://www.beignetjs.com/typedoc/functions/_beignet_provider-error-reporting-sentry.createSentryErrorReportingProvider.html) ## Related pages - [Logging](https://www.beignetjs.com/markdown/logging.md) for structured application logs. - [Errors](https://www.beignetjs.com/markdown/errors.md) for app error catalogs and client error handling. - [Outbox](https://www.beignetjs.com/markdown/outbox.md) and [Jobs](https://www.beignetjs.com/markdown/jobs.md) for durable failure semantics. - [Going to production](https://www.beignetjs.com/markdown/deployment.md) for redaction and sensitive data boundaries.