---
title: "Custom Instrumentation"
description: "Leverage the re-exported Sentry SDK to record custom spans, breadcrumbs, tags, and messages."
canonical_url: "https://eienjs.com/packages/adonisjs-sentry/advanced/custom-instrumentation"
---

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

`@eienjs/adonisjs-sentry` directly re-exports the full `@sentry/node` namespace through `Sentry`. You can import `Sentry` anywhere in your application without adding duplicate dependencies:

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

## Adding Breadcrumbs

Breadcrumbs record a trail of events that took place prior to an error. Sentry automatically captures console and HTTP breadcrumbs, but you can add business-level milestones manually:

```ts [app/services/checkout_service.ts]
import { Sentry } from '@eienjs/adonisjs-sentry';

export class CheckoutService {
  async processCart(cartId: string) {
    Sentry.addBreadcrumb({
      category: 'checkout',
      message: `Starting checkout validation for cart ${cartId}`,
      level: 'info',
      data: { cartId },
    });

    // ... continue processing
  }
}
```

## Capturing Custom Messages

To log informational or warning events to Sentry without throwing an exception:

```ts [app/services/subscription_service.ts]
import { Sentry } from '@eienjs/adonisjs-sentry';

export class SubscriptionService {
  renewSubscription(subscriptionId: string) {
    Sentry.captureMessage(`Auto-renewal grace period triggered for ${subscriptionId}`, 'warning');
  }
}
```

## Custom Spans and Background Tasks

For long-running background tasks, queue jobs, or external API interactions, create custom spans with `Sentry.startSpan`:

```ts [app/tasks/sync_inventory.ts]
import { Sentry } from '@eienjs/adonisjs-sentry';

export async function syncInventory() {
  return await Sentry.startSpan(
    {
      name: 'inventory.sync',
      op: 'task.sync',
    },
    async (span) => {
      span.setAttribute('sync.source', 'warehouse_api');

      const items = await fetchWarehouseItems();
      span.setAttribute('sync.items_count', items.length);

      await updateDatabaseRecords(items);
    }
  );
}
```

## Setting Custom Tags and Context

You can enrich the current scope with domain-specific metadata that helps you query and filter issues in Sentry:

```ts [app/controllers/tenants_controller.ts]
import type { HttpContext } from '@adonisjs/core/http';
import { Sentry } from '@eienjs/adonisjs-sentry';

export default class TenantsController {
  async show({ params }: HttpContext) {
    Sentry.setTag('tenant.plan', 'enterprise');
    Sentry.setContext('tenant', {
      id: params.id,
      region: 'us-east-1',
    });

    // ...
  }
}
```

## Sitemap

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