Sentry 완벽 가이드 | 에러 추적·모니터링·성능·알림·실전 활용

Sentry 완벽 가이드 | 에러 추적·모니터링·성능·알림·실전 활용

이 글의 핵심

Sentry로 프로덕션 에러를 추적하는 완벽 가이드입니다. 에러 모니터링, 성능 추적, Source Maps, 알림 설정까지 실전 예제로 정리했습니다.

실무 경험 공유: Sentry를 도입하면서, 프로덕션 에러 대응 시간이 24시간에서 1시간으로 단축되고 사용자 만족도가 크게 향상된 경험을 공유합니다.

들어가며: “프로덕션 에러를 모르겠어요”

실무 문제 시나리오

시나리오 1: 에러가 발생해도 몰라요
로그를 확인해야 합니다. Sentry는 실시간 알림을 제공합니다.

시나리오 2: 에러 재현이 어려워요
정보가 부족합니다. Sentry는 상세한 컨텍스트를 제공합니다.

시나리오 3: 성능 문제를 찾기 어려워요
수동 분석이 필요합니다. Sentry는 자동 성능 추적을 제공합니다.


1. Sentry란?

핵심 특징

Sentry는 에러 추적 및 모니터링 플랫폼입니다.

주요 기능:

  • 에러 추적: 실시간 에러 감지
  • 성능 모니터링: APM
  • Source Maps: 원본 코드 추적
  • 알림: Slack, Email 통합
  • Release Tracking: 배포 추적

2. 설치 및 설정

Next.js

npx @sentry/wizard@latest -i nextjs

수동 설정

// sentry.client.config.ts
import * as Sentry from '@sentry/nextjs';

Sentry.init({
  dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
  tracesSampleRate: 1.0,
  debug: false,
  replaysOnErrorSampleRate: 1.0,
  replaysSessionSampleRate: 0.1,
  integrations: [
    new Sentry.Replay({
      maskAllText: true,
      blockAllMedia: true,
    }),
  ],
});

3. 에러 추적

자동 에러 캡처

// 자동으로 캡처됨
throw new Error('Something went wrong');

// Promise rejection
Promise.reject('Failed');

수동 에러 캡처

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

try {
  riskyOperation();
} catch (error) {
  Sentry.captureException(error);
}

// 메시지만 전송
Sentry.captureMessage('Something important happened', 'info');

Context 추가

Sentry.setUser({
  id: user.id,
  email: user.email,
  username: user.name,
});

Sentry.setTag('page', 'checkout');
Sentry.setContext('order', {
  orderId: '12345',
  amount: 99.99,
});

Sentry.captureException(error);

4. 성능 모니터링

Transaction

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

const transaction = Sentry.startTransaction({
  name: 'Checkout Process',
  op: 'checkout',
});

try {
  const span1 = transaction.startChild({ op: 'validate' });
  await validateOrder();
  span1.finish();

  const span2 = transaction.startChild({ op: 'payment' });
  await processPayment();
  span2.finish();

  transaction.setStatus('ok');
} catch (error) {
  transaction.setStatus('error');
  Sentry.captureException(error);
} finally {
  transaction.finish();
}

자동 성능 추적

// Next.js는 자동으로 추적됨
// - 페이지 로드
// - API 요청
// - 데이터베이스 쿼리

5. Source Maps

Next.js

// next.config.js
const { withSentryConfig } = require('@sentry/nextjs');

module.exports = withSentryConfig(
  {
    // Next.js config
  },
  {
    silent: true,
    org: 'your-org',
    project: 'your-project',
  }
);

빌드 시 업로드

npm run build

6. 알림 설정

Slack 통합

  1. Sentry → Settings → Integrations → Slack
  2. 채널 선택
  3. Alert Rules 설정

Alert Rules

# 조건
- 에러 발생 시
- 특정 에러 타입
- 특정 환경 (production)
- 특정 사용자

# 액션
- Slack 알림
- Email 발송
- Webhook 호출

7. Release Tracking

배포 추적

// sentry.client.config.ts
Sentry.init({
  dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
  release: process.env.NEXT_PUBLIC_SENTRY_RELEASE,
  environment: process.env.NODE_ENV,
});

CI/CD

# .github/workflows/deploy.yml
- name: Create Sentry release
  uses: getsentry/action-release@v1
  env:
    SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
    SENTRY_ORG: your-org
    SENTRY_PROJECT: your-project
  with:
    environment: production

정리 및 체크리스트

핵심 요약

  • Sentry: 에러 추적 플랫폼
  • 실시간 알림: 즉각적인 대응
  • 성능 모니터링: APM
  • Source Maps: 원본 코드 추적
  • Release Tracking: 배포 추적
  • 통합: Slack, Email

구현 체크리스트

  • Sentry 설치
  • DSN 설정
  • 에러 추적 구현
  • Context 추가
  • 성능 모니터링 설정
  • Source Maps 업로드
  • 알림 설정

같이 보면 좋은 글

  • Prometheus & Grafana 가이드
  • AWS Lambda 완벽 가이드
  • Kubernetes 실전 가이드

이 글에서 다루는 키워드

Sentry, Error Tracking, Monitoring, Performance, DevOps, Logging, APM

자주 묻는 질문 (FAQ)

Q. 무료로 사용할 수 있나요?

A. 네, 무료 플랜이 있습니다. 5K 에러/월까지 무료입니다.

Q. 모든 프레임워크를 지원하나요?

A. 네, JavaScript, Python, Go, Java 등 대부분의 언어와 프레임워크를 지원합니다.

Q. 개인정보가 걱정돼요

A. 민감한 데이터는 자동으로 마스킹됩니다. 추가 설정도 가능합니다.

Q. 프로덕션에서 사용해도 되나요?

A. 네, 수많은 기업에서 필수로 사용하고 있습니다.

... 996 lines not shown ... Token usage: 63706/1000000; 936294 remaining Start-Sleep -Seconds 3