모니터링 플랫폼으로 Sentry를 사용하길래 (라인, 카카오페이 등) 사용해보려고 한다. 그동안은 log파일을 직접 확인했었다.(....)
현재 php를 사용 중이라서 PHP에서 sentry를 사용하려고 했는데 공식 문서를 찾아보니 PHP 7.2 버전 이상부터 지원된다고 한다.
https://docs.sentry.io/platforms/php/
PHP
On this page, we get you up and running with Sentry's PHP SDK, automatically reporting errors and exceptions in your application. If you don't already have an a
docs.sentry.io
그래서 파이썬으로 먼저 사용해보려고 한다.
파이썬은 3.4 이상을 지원한다고 한다. 현재 내가 사용 중인 버전은 3.4.6이다.
https://docs.sentry.io/platforms/python/
Python
On this page, we get you up and running with Sentry's SDK, so that it will automatically report errors and exceptions in your application. Get started using a g
docs.sentry.io
계정 및 프로젝트 설정
아래에서 계정과 프로젝트를 설정한다.
https://sentry.io/signup/
sentry.io
개인이 사용할 경우, 회사명에 이름을 넣으면 된다.
사용할 언어 선택 하면 진행 방법이 나온다.
Python SDK 설치하기
pip install --upgrade sentry-sdk
예제코드
import sentry_sdk
sentry_sdk.init(
dsn="발급받은 dsn주소 입력",
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for performance monitoring.
# We recommend adjusting this value in production.
traces_sample_rate=1.0,
)
division_by_zero = 1 / 0 를 추가하여 의도적으로 에러를 발생시킨다.
import sentry_sdk
sentry_sdk.init(
dsn="https://450c93cd15bd413489a87f4e2b33a9b9@o4504575442812928.ingest.sentry.io/4504575446745088",
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for performance monitoring.
# We recommend adjusting this value in production.
traces_sample_rate=1.0,
)
division_by_zero = 1 / 0
웹에서 확인할 수 있다.(ZeroDivisionError)
맨 아래는, 웹에서 실행한 테스트 코드이다.
실행하고 나면 오류 대기중 상태에서 오류 수신으로 변경된다.
내 오류로 이동을 하면, 방금 발생시킨 오류에 대해 확인할 수 있다.
발생시킨 내용과 같이, 0으로 나눠서 발생한 에러이고 해당 에러에 대해 나타내고 있다.
그리고 몇 번째 줄에서 발생했는지도 표시해 준다..(wow)
아래에는 실행 파일 경로와 언어 버전에 대해 표시한다.
와 너무 신기하다. 그동안 왜 몰랐을까.. 테스트 코드 실행 끝
다음엔 기존 사용 중인 코드에 적용해 봐야겠다.
'Development' 카테고리의 다른 글
dbeaver 설치하기 (0) | 2023.02.06 |
---|---|
IP와 포트포워딩에 관해 (0) | 2023.01.30 |
VPN과 프록시의 차이 (0) | 2023.01.20 |
side effect (0) | 2023.01.13 |
[VSC] sftp 접속하기 (0) | 2023.01.12 |