Sentry
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/sentrysh
yarn add @gramio/sentrysh
pnpm add @gramio/sentrysh
bun add @gramio/sentryUsage
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
| Option | Type | Description |
|---|---|---|
setUser | boolean | Automatically set the Sentry user from context.from |
breadcrumbs | boolean | Add a breadcrumb for each update and API call |
tracing | boolean | Enable 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);