$npx -y skills add getsentry/sentry-for-ai --skill sentry-nestjs-sdkFull Sentry SDK setup for NestJS. Use when asked to "add Sentry to NestJS", "install @sentry/nestjs", "setup Sentry in NestJS", or configure error monitoring, tracing, profiling, logging, metrics, crons, or AI monitoring for NestJS applications. Supports Express and Fastify adapt
| 1 | > [All Skills](../../SKILL_TREE.md) > [SDK Setup](../sentry-sdk-setup/SKILL.md) > NestJS SDK |
| 2 | |
| 3 | # Sentry NestJS SDK |
| 4 | |
| 5 | Opinionated wizard that scans your NestJS project and guides you through complete Sentry setup. |
| 6 | |
| 7 | ## Invoke This Skill When |
| 8 | |
| 9 | - User asks to "add Sentry to NestJS" or "setup Sentry" in a NestJS app |
| 10 | - User wants error monitoring, tracing, profiling, logging, metrics, or crons in NestJS |
| 11 | - User mentions `@sentry/nestjs` or Sentry + NestJS |
| 12 | - User wants to monitor NestJS controllers, services, guards, microservices, or background jobs |
| 13 | |
| 14 | > **Note:** SDK versions and APIs below reflect `@sentry/nestjs` 10.x (NestJS 8–11 supported). |
| 15 | > Always verify against [docs.sentry.io/platforms/node/guides/nestjs/](https://docs.sentry.io/platforms/node/guides/nestjs/) before implementing. |
| 16 | |
| 17 | --- |
| 18 | |
| 19 | ## Phase 1: Detect |
| 20 | |
| 21 | Run these commands to understand the project before making recommendations: |
| 22 | |
| 23 | ```bash |
| 24 | # Confirm NestJS project |
| 25 | grep -E '"@nestjs/core"' package.json 2>/dev/null |
| 26 | |
| 27 | # Check NestJS version |
| 28 | node -e "console.log(require('./node_modules/@nestjs/core/package.json').version)" 2>/dev/null |
| 29 | |
| 30 | # Check existing Sentry |
| 31 | grep -i sentry package.json 2>/dev/null |
| 32 | ls src/instrument.ts 2>/dev/null |
| 33 | grep -r "Sentry.init\|@sentry" src/main.ts src/instrument.ts 2>/dev/null |
| 34 | |
| 35 | # Check for existing Sentry DI wrapper (common in enterprise NestJS) |
| 36 | grep -rE "SENTRY.*TOKEN|SentryProxy|SentryService" src/ libs/ 2>/dev/null |
| 37 | |
| 38 | # Check for config-class-based init (vs env-var-based) |
| 39 | grep -rE "class SentryConfig|SentryConfig" src/ libs/ 2>/dev/null |
| 40 | |
| 41 | # Check if SentryModule.forRoot() is already registered in a shared module |
| 42 | grep -rE "SentryModule\.forRoot|SentryProxyModule" src/ libs/ 2>/dev/null |
| 43 | |
| 44 | # Detect HTTP adapter (default is Express) |
| 45 | grep -E "FastifyAdapter|@nestjs/platform-fastify" package.json src/main.ts 2>/dev/null |
| 46 | |
| 47 | # Detect GraphQL |
| 48 | grep -E '"@nestjs/graphql"|"apollo-server"' package.json 2>/dev/null |
| 49 | |
| 50 | # Detect microservices |
| 51 | grep '"@nestjs/microservices"' package.json 2>/dev/null |
| 52 | |
| 53 | # Detect WebSockets |
| 54 | grep -E '"@nestjs/websockets"|"socket.io"' package.json 2>/dev/null |
| 55 | |
| 56 | # Detect task queues / scheduled jobs |
| 57 | grep -E '"@nestjs/bull"|"@nestjs/bullmq"|"@nestjs/schedule"|"bullmq"|"bull"' package.json 2>/dev/null |
| 58 | |
| 59 | # Detect databases |
| 60 | grep -E '"@prisma/client"|"typeorm"|"mongoose"|"pg"|"mysql2"' package.json 2>/dev/null |
| 61 | |
| 62 | # Detect AI libraries |
| 63 | grep -E '"openai"|"@anthropic-ai"|"langchain"|"@langchain"|"@google/generative-ai"|"ai"' package.json 2>/dev/null |
| 64 | |
| 65 | # Check for companion frontend |
| 66 | ls -d ../frontend ../web ../client ../ui 2>/dev/null |
| 67 | ``` |
| 68 | |
| 69 | **What to note:** |
| 70 | |
| 71 | - Is `@sentry/nestjs` already installed? If yes, check if `instrument.ts` exists and `Sentry.init()` is called — may just need feature config. |
| 72 | - **Sentry DI wrapper detected?** → The project wraps Sentry behind a DI token (e.g. `SENTRY_PROXY_TOKEN`) for testability. Use the injected proxy for all runtime Sentry calls (`startSpan`, `captureException`, `withIsolationScope`) instead of importing `@sentry/nestjs` directly in controllers, services, and processors. Only `instrument.ts` should import `@sentry/nestjs` directly. |
| 73 | - **Config class detected?** → The project uses a typed config class for `Sentry.init()` options (e.g. loaded from YAML or `@nestjs/config`). Any new SDK options must be added to the config type — do not hardcode values that should be configurable per environment. |
| 74 | - **`SentryModule.forRoot()` already registered?** → If it's in a shared module (e.g. a Sentry proxy module), do not add it again in `AppModule` — this causes duplicate interceptor registration. |
| 75 | - Express (default) or Fastify adapter? Express is fully supported; Fastify works but has known edge cases. |
| 76 | - GraphQL detected? → `SentryGlobalFilter` handles it natively. |
| 77 | - Microservices detected? → Recommend RPC exception filter. |
| 78 | - Task queues / `@nestjs/schedule`? → Recommend crons. |
| 79 | - AI libraries? → Auto-instrumented, zero config. |
| 80 | - Prisma? → Requires manual `prismaIntegration()`. |
| 81 | - Companion frontend? → Triggers Phase 4 cross-link. |
| 82 | |
| 83 | --- |
| 84 | |
| 85 | ## Phase 2: Recommend |
| 86 | |
| 87 | Based on what you found, present a concrete proposal. Don't ask open-ended questions — lead with a recommendation: |
| 88 | |
| 89 | **Always recommended (core coverage):** |
| 90 | |
| 91 | - ✅ **Error Monitoring** — captures unhandled exceptions across HTTP, GraphQL, RPC, and WebSocket contexts |
| 92 | - ✅ **Tracing** — auto-instruments middleware, guards, pipes, interceptors, filters, and route handlers |
| 93 | |
| 94 | **Recommend when detected:** |
| 95 | |
| 96 | - ✅ **Profiling** — production apps where CPU performance matters (`@sentry/profiling-node`) |
| 97 | - ✅ ** |