λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°

πŸ‘©πŸ»‍πŸ’» dev

[spotify-api] VINYLIFY : μŠ€ν¬ν‹°νŒŒμ΄ apiν™œμš©ν•œ 검색 + μž¬μƒ ν”„λ‘œμ νŠΈ(7) Sentry μ„€μ •

2024.08.10 - [πŸ‘©πŸ»‍πŸ’» dev] - [spotify-api] VINYLIFY : μŠ€ν¬ν‹°νŒŒμ΄ apiν™œμš©ν•œ 검색 + μž¬μƒ ν”„λ‘œμ νŠΈ(6)

 

 

[spotify-api] VINYLIFY : μŠ€ν¬ν‹°νŒŒμ΄ apiν™œμš©ν•œ 검색 + μž¬μƒ ν”„λ‘œμ νŠΈ(6)

[이전글] 2024.08.09 - [πŸ‘©πŸ»‍πŸ’» dev] - [spotify-api] VINYLIFY : μŠ€ν¬ν‹°νŒŒμ΄ apiν™œμš©ν•œ 검색 + μž¬μƒ ν”„λ‘œμ νŠΈ(5) react router μ„€μ • [spotify-api] VINYLIFY : μŠ€ν¬ν‹°νŒŒμ΄ apiν™œμš©ν•œ 검색 + μž¬μƒ ν”„λ‘œμ νŠΈ(5) react router

pyotato-dev.tistory.com

sentry can't fix this

 

유튜브 κ΄‘κ³ λ‘œ μ’…μ’… 봀던 sentry! μ˜€λŠ˜μ€ sentry μ μš©μ— λŒ€ν•΄ 정리λ₯Ό ν•˜κ³ μž ν•œλ‹€.
sentry에 λŒ€ν•΄ μ•Œκ²Œ 된 게 ν”„λ‘œμ νŠΈ 마무리 μ‹œμ μ΄λΌ, κ²½ν—˜μ€ 해보고 μ‹Άμ–΄μ„œ μ•„μ‰¬μš΄λŒ€λ‘œ μ μš©μ„ ν•΄λ΄€λ‹€.

⚠️ μ‹œκ°„μƒ λ§ˆμ§€λ§‰ 단계에 ν–ˆμ§€λ§Œ, μ„€μ • κ΄€λ ¨ νšŒκ³ λ“€μ„ 같이 λͺ¨μ•„두고 μ‹Άμ–΄μ„œ sentry 섀정에 λŒ€ν•΄ λ¨Όμ € λ‹€λ£¨κ²Œ λ˜μ—ˆμŠ΅λ‹ˆλ‹€! yarn, reactλ₯Ό κΈ°μ€€μœΌλ‘œ μž‘μ„±λ˜μ—ˆμŠ΅λ‹ˆλ‹€!

 

sentryλŠ” κ°œλ°œμžλ“€μ΄ μ„œλΉ„μŠ€μ™€ μ‹œμŠ€ν…œ μ „λ°˜μ— 걸쳐 μ„±λŠ₯ μ΄μŠˆλ‚˜ μ—λŸ¬λ“€μ„ λ°œκ²¬ν•˜κ³  λ””λ²„κΉ…ν•˜λŠ”λ° λ„μ™€μ£ΌλŠ” 도ꡬ닀.

뿐만 μ•„λ‹ˆλΌ μ—¬λŸ¬ μ„œλΉ„μŠ€λ‚˜ μ• ν”Œλ¦¬μΌ€μ΄μ…˜ 간에 μƒν˜Έμž‘μš©μ„ λͺ¨λ‹ˆν„°λ§ν•  수 μžˆλ‹€λŠ” μž₯점이 μžˆλ‹€.

 

μ•„λž˜μ²˜λŸΌ μ–΄λ–€ 경둜둜 μš”μ²­μ΄ 많이 κ°€κ³  μ΄μŠˆκ°€ μžˆμ„ λ•Œ 둜그λ₯Ό 확인할 수 있고, κ°€μž…ν–ˆλ˜ μ΄λ©”μΌλ‘œ μ—λŸ¬ λ°œμƒ μ‹œ 이메일이 μ˜¨λ‹€.

 

μ—λŸ¬κ°€ λ°œμƒν•  경우 dom λ¦¬ν”Œλ ˆμ΄λ„ κ°€λŠ₯ν•˜λ‹€.

 

μ΄λ ‡κ²Œ μ‹œκ°μ μœΌλ‘œ μ—λŸ¬κ°€ μ–΄λ–»κ²Œ μ–΄λ””μ„œ λ°œμƒν•˜λŠ” μ§€ μ•Œλ €μ£ΌλŠ” 게 μ‹ λ°•ν•œ κ±° κ°™λ‹€.

그럼 본격적으둜 섀정을 ν•΄λ³΄μž! (계정 κ°€μž… ν›„ 과정을 λ‹€λ£Ήλ‹ˆλ‹€.)

 

μ„€μ • λ°©λ²•μœΌλ‘œλŠ” νŒ¨ν‚€μ§€ λ§€λ‹ˆμ €/ loader/ cdn 방법이 μžˆλŠ”λ°, κ·Έ 쀑 νŒ¨ν‚€μ§€ λ§€λ‹ˆμ €λ‘œ μ„€μΉ˜λ₯Ό ν•  것이닀.

μ„€μΉ˜

yarn add @sentry/react

μ„€μ •

sentryλŠ” react router 버전을 μ—¬λŸ¬κ°œ μ§€μ›ν•œλ‹€.

κ°€λŠ₯ν•œ μ•±μ˜ μ΅œμƒλ‹¨μ— sentry μ΄ˆκΈ°ν™”λ₯Ό ν•΄μ€˜μ•Όν•œλ‹€. λ‹€μŒκ³Ό 같이 μ΄ˆκΈ°ν™” μ½”λ“œλ₯Ό μ• ν”Œλ¦¬μΌ€μ΄μ…˜ μ΅œμƒλ‹¨μ— ν•˜λ„λ‘ ν•˜μž. 

vinylify의 μ•± μ§„μž… νŒŒμΌμ€ main.tsxλ‹€. (viteμ—μ„œ index.htmlμ—μ„œ <script type="module" src="/src/main.tsx"></script>둜 μ„€μ •λ˜μ–΄ 있기 λ•Œλ¬Έ)

 

https://docs.sentry.io/platforms/javascript/#configure에 μžˆλŠ” μ½”λ“œλ₯Ό λ³΅μ‚¬ν•΄μ˜€λ©΄ λœλ‹€.

  • main.tsx 
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App.tsx';

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

Sentry.init({
  dsn: 'https://랜덀일련번호.ingest.us.sentry.io/랜덀일련번호2',
  integrations: [
    Sentry.browserTracingIntegration(),
    Sentry.replayIntegration(),
  ],
  // Performance Monitoring
  tracesSampleRate: 1.0, //  Capture 100% of the transactions
  // Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
  tracePropagationTargets: [
    'localhost',
    /^https:\/\/yourserver\.io\/api/,
    /^https:\/\/vinylify-express.vercel.app/, //둜그인 νŽ˜μ΄μ§€μ™€μ˜ μƒν˜Έμž‘μš©μ„ μ•ŒκΈ° μœ„ν•΄ 등둝
    // /^https:\/\/api.spotify.com/,
  ],
  // Session Replay
  replaysSessionSampleRate: 0.1, // This sets the sample rate at 10%. You may want to change it to 100% while in development and then sample at a lower rate in production.
  replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.
});

ReactDOM.createRoot(document.getElementById('root')!).render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
);

 

κ·Έ ν›„ vite.config.ts에 ν”ŒλŸ¬κ·ΈμΈ 섀정을 μΆ”κ°€ν•΄μ£Όμž.

import { sentryVitePlugin } from '@sentry/vite-plugin';
import react from '@vitejs/plugin-react';
import { resolve } from 'path';
import { defineConfig } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';

import type { UserConfig } from 'vite';
import type { InlineConfig } from 'vitest';

type ViteConfig = UserConfig & { test: InlineConfig };
const config: ViteConfig = {
  plugins: [
    react(),
    tsconfigPaths(),
    //////////////////////////////////////////////// πŸ’– μΆ”κ°€ ////////////////////////////////////////////////////////////////
    sentryVitePlugin({
      authToken: process.env.SENTRY_AUTH_TOKEN,
      org: 'pyotato',
      project: 'javascript-react',
    }),
    //////////////////////////////////////////////// πŸ’– μΆ”κ°€ ////////////////////////////////////////////////////////////////
  ],
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src'),
    },
  },
  test: {
    globals: true,
    environment: 'jsdom',
  },
  build: {
    sourcemap: true, // Source map generation must be turned on
  },
};
export default defineConfig(config);

 

κΉƒν—ˆλΈŒμ— sentry token 도 λ“±λ‘ν•΄μ£Όμž.


 πŸ“š References

https://docs.sentry.io/platforms/javascript/guides/react/

 

React | Sentry for React

Learn about Sentry's React SDK and how it automatically reports errors and exceptions in your application.

docs.sentry.io