Skip to content

Sentry

npmJSRJSR Score

Sentry error tracking for GramIO with automatic error capture, user identification, breadcrumbs, and optional tracing. Uses @sentry/core for runtime-agnostic support (Bun + Node.js).

Installation

sh
npm install @gramio/sentry
sh
yarn add @gramio/sentry
sh
pnpm add @gramio/sentry
sh
bun add @gramio/sentry

Usage

typescript
import { Bot } from "gramio";
import { sentryPlugin } from "@gramio/sentry";

const bot = new Bot(process.env.BOT_TOKEN!)
    .extend(sentryPlugin({
        setUser: true,
        breadcrumbs: true,
        tracing: false,
    }))
    .command("test", (context) => {
        context.sentry.captureMessage("Something happened");
        context.sentry.setTag("custom", "value");
    });

await bot.start();

Options

OptionTypeDescription
setUserbooleanAutomatically set the Sentry user from context.from
breadcrumbsbooleanAdd a breadcrumb for each update and API call
tracingbooleanEnable per-update isolation scopes and spans

Methods

All methods are available on context.sentry:

captureMessage(msg)

Sends a message event to Sentry:

typescript
context.sentry.captureMessage("User reached step 3");

captureException(error)

Captures an exception and sends it to Sentry:

typescript
try {
    await riskyOperation();
} catch (error) {
    context.sentry.captureException(error);
}

setTag(key, value)

Sets a tag on the current Sentry scope:

typescript
context.sentry.setTag("feature", "onboarding");

setExtra(key, value)

Attaches extra data to the current Sentry scope:

typescript
context.sentry.setExtra("payload", context.message);