Sentry 통합은(는) 무엇을 하나요?
오류 모니터링 및 성능 추적을 위해 Sentry를 사용하는 방법에 대한 지침입니다.
예외 캐치
try/catch 블록에서 Sentry.captureException(error)을 사용하세요:
try {
await riskyOperation();
} catch (error) {
Sentry.captureException(error);
throw error;
}
성능 추적
버튼 클릭, API 호출, 함수 호출과 같은 의미 있는 작업에 대해 스팬(span)을 생성하세요.
UI 액션
function handleClick() {
Sentry.startSpan(
{ op: "ui.click", name: "Submit Form" },
(span) => {
span.setAttribute("formId", formId);
submitForm();
}
);
}
API 호출
async function fetchData(id) {
return Sentry.startSpan(
{ op: "http.client", name: `GET /api/items/${id}` },
async () => {
const response = await fetch(`/api/items/${id}`);
return response.json();
}
);
}
설정 (Next.js)
Sentry 초기화 파일:
sentry.client.config.ts- 클라이언트 측sentry.server.config.ts- 서버 측sentry.edge.config.ts- 엣지 런타임
import * as Sentry from "@sentry/nextjs"로 임포트하며, 다른 파일에서 초기화할 필요는 없습니다.
기본 설정
import * as Sentry from "@sentry/nextjs";
Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
enableLogs: true,
});
콘솔 로깅 사용
Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
integrations: [
Sentry.consoleLoggingIntegration({ levels: ["log", "warn", "error"] }),
],
});
구조화된 로깅
변수와 함께 템플릿 리터럴을 사용하려면 logger.fmt을 활용하세요:
const { logger } = Sentry;
logger.trace("Connecting", { database: "users" });
logger.debug(logger.fmt`Cache miss for: ${userId}`);
logger.info("Updated profile", { profileId: 345 });
logger.warn("Rate limit reached", { endpoint: "/api/data" });
logger.error("Payment failed", { orderId: "order_123" });
logger.fatal("Connection pool exhausted", { activeConnections: 100 });