Token导航 LogoToken导航TokenDH.com
研究检索操作浏览器github未标认证来源可访问许可证需确认审计通过

sentry-nextjs-sdkSentry Next.js SDK 搜索

Agent Skill

用于辅助前端页面、组件、样式和交互逻辑的开发与维护。它适合让 Agent 生成或审查 React、Next.js、Vue、Tailwind、CSS 等相关代码,整理组件结构,或定位布局和性能问题。使用时需要结合项目现有设计系统、路由和构建方式,避免只生成孤立片段;涉及页面改动时,应配合本地预览和构建检查确认视觉效果。

总安装

25,872

周安装

1,144

GitHub Stars

156

下载量

9,064
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:sentry-nextjs-sdk(Sentry Next.js SDK 搜索)
来源仓库:https://github.com/getsentry/sentry-for-ai
仓库路径:skills/sentry-nextjs-sdk
安装命令:
npx skills add https://github.com/getsentry/sentry-for-ai --skill sentry-nextjs-sdk
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/getsentry/sentry-for-ai --skill sentry-nextjs-sdk

简介

用于辅助前端页面、组件和样式逻辑的开发与维护。

  • 适合生成或审查 Next.js、React、Tailwind CSS 相关代码。
  • 通过 GitHub 安装后,结合项目路由和构建方式使用。
  • 页面改动后应通过本地预览验证实际效果。
  • sentry-nextjs-sdk 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

All Skills > SDK Setup > Next.js SDK

Sentry Next.js SDK

Opinionated wizard that scans your Next.js project and guides you through complete Sentry setup across all three runtimes: browser, Node.js server, and Edge.

Invoke This Skill When

  • User asks to "add Sentry to Next.js" or "set up Sentry" in a Next.js app
  • User wants to install or configure @sentry/nextjs
  • User wants error monitoring, tracing, session replay, logging, or profiling for Next.js
  • User asks about instrumentation.ts, withSentryConfig(), or global-error.tsx
  • User wants to capture server actions, server component errors, or edge runtime errors
Note: SDK versions and APIs below reflect current Sentry docs at time of writing (@sentry/nextjs ≥8.28.0). Always verify against docs.sentry.io/platforms/javascript/guides/nextjs/ before implementing.

Phase 1: Detect

Run these commands to understand the project before making any recommendations:

# Detect Next.js version and existing Sentry
cat package.json | grep -E '"next"|"@sentry/'

# Detect router type (App Router vs Pages Router)
ls src/app app src/pages pages 2>/dev/null

# Check for existing Sentry config files
ls instrumentation.ts instrumentation-client.ts sentry.server.config.ts sentry.edge.config.ts 2>/dev/null
ls src/instrumentation.ts src/instrumentation-client.ts 2>/dev/null

# Check next.config
ls next.config.ts next.config.js next.config.mjs 2>/dev/null

# Check for existing error boundaries
find . -name "global-error.tsx" -o -name "_error.tsx" 2>/dev/null | grep -v node_modules

# Check build tool
cat package.json | grep -E '"turbopack"|"webpack"'

# Check for logging libraries
cat package.json | grep -E '"pino"|"winston"|"bunyan"'

# Check for companion backend
ls ../backend ../server ../api 2>/dev/null
cat ../go.mod ../requirements.txt ../Gemfile 2>/dev/null | head -3

What to determine:

QuestionImpact
Next.js version?13+ required; 15+ needed for Turbopack support
App Router or Pages Router?Determines error boundary files needed (global-error.tsx vs _error.tsx)
@sentry/nextjs already present?Skip install, go to feature config
Existing instrumentation.ts?Merge Sentry into it rather than replace
Turbopack in use?Tree-shaking in withSentryConfig is webpack-only
Logging library detected?Recommend Sentry Logs integration
Backend directory found?Trigger Phase 4 cross-link suggestion

Phase 2: Recommend

Present a concrete recommendation based on what you found. Don't ask open-ended questions — lead with a proposal:

Recommended (core coverage):

  • Error Monitoring — always; captures server errors, client errors, server actions, and unhandled promise rejections
  • Tracing — server-side request tracing + client-side navigation spans across all runtimes
  • Session Replay — recommended for user-facing apps; records sessions around errors

Optional (enhanced observability):

  • Logging — structured logs via Sentry.logger.*; recommend when pino/winston or log search is needed
  • Profiling — continuous profiling; requires Document-Policy: js-profiling header
  • AI Monitoring — OpenAI, Vercel AI SDK, Anthropic; recommend when AI/LLM calls detected
  • Crons — detect missed/failed scheduled jobs; recommend when cron patterns detected
  • Metrics — custom metrics via Sentry.metrics.*; recommend when custom KPIs or business metrics needed

Recommendation logic:

FeatureRecommend when...
Error MonitoringAlways — non-negotiable baseline
TracingAlways for Next.js — server route tracing + client navigation are high-value
Session ReplayUser-facing app, login flows, or checkout pages
LoggingApp uses structured logging or needs log-to-trace correlation
ProfilingPerformance-critical app; client sets Document-Policy: js-profiling
AI MonitoringApp makes OpenAI, Vercel AI SDK, or Anthropic calls
CronsApp has Vercel Cron jobs, scheduled API routes, or node-cron usage
MetricsApp needs custom counters, gauges, or histograms via Sentry.metrics.*

Propose: *"I recommend setting up Error Monitoring + Tracing + Session Replay. Want me to also add Logging or Profiling?"*


Phase 3: Guide

Option 1: Wizard (Recommended)

You need to run this yourself — the wizard opens a browser for login and requires interactive input that the agent can't handle. Copy-paste into your terminal: `` npx @sentry/wizard@latest -i nextjs ` It handles login, org/project selection, SDK installation, config files (instrumentation-client.ts, sentry.server.config.ts, sentry.edge.config.ts, instrumentation.ts), next.config.ts wrapping, source map upload, and adds a /sentry-example-page`. Once it finishes, come back and skip to Verification.

If the user skips the wizard, proceed with Option 2 (Manual Setup) below.


Option 2: Manual Setup

Install

npm install @sentry/nextjs --save

Create instrumentation-client.ts — Browser / Client Runtime

Older docs used sentry.client.config.ts — the current pattern is instrumentation-client.ts.
import * as Sentry from "@sentry/nextjs";

Sentry.init({
  dsn: process.env.NEXT_PUBLIC_SENTRY_DSN ?? "___PUBLIC_DSN___",

  sendDefaultPii: true,

  // 100% in dev, 10% in production
  tracesSampleRate: process.env.NODE_ENV === "development" ? 1.0 : 0.1,

  // Session Replay: 10% of all sessions, 100% of sessions with errors
  replaysSessionSampleRate: 0.1,
  replaysOnErrorSampleRate: 1.0,

  enableLogs: true,

  integrations: [
    Sentry.replayIntegration(),
    // Optional: user feedback widget
    // Sentry.feedbackIntegration({ colorScheme: "system" }),
  ],
});

// Hook into App Router navigation transitions (App Router only)
export const onRouterTransitionStart = Sentry.captureRouterTransitionStart;

Create sentry.server.config.ts — Node.js Server Runtime

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

Sentry.init({
  dsn: process.env.SENTRY_DSN ?? "___DSN___",

  sendDefaultPii: true,
  tracesSampleRate: process.env.NODE_ENV === "development" ? 1.0 : 0.1,

  // Attach local variable values to stack frames
  includeLocalVariables: true,

  enableLogs: true,
});

Create sentry.edge.config.ts — Edge Runtime

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

Sentry.init({
  dsn: process.env.SENTRY_DSN ?? "___DSN___",

  sendDefaultPii: true,
  tracesSampleRate: process.env.NODE_ENV === "development" ? 1.0 : 0.1,

  enableLogs: true,
});

Create instrumentation.ts — Server-Side Registration Hook

Requires experimental.instrumentationHook: true in next.config for Next.js < 14.0.4. It's stable in 14.0.4+.
import * as Sentry from "@sentry/nextjs";

export async function register() {
  if (process.env.NEXT_RUNTIME === "nodejs") {
    await import("./sentry.server.config");
  }

  if (process.env.NEXT_RUNTIME === "edge") {
    await import("./sentry.edge.config");
  }
}

// Automatically captures all unhandled server-side request errors
// Requires @sentry/nextjs >= 8.28.0
export const onRequestError = Sentry.captureRequestError;

Runtime dispatch:

NEXT_RUNTIMEConfig file loaded
"nodejs"sentry.server.config.ts
"edge"sentry.edge.config.ts
*(client bundle)*instrumentation-client.ts (Next.js handles this directly)

App Router: Create app/global-error.tsx

This catches errors in the root layout and React render errors:

"use client";

import * as Sentry from "@sentry/nextjs";
import NextError from "next/error";
import { useEffect } from "react";

export default function GlobalError({
  error,
}: {
  error: Error & { digest?: string };
}) {
  useEffect(() => {
    Sentry.captureException(error);
  }, [error]);

  return (
    <html>
      <body>
        <NextError statusCode={0} />
      </body>
    </html>
  );
}

Pages Router: Update pages/_error.tsx

import * as Sentry from "@sentry/nextjs";
import type { NextPageContext } from "next";
import NextErrorComponent from "next/error";

type ErrorProps = { statusCode: number };

export default function CustomError({ statusCode }: ErrorProps) {
  return <NextErrorComponent statusCode={statusCode} />;
}

CustomError.getInitialProps = async (ctx: NextPageContext) => {
  await Sentry.captureUnderscoreErrorException(ctx);
  return NextErrorComponent.getInitialProps(ctx);
};

Wrap next.config.ts with withSentryConfig()

import type { NextConfig } from "next";
import { withSentryConfig } from "@sentry/nextjs";

const nextConfig: NextConfig = {
  // your existing Next.js config
};

export default withSentryConfig(nextConfig, {
  org: "___ORG_SLUG___",
  project: "___PROJECT_SLUG___",

  // Source map upload auth token (see Source Maps section below)
  authToken: process.env.SENTRY_AUTH_TOKEN,

  // Upload wider set of client source files for better stack trace resolution
  widenClientFileUpload: true,

  // Create a proxy API route to bypass ad-blockers
  tunnelRoute: "/monitoring",

  // Suppress non-CI output
  silent: !process.env.CI,
});

Exclude Tunnel Route from Middleware

If you have middleware.ts, exclude the tunnel path from auth or redirect logic:

// middleware.ts
export const config = {
  matcher: [
    // Exclude monitoring route, Next.js internals, and static files
    "/((?!monitoring|_next/static|_next/image|favicon.ico).*)",
  ],
};

Source Maps Setup

Source maps make production stack traces readable — without them, you see minified code. This is non-negotiable for production apps.

Step 1: Generate a Sentry auth token

Go to sentry.io/settings/auth-tokens/ and create a token with project:releases and org:read scopes.

Step 2: Set environment variables

# .env.sentry-build-plugin  (gitignore this file)
SENTRY_AUTH_TOKEN=sntrys_eyJ...

Or set in CI secrets:

SENTRY_AUTH_TOKEN=sntrys_eyJ...
SENTRY_ORG=my-org        # optional if set in next.config
SENTRY_PROJECT=my-project # optional if set in next.config

Step 3: Add to .gitignore

.env.sentry-build-plugin

Step 4: Verify authToken is wired in next.config.ts

withSentryConfig(nextConfig, {
  org: "my-org",
  project: "my-project",
  authToken: process.env.SENTRY_AUTH_TOKEN, // reads from .env.sentry-build-plugin or CI env
  widenClientFileUpload: true,
});

Source maps are uploaded automatically on every next build.


For Each Agreed Feature

Load the corresponding reference file and follow its steps:

FeatureReference fileLoad when...
Error Monitoringreferences/error-monitoring.mdAlways (baseline) — App Router error boundaries, Pages Router _error.tsx, server action wrapping
Tracingreferences/tracing.mdServer-side request tracing, client navigation, distributed tracing, tracePropagationTargets
Session Replayreferences/session-replay.mdUser-facing app; privacy masking, canvas recording, network capture
Loggingreferences/logging.mdStructured logs, Sentry.logger.*, log-to-trace correlation
Profilingreferences/profiling.mdContinuous profiling, Document-Policy header, nodeProfilingIntegration
AI Monitoringreferences/ai-monitoring.mdApp uses OpenAI, Vercel AI SDK, or Anthropic
Cronsreferences/crons.mdVercel Cron, scheduled API routes, node-cron
Metricsreferences/metrics.mdCustom counters, gauges, distributions via Sentry.metrics.*

For each feature: read the reference file, follow its steps exactly, and verify before moving on.


Verification

After wizard or manual setup, verify Sentry is working:

// Add temporarily to a server action or API route, then remove
import * as Sentry from "@sentry/nextjs";

throw new Error("Sentry test error — delete me");
// or
Sentry.captureException(new Error("Sentry test error — delete me"));

Then check your Sentry Issues dashboard — the error should appear within ~30 seconds.

Verification checklist:

CheckHow
Client errors capturedThrow in a client component, verify in Sentry
Server errors capturedThrow in a server action or API route
Edge errors capturedThrow in middleware or edge route handler
Source maps workingCheck stack trace shows readable file names
Session Replay workingCheck Replays tab in Sentry dashboard

Config Reference

Sentry.init() Options

OptionTypeDefaultNotes
dsnstringRequired. Use NEXT_PUBLIC_SENTRY_DSN for client, SENTRY_DSN for server
tracesSampleRatenumber0–1; 1.0 in dev, 0.1 in prod recommended
replaysSessionSampleRatenumber0.1Fraction of all sessions recorded
replaysOnErrorSampleRatenumber1.0Fraction of error sessions recorded
sendDefaultPiibooleanfalseInclude IP, request headers in events
includeLocalVariablesbooleanfalseAttach local variable values to stack frames (server only)
enableLogsbooleanfalseEnable Sentry Logs product
environmentstringauto"production", "staging", etc.
releasestringautoSet to commit SHA or version tag
debugbooleanfalseLog SDK activity to console

withSentryConfig() Options

OptionTypeNotes
orgstringSentry organization slug
projectstringSentry project slug
authTokenstringSource map upload token (SENTRY_AUTH_TOKEN)
widenClientFileUploadbooleanUpload more client files for better stack traces
tunnelRoutestringAPI route path for ad-blocker bypass (e.g. "/monitoring")
silentbooleanSuppress build output (!process.env.CI recommended)
webpack.treeshake.*objectTree-shake SDK features (webpack only, not Turbopack)

Environment Variables

VariableRuntimePurpose
NEXT_PUBLIC_SENTRY_DSNClientDSN for browser Sentry init (public)
SENTRY_DSNServer / EdgeDSN for server/edge Sentry init
SENTRY_AUTH_TOKENBuildSource map upload auth token (secret)
SENTRY_ORGBuildOrg slug (alternative to org in config)
SENTRY_PROJECTBuildProject slug (alternative to project in config)
SENTRY_RELEASEServerRelease version string (auto-detected from git)
NEXT_RUNTIMEServer / Edge"nodejs" or "edge" (set by Next.js internally)

Phase 4: Cross-Link

After completing Next.js setup, check for companion services:

# Check for backend services in adjacent directories
ls ../backend ../server ../api ../services 2>/dev/null

# Check for backend language indicators
cat ../go.mod 2>/dev/null | head -3
cat ../requirements.txt ../pyproject.toml 2>/dev/null | head -3
cat ../Gemfile 2>/dev/null | head -3
cat ../pom.xml ../build.gradle 2>/dev/null | head -3

If a backend is found, suggest the matching SDK skill:

Backend detectedSuggest skill
Go (go.mod)sentry-go-sdk
Python (requirements.txt, pyproject.toml)sentry-python-sdk
Ruby (Gemfile)sentry-ruby-sdk
Java/Kotlin (pom.xml, build.gradle)See docs.sentry.io/platforms/java/
Node.js (Express, Fastify, Hapi)@sentry/node — see docs.sentry.io/platforms/javascript/guides/express/

Connecting frontend and backend with the same DSN or linked projects enables distributed tracing — stack traces that span your browser, Next.js server, and backend API in a single trace view.


Troubleshooting

IssueCauseSolution
Events not appearingDSN misconfigured or debug: false hiding errorsSet debug: true temporarily; check browser network tab for requests to sentry.io
Stack traces show minified codeSource maps not uploadingCheck SENTRY_AUTH_TOKEN is set; run next build and look for "Source Maps" in build output
onRequestError not firingSDK version < 8.28.0Upgrade: npm install @sentry/nextjs@latest
Edge runtime errors missingsentry.edge.config.ts not loadedVerify instrumentation.ts imports it when NEXT_RUNTIME === "edge"
Tunnel route returns 404tunnelRoute set but Next.js route missingThe plugin creates it automatically; check you ran next build after adding tunnelRoute
withSentryConfig tree-shaking breaks buildTurbopack in useTree-shaking options only work with webpack; remove webpack.treeshake options when using Turbopack
global-error.tsx not catching errorsMissing "use client" directiveAdd "use client" as the very first line of global-error.tsx
Session Replay not recordingreplayIntegration() missing from client initAdd Sentry.replayIntegration() to integrations in instrumentation-client.ts

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

34.63%
按下载量换算3,139

Claude

30.21%
按下载量换算2,738

Cursor

20.31%
按下载量换算1,841

Gemini CLI

10.41%
按下载量换算944

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

操作浏览器

该 Skill 可能涉及浏览器控制能力,使用时可能读取或操作网页内容,需要在受控环境中确认权限边界。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills