---
title: "Functions and Classes"
description: "API reference for defineConfig, reportException, SentryMiddleware, and SentryProvider."
canonical_url: "https://eienjs.com/packages/adonisjs-sentry/api-reference/functions-and-classes"
---

> Index of every page on this site: [llms.txt](https://eienjs.com/llms.txt)

This page provides the API reference for functions, classes, and exported services in `@eienjs/adonisjs-sentry`.

## Functions

### `defineConfig(config)`

Validates and returns the Sentry configuration object for AdonisJS.

```ts
import { defineConfig } from '@eienjs/adonisjs-sentry';

export default defineConfig({
  enabled: true,
  environment: 'production',
  dsn: 'https://...',
});
```

- **Parameters**:

  - `config` ([`SentryConfig`](https://eienjs.com/packages/adonisjs-sentry/api-reference/types#sentryconfig)): Sentry configuration options.
- **Returns**: `SentryConfig`
- **Throws**:

  - `RuntimeException`: When `environment` is missing or empty.
  - `RuntimeException`: When `enabled` is `true` but `dsn` is missing or undefined.

---

### `reportException(error, ctx?)`

Captures an exception in Sentry with contextual metadata and tags.

```ts
import { reportException } from '@eienjs/adonisjs-sentry';

// Inside HttpExceptionHandler
const eventId = reportException(error, ctx);

// Standalone in background job or service
const eventId = reportException(error);
```

- **Parameters**:

  - `error` (`unknown`): The exception or error to capture.
  - `ctx` (`HttpContext`, optional): The AdonisJS HTTP context for the current request.
- **Returns**: `string | undefined` — The generated Sentry event ID, or `undefined` if Sentry is disabled, uninitialized, or the exception matches an ignore list.

---

### `configure(command)`

Invoked internally by AdonisJS during `node ace configure @eienjs/adonisjs-sentry`.

- **Parameters**:

  - `command` (`ConfigureCommand`): The Ace configure command instance.

---

## Exports

### `Sentry`

A direct re-export of the entire `@sentry/node` SDK namespace.

```ts
import { Sentry } from '@eienjs/adonisjs-sentry';

Sentry.captureMessage('Order placed', 'info');
Sentry.addBreadcrumb({ category: 'cart', message: 'Item added' });
```

---

### `stubsRoot`

Absolute filesystem path pointing to the package's `stubs/` directory.

```ts
import { stubsRoot } from '@eienjs/adonisjs-sentry';
```

---

## Classes

### `SentryMiddleware`

*Import path: @eienjs/adonisjs-sentry/middleware/sentry_middleware*

AdonisJS router middleware that isolates the Sentry scope for each HTTP request and instruments root spans.

#### Methods

- `handle(ctx: HttpContext, next: NextFn): Promise<unknown>`
  - Evaluates whether Sentry is initialized.
  - Wraps execution in `Sentry.withIsolationScope(...)`.
  - Sets transaction name `${method} ${pattern}` and updates the active root span.
  - Attaches `route`, `http.method`, and `request_id` tags.

---

### `SentryProvider`

*Import path: @eienjs/adonisjs-sentry/providers/sentry_provider*

The service provider registered in `adonisrc.ts`.

#### Methods

- `register(): Promise<void>`
  - Reads `config/sentry.ts`.
  - Configures global reporting options via `configureReporting(report)`.
  - Initializes `Sentry.init(options)` if enabled and not already initialized.
- `shutdown(): Promise<void>`
  - Flushes queued events and closes the Sentry client with a 2-second timeout (`Sentry.close(2000)`).

---

### `VerifySentryIntegration`

*Import path: @eienjs/adonisjs-sentry/commands/verify_sentry_integration*

Ace command class representing `node ace sentry:verify`.

#### Properties

- `static commandName`: `'sentry:verify'`
- `static description`: `'Generate a test event and send it to Sentry'`

## Sitemap

See the full [sitemap](https://eienjs.com/sitemap.md) for all pages.
