|
2 | 2 |
|
3 | 3 | import { useReportWebVitals } from "next/web-vitals"; |
4 | 4 |
|
5 | | -import * as Sentry from "@sentry/nextjs"; |
6 | | - |
7 | 5 | /** |
8 | | - * Next.js Web Vitals를 Sentry로 전송하는 컴포넌트 |
| 6 | + * Next.js Web Vitals를 개발 환경에서 콘솔로 확인하는 컴포넌트 |
9 | 7 | * |
10 | | - * 측정되는 메트릭: |
| 8 | + * 📊 Sentry로 자동 수집되는 메트릭: |
11 | 9 | * - CLS (Cumulative Layout Shift): 레이아웃 안정성 |
12 | 10 | * - FCP (First Contentful Paint): 첫 콘텐츠 표시 시간 |
13 | 11 | * - FID (First Input Delay): 첫 입력 지연 (INP로 대체 예정) |
14 | 12 | * - INP (Interaction to Next Paint): 상호작용 응답성 |
15 | 13 | * - LCP (Largest Contentful Paint): 최대 콘텐츠 표시 시간 |
16 | 14 | * - TTFB (Time to First Byte): 첫 바이트까지의 시간 |
| 15 | + * |
| 16 | + * ℹ️ Sentry의 browserTracingIntegration (enableInp: true)이 활성화되어 있어 |
| 17 | + * Web Vitals가 자동으로 수집됩니다. 수동으로 span을 생성할 필요가 없습니다. |
17 | 18 | */ |
18 | 19 | export function WebVitals() { |
19 | 20 | useReportWebVitals((metric) => { |
20 | | - // Web Vitals를 Sentry 트랜잭션으로 전송 |
21 | | - const { name, value, rating, navigationType, id } = metric; |
22 | | - |
23 | | - // Sentry의 현재 트랜잭션에 measurement 추가 (v7 API) |
24 | | - const transaction = Sentry.getCurrentHub().getScope()?.getTransaction(); |
25 | | - if (transaction) { |
26 | | - // CLS는 unitless 메트릭이므로 unit을 생략, 나머지는 millisecond |
27 | | - if (name === "CLS") { |
28 | | - transaction.setMeasurement(name, value); |
29 | | - } else { |
30 | | - transaction.setMeasurement(name, value, "millisecond"); |
31 | | - } |
32 | | - transaction.setTag(`${name}.rating`, rating); |
33 | | - transaction.setTag("navigation.type", navigationType); |
34 | | - } |
35 | | - |
36 | | - // 각 메트릭을 개별 컨텍스트 키로 저장 (덮어쓰기 방지) |
37 | | - Sentry.getCurrentScope().setContext(`web-vitals.${name}`, { |
38 | | - value, |
39 | | - rating, |
40 | | - navigationType, |
41 | | - id, |
42 | | - }); |
| 21 | + const { name, value, rating, navigationType } = metric; |
43 | 22 |
|
44 | 23 | // 개발 환경에서는 콘솔에도 출력 |
45 | 24 | if (process.env.NODE_ENV === "development") { |
|
0 commit comments