Sentry

概述:Sentry

[TOC]

官方网站 https://docs.sentry.io/

1. Sentry python

1.1 Install

1
pip install --upgrade sentry-sdk

1.2 configure

1
2
3
4
5
6
7
8
9
10
11
12
import sentry_sdk

sentry_sdk.init(
"https://b7d9fd41905a4d5795e5922eef4bab93@o474387.ingest.sentry.io/5707083",
# 请修改上述的地址
# 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
)

abc = 1 / 0

1.3 Issues 效果

![image-20210406150501239](/Users/junmingguo/Library/Application Support/typora-user-images/image-20210406150501239.png)

2. 补充

2.1 针对Django框架的配置

1
2
3
4
5
6
7
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration

sentry_sdk.init(
dsn="https://bedd55c63dc0443398c8401d3bad3421@sentry.io/1393845",
integrations=[DjangoIntegration()], # DjangoIntegration记录信息包括基本的HTTP method, URL, headers, form data, JSON payloads等
)

2.2 其它配置参数

1
2
3
4
send_default_pii=True,  # 显示原始的body,multifiles,用户信息
environment='STAGING', # 显示环境
sample_rate=1.0, # 采样率,目前是全量上报。取值范围: 0.0 ~ 1.0
before_send=before_send, # 上报前执行过滤函数,可指定错误不上报

2.3 过滤指定类型错误

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import sentry_sdk


def before_send(event, hint):
if 'exc_info' in hint:
exc_type, exc_value, tb = hint['exc_info']
if isinstance(ZeroDivisionError, exc_type):
return None
return event

sentry_sdk.init(before_send=before_send)

sentry_sdk.init(
"https://b7d9fd41905a4d5795e5922eef4bab93@o474387.ingest.sentry.io/5707083",
# 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,
before_send=before_send,
)

aaa = 1 / 0