Front-End/Next.js

[Next.js] Sentry ๋„์ž…ํ•˜๊ธฐ

Bigone17 2023. 10. 8. 22:26

๐ŸŸก 1. Sentry์ด๋ž€?

 Sentry๋Š” ์†Œํ”„ํŠธ์›จ์–ด ๋ฒ„๊ทธ ๋ฐ ์—๋Ÿฌ ์ถ”์ ์„ ์œ„ํ•œ ์˜คํ”ˆ ์†Œ์Šค ์˜ค๋ฅ˜ ๋ชจ๋‹ˆํ„ฐ๋ง ๋„๊ตฌ์ž…๋‹ˆ๋‹ค. ๊ฐœ๋ฐœ์ž๋“ค์ด ์‹ค์‹œ๊ฐ„์œผ๋กœ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ๋ฐœ์ƒํ•œ ๋ฒ„๊ทธ, ์˜ˆ์™ธ, ํฌ๋ž˜์‹œ ๋“ฑ์„ ๋ชจ๋‹ˆํ„ฐ๋งํ•˜๊ณ  ์ด๋ฅผ ์ถ”์ ํ•˜์—ฌ ๋””๋ฒ„๊น…ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค๋‹ˆ๋‹ค. Sentry๋Š” ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜, ๋ชจ๋ฐ”์ผ ์•ฑ ๋ฐ ๋‹ค์–‘ํ•œ ํ”Œ๋žซํผ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

๐ŸŸก 2. Next.js ํ”„๋กœ์ ํŠธ์— Sentry ๋„์ž…ํ•˜๊ธฐ.

  ๐ŸŸฃ 2.1 Senty ์›น์‚ฌ์ดํŠธ์—์„œ ํ”„๋กœ์ ํŠธ ๋งŒ๋“ค๊ธฐ.

      ํšŒ์›๊ฐ€์ž… ๋ฐ ๋กœ๊ทธ์ธ -> Projectํƒญ -> ์šฐ์ธก ์ƒ๋‹จ์— Create Project ๋ฒ„ํŠผ

Next.js ํด๋ฆญ -> Project name์€ ์ž์‹ ์˜ next.js ํ”„๋กœ์ ํŠธ ์ด๋ฆ„ ์ž…๋ ฅ(๊ฐ™์ง€ ์•Š์•„๋„ ๋จ) -> ํ™œ์„ฑํ™”๋œ Create Project ํด๋ฆญ

  ๐ŸŸฃ 2.2 Next.js ํ”„๋กœ์ ํŠธ์— Sentry module ์„ค์น˜

  next.js ํ”„๋กœ์ ํŠธ ํ„ฐ๋ฏธ๋„๋กœ ๊ฐ€์„œ, ์œ„ npx @sentry/wizard@latest -i nextjs ์ž…๋ ฅ.

  Ok to preceed?(y) => y ์ž…๋ ฅ

  - ์œ„ ์งˆ๋ฌธ๋“ค์— ๋ชจ๋‘ yes

  - Select your Sentry project๋Š” sentry์— ๋งŒ๋“ค์–ด์ง„ project๊ฐ€ ์—ฌ๋Ÿฌ๊ฐœ ์žˆ์œผ๋ฉด ๋ฆฌ์ŠคํŠธ๊ฐ€ ๋‚˜์˜ด. ๊ทธ์ค‘์— ๋„์ž…ํ•˜๊ณ ์ž ํ•˜๋Š” project๋ฅผ ๋ฐฉํ–ฅํ‚ค๋กœ ์„ ํƒ ํ›„ ์—”ํ„ฐ.

 ๐ŸŸฃ 2.3 Next.js ํ”„๋กœ์ ํŠธ์— Sentry ์ฝ”๋“œ ๋„์ž….

 

 

  ์œ„ ๊ณผ์ •์ด ๋๋‚˜๋ฉด ํ”„๋กœ์ ํŠธ ๋””๋ ‰ํ† ๋ฆฌ๊ฐ€ ์‚ฌ์ง„๊ณผ ๊ฐ™์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ด๋•Œ ์„ผํŠธ๋ฆฌ ํ…Œ์ŠคํŠธ๋ฅผ ํ•ด๋ณด๊ธฐ ์œ„ํ•ด์„œ src/app/sentry-example-page/page.jsx ํŒŒ์ผ ๋‚ด์šฉ์„ ๋ณต์‚ฌํ•ด์„œ src/app/page.tsx์— ๋ถ™์—ฌ ๋„ฃ์œผ๋ฉด ํ…Œ์ŠคํŠธ๊ฐ€ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. (๋นจ๊ฐ„์ƒ‰ -> ๋…ธ๋ž€์ƒ‰)

 

 

 

 

 

 

 

์ฝ”๋“œ๋ฅผ ์ ์šฉํ•˜๊ณ  ํ”„๋กœ์ ํŠธ๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ์œ„์™€ ๊ฐ™์ด ์‹คํ–‰์ด ๋œ๋‹ค.

sentry์— ์žกํžŒ ๋กœ๊ทธ๋“ค

 

๐Ÿ›‘ ์ฃผ์˜ ์‚ฌํ•ญ

- ๋ธŒ๋ผ์šฐ์ €๋Š” ํฌ๋กฌ์„ ์ถ”์ฒœํ•ฉ๋‹ˆ๋‹ค.

- ๋ธŒ๋ผ์šฐ์ €์— ๊ด‘๊ณ  ๋ฐ ํŠธ๋ž˜ํ‚น ์ œ๊ฑฐ ํ™•์žฅ ํ”„๋กœ๊ทธ๋žจ์ด ์žˆ๋‹ค๋ฉด, ์„ผํŠธ๋ฆฌ๊ฐ€ ์ •์ƒ ์ž‘๋™ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

 

 ๐ŸŸฃ 2.4 Next.js ํ”„๋กœ์ ํŠธ์— Sentry ์ฝ”๋“œ ๋„์ž…. (sentry ๋ฐ nextjs ๋ฒ„์ „์ด ์ตœ์‹ ์ด ์•„๋‹Œ ๊ฒฝ์šฐ)

- ๋ฃจํŠธ ๋””๋ ‰ํ† ๋ฆฌ์— ์œ„ ํŒŒ์ผ 3๊ฐœ๋ฅผ ์ƒ์„ฑํ•˜๊ณ , ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด์ค๋‹ˆ๋‹ค.

๋”๋ณด๊ธฐ

DSN ์–ป๋Š” ๋ฐฉ๋ฒ•

 

Setting -> Projects ->  ๋‚ด ํ”„๋กœ์ ํŠธ ํด๋ฆญ -> SDK Setup -> Client Keys(DSN)

// sentry.client.config.ts, sentry.server.config.ts, sentry.edge.config.ts
import * as Sentry from "@sentry/nextjs";

Sentry.init({
  dsn: "๋‚ด ์„ผํŠธ๋ฆฌ ํ”„๋กœ์ ํŠธ dsn",
  // Adjust this value in production, or use tracesSampler for greater control
  tracesSampleRate: 1,
  // Setting this option to true will print useful information to the console while you're setting up Sentry.
  debug: false,
});

 

next.config.js ํŒŒ์ผ์— ์•„๋ž˜ ์ฝ”๋“œ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

/** @type {import('next').NextConfig} */
const nextConfig = {}

module.exports = nextConfig

const { withSentryConfig } = require("@sentry/nextjs");

module.exports = withSentryConfig(
  module.exports,
  {
    silent: true,
    org: "๋‚ดํšŒ์‚ฌ",
    project: "sentry-test-project",
  },
  {
    widenClientFileUpload: true,
    transpileClientSDK: true,
    tunnelRoute: "/monitoring",
    hideSourceMaps: true,
    disableLogger: true,
  }
);

 

.sentryclirc ํŒŒ์ผ๋„ ์ƒ์„ฑ ํ›„ ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.

[auth]
token=๋‚ดํ† ํฐ

 

auth ํ† ํฐ์€ Settings -> Developer settings -> auth Tokens์—์„œ ์‹ ๊ทœ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

 

 

 

 

 

 

 

 

 

๐Ÿ“ ์ •๋ฆฌ 

  1. Sentry ์‚ฌ์ดํŠธ์—์„œ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑํ•˜๊ธฐ.
  2. next.js ํ”„๋กœ์ ํŠธ์— sentry module ์„ค์น˜ํ•˜๊ธฐ.
  3. ์ฝ”๋“œ ์ž‘์„ฑํ•˜๊ธฐ.
  4. sentry ์‚ฌ์ดํŠธ์—์„œ ํ™•์ธํ•˜๊ธฐ.

 

 

๊ธด ๊ธ€ ์ฝ์–ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค :) 
ํ‹€๋ฆฐ ๋‚ด์šฉ์ด ์žˆ๊ฑฐ๋‚˜, ๋ง๋ถ™์ผ ๋‚ด์šฉ์ด ์žˆ๋‹ค๋ฉด ์–ธ์ œ๋“ ์ง€ ๋Œ“๊ธ€ ๋‹ฌ์•„์ฃผ์„ธ์š”!
์ œ ๊ธ€์ด ์กฐ๊ธˆ์ด๋‚˜๋งˆ ์ฝ์œผ์‹  ๋ถ„๋“ค์—๊ฒŒ ๋„์›€์ด ๋˜๋„๋ก ๋…ธ๋ ฅํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค
๋‹ค์Œ ํŽธ์— ๋ดฌ์š”~

728x90
๋ฐ˜์‘ํ˜•