Skip to main content

@adrper79-dot/monitoring

Sentry integration scoped to Cloudflare Workers. Depends on @adrper79-dot/errors.

Installation

npm install @adrper79-dot/monitoring

Bindings required

// wrangler.jsonc vars (or secrets for DSN)
// Set via: wrangler secret put SENTRY_DSN

API

initSentry(opts)

Initializes the Sentry client for the current request lifecycle.
function initSentry(opts: {
  dsn: string;
  environment?: string;
  release?: string;
}): SentryClient;

captureException(client, error, context?)

Reports a FactoryError or unknown error to Sentry.
function captureException(
  client: SentryClient,
  error: unknown,
  context?: Record<string, unknown>,
): void;

withSentry(handler, opts)

Wraps a Hono handler to automatically catch and report unhandled errors.
function withSentry(
  handler: MiddlewareHandler,
  opts: { dsn: string; environment?: string },
): MiddlewareHandler;

Example

import { withSentry } from '@adrper79-dot/monitoring';
import { Hono } from 'hono';

const app = new Hono();

app.use('*', withSentry((c, next) => next(), {
  dsn: c.env.SENTRY_DSN,
  environment: 'production',
}));