getsentry/sentry-nextjs-sdk

Configuration complète du SDK Sentry pour Next.js. À utiliser lorsqu'on demande « ajouter Sentry à Next.js », « installer @sentry/nextjs », ou configurer la surveillance des erreurs, le tracing, la relecture de session, la journalisation, le profilage, la surveillance IA ou les crons pour les applications Next.js. Prend en charge Next.js 13+ avec App Router et Pages Router.

Qu'est-ce que sentry-nextjs-sdk ?

Cette compétence automatise la configuration complète de Sentry pour les applications Next.js, en prenant en charge à la fois l'App Router et le Pages Router pour Next.js 13 et versions ultérieures. Elle est idéale lorsqu'un développeur demande d'ajouter Sentry, d'installer @sentry/nextjs, ou de configurer des fonctionnalités avancées comme la surveillance des erreurs, le tracing distribué, la relecture de session, la journalisation, le profilage, la surveillance IA ou les tâches cron. L'outil installe et configure le SDK Sentry de manière appropriée, génère les fichiers de configuration nécessaires (comme sentry.client.config.ts et sentry.server.config.ts), et adapte les options en fonction du routeur utilisé. Il garantit une intégration fluide et cohérente avec les meilleures pratiques de Sentry, permettant aux développeurs de gagner du temps et d'éviter les erreurs de configuration manuelle. La compétence est conçue pour être utilisée dans des environnements de développement Next.js, que ce soit via un agent IA comme Claude Code ou Cursor, ou en ligne de commande.

Compatible avec~Claude Code~Codex CLI~Cursor
Part ofNext.js
npx skills add https://github.com/getsentry/sentry-for-ai/tree/main/skills/sentry-nextjs-sdk

Installed? Explore more Développement et programmation skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

Demander à votre IA préférée

Ouvre une nouvelle conversation avec cette compétence d'agent déjà préchargée.

Documentation

Que fait sentry-nextjs-sdk ?

Configuration complète du SDK Sentry pour Next.js. À utiliser lorsqu'on demande « ajouter Sentry à Next.js », « installer @sentry/nextjs », ou configurer la surveillance des erreurs, le tracing, la relecture de session, la journalisation, le profilage, la surveillance IA ou les crons pour les applications Next.js. Prend en charge Next.js 13+ avec App Router et Pages Router.

Installation

npm install @sentry/nextjs
# ou
pnpm add @sentry/nextjs
# ou
yarn add @sentry/nextjs

Configuration

Créez les fichiers de configuration suivants à la racine de votre projet Next.js :

sentry.client.config.ts ou sentry.client.config.js

import * as Sentry from "@sentry/nextjs";

Sentry.init({
  dsn: "VOTRE_DSN_SENTRY",
  tracesSampleRate: 1.0,
  replaysSessionSampleRate: 0.1,
  replaysOnErrorSampleRate: 1.0,
  integrations: [
    new Sentry.Replay(),
  ],
});

sentry.server.config.ts ou sentry.server.config.js

import * as Sentry from "@sentry/nextjs";

Sentry.init({
  dsn: "VOTRE_DSN_SENTRY",
  tracesSampleRate: 1.0,
});

sentry.edge.config.ts ou sentry.edge.config.js

import * as Sentry from "@sentry/nextjs";

Sentry.init({
  dsn: "VOTRE_DSN_SENTRY",
  tracesSampleRate: 1.0,
});

Pour l'App Router

Ajoutez le fournisseur Sentry dans votre app/layout.tsx :

import { Sentry } from "@sentry/nextjs";

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="fr">
      <body>
        <Sentry.ErrorBoundary fallback={<p>Une erreur est survenue</p>}>
          {children}
        </Sentry.ErrorBoundary>
      </body>
    </html>
  );
}

Pour le Pages Router

// pages/_app.tsx
import { useEffect } from "react";
import type { AppProps } from "next/app";

function MyApp({ Component, pageProps }: AppProps) {
  useEffect(() => {
    // Initialisation côté client
    import("@sentry/nextjs").then((Sentry) => {
      Sentry.init({
        dsn: "VOTRE_DSN_SENTRY",
        tracesSampleRate: 1.0,
      });
    });
  }, []);

  return <Component {...pageProps} />;
}

export default MyApp;

next.config.js

const { withSentryConfig } = require("@sentry/nextjs");

const nextConfig = {
  // Votre configuration Next.js existante
};

module.exports = withSentryConfig(nextConfig, {
  silent: false,
  hideSourceMaps: true,
  widenClientFileUpload: true,
  transpileClientSDK: true,
  tunnelRoute: "/monitoring",
});

Variables d'environnement

Assurez-vous de définir les variables d'environnement suivantes :

SENTRY_DSN=votre_dsn
SENTRY_AUTH_TOKEN=votre_token_auth
SENTRY_ORG=votre_organisation
SENTRY_PROJECT=votre_projet

Utilisation

Surveillance des erreurs

// Dans un composant ou une API route
import * as Sentry from "@sentry/nextjs";

try {
  // Opération risquée
} catch (error) {
  Sentry.captureException(error);
}

Tracing distribué

// Dans une fonction API
import * as Sentry from "@sentry/nextjs";

export default async function handler(req, res) {
  const transaction = Sentry.startTransaction({
    op: "api.handler",
    name: "Mon handler API",
  });

  try {
    // Logique métier
  } finally {
    transaction.finish();
  }
}

Relecture de session

// La relecture de session est configurée dans sentry.client.config.ts
// via l'intégration Sentry.Replay()

Journalisation

import * as Sentry from "@sentry/nextjs";

Sentry.captureMessage("Un événement personnalisé", {
  level: "info",
  extra: {
    cle1: "valeur1",
    cle2: "valeur2",
  },
});

Profilage

// Ajoutez l'option tracesSampleRate dans la configuration
// et utilisez le profilage avec ProfilingIntegration
import { ProfilingIntegration } from "@sentry/profiling-node";

Sentry.init({
  dsn: "VOTRE_DSN_SENTRY",
  integrations: [
    new ProfilingIntegration(),
  ],
  profilesSampleRate: 1.0,
});

Surveillance IA

// Utilisez Sentry pour surveiller les appels à l'IA
// À configurer selon le fournisseur d'IA spécifique

Crons (Tâches planifiées)

import { SentryCron } from "@sentry/nextjs/crons";

// Nouveau cron
const cron = new SentryCron({
  name: "Mon Cron",
  schedule: "0 * * * *",
  timeZone: "Europe/Paris",
});

cron.start();

Dépannage

Erreurs courantes

  • SENTRY_DSN manquant : Assurez-vous que la variable d'environnement SENTRY_DSN est définie.
  • Problèmes de source maps : Vérifiez la configuration de withSentryConfig dans next.config.js.
  • Rendu côté client vs serveur : Assurez-vous de configurer séparément les configurations serveur et client.

Ressources

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

getsentry/sentry-android-sdk

Full Sentry SDK setup for Android. Use when asked to "add Sentry to Android", "install sentry-android", "setup Sentry in Android", or configure error monitoring, tracing, profiling, session replay, or logging for Android applications. Supports Kotlin and Java codebases.

getsentry/sentry-browser-sdk

Full Sentry SDK setup for browser JavaScript. Use when asked to "add Sentry to a website", "install @sentry/browser", or configure error monitoring, tracing, session replay, or logging for vanilla JavaScript, jQuery, static sites, or WordPress.

getsentry/sentry-cloudflare-sdk

Full Sentry SDK setup for Cloudflare Workers and Pages. Use when asked to "add Sentry to Cloudflare Workers", "install @sentry/cloudflare", or configure error monitoring, tracing, logging, crons, or AI monitoring for Cloudflare Workers, Pages, Durable Objects, Queues, Workflows, or Hono on Cloudflare.

getsentry/sentry-cocoa-sdk

Full Sentry SDK setup for Apple platforms (iOS, macOS, tvOS, watchOS, visionOS). Use when asked to "add Sentry to iOS", "add Sentry to Swift", "install sentry-cocoa", or configure error monitoring, tracing, profiling, session replay, logging, or metrics for Apple applications. Supports SwiftUI and UIKit.

getsentry/sentry-code-review

Analyze and resolve Sentry comments on GitHub Pull Requests. Use this when asked to review or fix issues identified by Sentry in PR comments. Can review specific PRs by number or automatically find recent PRs with Sentry feedback.

getsentry/sentry-create-alert

Create Sentry alerts using the workflow engine API. Use when asked to create alerts, set up notifications, configure issue priority alerts, or build workflow automations. Supports email, Slack, PagerDuty, Discord, and other notification actions.

getsentry/sentry-dotnet-sdk

Full Sentry SDK setup for .NET. Use when asked to "add Sentry to .NET", "install Sentry for C#", or configure error monitoring, tracing, profiling, logging, or crons for ASP.NET Core, MAUI, WPF, WinForms, Blazor, Azure Functions, or any other .NET application.

getsentry/sentry-elixir-sdk

Full Sentry SDK setup for Elixir. Use when asked to "add Sentry to Elixir", "install sentry for Elixir", or configure error monitoring, tracing, logging, or crons for Elixir, Phoenix, or Plug applications. Supports Phoenix, Plug, LiveView, Oban, and Quantum.

getsentry/sentry-feature-setup

Configure specific Sentry features beyond basic SDK setup. Use when asked to monitor AI/LLM calls, set up OpenTelemetry pipelines, create alerts and notifications, or enable span streaming.

getsentry/sentry-fix-issues

Find and fix issues from Sentry using MCP. Use when asked to fix Sentry errors, debug production issues, investigate exceptions, or resolve bugs reported in Sentry. Methodically analyzes stack traces, breadcrumbs, traces, and context to identify root causes.

getsentry/sentry-flutter-sdk

Full Sentry SDK setup for Flutter and Dart. Use when asked to "add Sentry to Flutter", "install sentry_flutter", "setup Sentry in Dart", or configure error monitoring, tracing, profiling, session replay, or logging for Flutter applications. Supports Android, iOS, macOS, Linux, Windows, and Web.

getsentry/sentry-go-sdk

Full Sentry SDK setup for Go. Use when asked to "add Sentry to Go", "install sentry-go", "setup Sentry in Go", or configure error monitoring, tracing, logging, metrics, or crons for Go applications. Supports net/http, Gin, Echo, Fiber, FastHTTP, Iris, Negroni, and gRPC.

getsentry/sentry-nestjs-sdk

Full 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 adapters, GraphQL, microservices, WebSockets, and background jobs.

getsentry/sentry-node-sdk

Full Sentry SDK setup for Node.js, Bun, and Deno. Use when asked to "add Sentry to Node.js", "add Sentry to Bun", "add Sentry to Deno", "install @sentry/node", "@sentry/bun", or "@sentry/deno", or configure error monitoring, tracing, logging, profiling, metrics, crons, or AI monitoring for server-side JavaScript/TypeScript runtimes.

getsentry/sentry-otel-exporter-setup

Configure the OpenTelemetry Collector with Sentry Exporter for multi-project routing and automatic project creation. Use when setting up OTel with Sentry, configuring collector pipelines for traces and logs, or routing telemetry from multiple services to Sentry projects.

getsentry/sentry-php-sdk

Full Sentry SDK setup for PHP. Use when asked to "add Sentry to PHP", "install sentry/sentry", "setup Sentry in PHP", or configure error monitoring, tracing, profiling, logging, metrics, or crons for PHP applications. Supports plain PHP, Laravel, and Symfony.

getsentry/sentry-pr-code-review

Review a project's PRs to check for issues detected in code review by Seer Bug Prediction. Use when asked to review or fix issues identified by Sentry in PR comments, or to find recent PRs with Sentry feedback.

getsentry/sentry-python-sdk

Full Sentry SDK setup for Python. Use when asked to "add Sentry to Python", "install sentry-sdk", "setup Sentry in Python", or configure error monitoring, tracing, profiling, logging, metrics, crons, or AI monitoring for Python applications. Supports Django, Flask, FastAPI, Celery, Starlette, AIOHTTP, Tornado, and more.

getsentry/sentry-react-native-sdk

Full Sentry SDK setup for React Native and Expo. Use when asked to "add Sentry to React Native", "install @sentry/react-native", "setup Sentry in Expo", or configure error monitoring, tracing, profiling, session replay, or logging for React Native applications. Supports Expo managed, Expo bare, and vanilla React Native.

getsentry/sentry-react-sdk

Full Sentry SDK setup for React. Use when asked to "add Sentry to React", "install @sentry/react", or configure error monitoring, tracing, session replay, profiling, or logging for React applications. Supports React 16+, React Router v5-v7 non-framework mode, TanStack Router, Redux, Vite, and webpack.

Skills associés