# Sentry ![캡처](https://user-images.githubusercontent.com/5876149/99229632-9ef07780-2831-11eb-87f9-8a213bdebad6.JPG) ## Sentry 란 ? ``` Sentry's SDKs enable automatic reporting of errors and exceptions. ``` Sentry 는 자동적으로 에러 및 예외처리에 대해서 수집하는 기능을 가지고 있는 SDK 입니다. ## 주요기능 ( 11조가 구현하려고 하는 것들 ) - 에러 메세지 수집 - 에러 메세지 그룹핑 가능 - 에러 콜 스택 확인 ## SDK - 초기 설정 ```jsx import Sentry from 'sentry-clone' Sentry.init({ dsn: "https://examplePublicKey@o0.ingest.sentry.io/0", release: "my-project-name@" + process.env.npm_package_version, userID: "test", // dotenv -> 유저아이디 password: "1234", // dotenv -> 유저 패스워드 }); // sentry-clone.js const defaultSetting = { dsn: "" release: "" } let token; export default { init: async (info) => { const response = axios.get(info); token = response.data.token; } } ``` - 로그 설정 ```jsx // ~ YourCode ex) 로그인 기능코드 ~ // Sentry.captureMessage(`${user.nickname}님이 로그인 하였습니다.`); // ~ YourCode ~ // // Type 추가 // Sentry.addMessageType(); // sentry-clone.js let token; // <-- const typeList=['default'] export default { ... captureMessage: (message, type = 'default') => { if(!typeList.includes(type)){ throw new Error("지정되지 않은 타입입니다.") } axios.post( '로그 메세지 받는 URL', { message, level }, { header: `Bearer ${token}`} ); }, addMessageType: (addType: string or Array) => { if(addType : string) { typeList.push(addType); } else { typeList=[...typeList, ...addType]; } } } ``` - 에러 설정 ```jsx try { aFunctionThatMightFail(); } catch (err) { Sentry.captureException(err); } // sentry-clone.js let token; // <-- export default { ... captureMessage: (error, level = 5) => { axios.post( 'error 메세지 받는 URL', { error, level }, { header: `Bearer ${token}`} ); } } ``` - [에러 레벨 설정](https://github.com/getsentry/sentry-javascript/blob/73b9bbd4c42efa5f95a7d5446b3390dd859f82fa/packages/types/src/severity.ts)