> ## Documentation Index
> Fetch the complete documentation index at: https://docs.latwoodtech.com/llms.txt
> Use this file to discover all available pages before exploring further.

# @adrper79-dot/monitoring

> Sentry error reporting for Cloudflare Workers.

# @adrper79-dot/monitoring

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

## Installation

```bash theme={null}
npm install @adrper79-dot/monitoring
```

## Bindings required

```jsonc theme={null}
// 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.

```typescript theme={null}
function initSentry(opts: {
  dsn: string;
  environment?: string;
  release?: string;
}): SentryClient;
```

### `captureException(client, error, context?)`

Reports a `FactoryError` or unknown error to Sentry.

```typescript theme={null}
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.

```typescript theme={null}
function withSentry(
  handler: MiddlewareHandler,
  opts: { dsn: string; environment?: string },
): MiddlewareHandler;
```

## Example

```typescript theme={null}
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',
}));
```
