현재 진행하고 있는 동아리 홈페이지 제작 중에 Sentry를 미리 도입해서 바로 에러를 추적할 수 있게끔 하기 위해서 Sentry를 도입했습니다.
애플리케이션에서 오류가 발생하면 알려주는 강력한 에러 트래킹 서비스입니다.
npm install @sentry/nextjs --save
npx @sentry/wizard@latest -i nextjs
(wizard는 설정할 사항을 y/n로 선택해서 설정할 수 있게 해줍니다.)
wizard 설치 시 아래처럼 나오게 됩니다. 각자 상황에 맞추어 선택하면 됩니다!



NEXT_PUBLIC_SENTRY_DNS를 .env.local에 저장해둡니다. (배포 시에는 DNS와 SENTRY_AUTH_TOKEN도 환경변수로 추가해야 합니다.)
아래처럼 나오는 것을 확인할 수 있습니다!

sentry.client.config 파일과 동일 (Next.js 13+ App Router 환경에서 클라이언트 초기화 로직을 이 파일로 통일함)공식문서 예시)
Sentry.logger.trace("Starting database connection", { database: "users" });
Sentry.logger.debug("Cache miss for user", { userId: 123 });
Sentry.logger.info("Updated profile", { profileId: 345 });
Sentry.logger.warn("Rate limit reached for endpoint", {
endpoint: "/api/results/",
isEnterprise: false,
});
Sentry.logger.error("Failed to process payment", {
orderId: "order_123",
amount: 99.99,
});
Sentry.logger.fatal("Database connection pool exhausted", {
database: "users",
activeConnections: 100,
});
실사용 예시) API 작업 시
onClick={async () => {
await Sentry.startSpan(
{
name: "Example Frontend/Backend Span",
op: "test",
},
async () => {
const res = await fetch("/api/sentry-example-api");
if (!res.ok) {
setHasSentError(true);
// API 실패를 로그로 기록
Sentry.logger.fatal("API call failed from frontend", {
status: res.status,
});
}
}
);
const error = new SentryExampleFrontendError(
"This error is raised on the frontend of the example page."
);
// error 수준 로그
Sentry.logger.error("Frontend error occurred", { error });
throw error; // 해당 코드는 런타임시 잡아서 자동으로 Sentry에 전송
}}
➡️ 즉, logger는 관찰/분류용, captureException은 꼭 전송하고 싶은 에러 보고용입니다.
디스코드나 slack으로 연동도 가능하다고 해서 추후엔 연동해보면 좋을 것 같네용