【问题标题】:sentry sdk custom performance integration for python apppython 应用程序的 sentry sdk 自定义性能集成
【发布时间】:2022-11-18 04:23:52
【问题描述】:
标签:
python
performance
sentry
【解决方案1】:
你不需要使用capture_event
我建议改用sentry_sdk.start_transaction。它还允许跟踪您的功能性能。
看我的例子
from time import sleep
from sentry_sdk import Hub, init, start_transaction
init(
dsn="dsn",
traces_sample_rate=1.0,
)
def sentry_trace(func):
def wrapper(*args, **kwargs):
transaction = Hub.current.scope.transaction
if transaction:
with transaction.start_child(op=func.__name__):
return func(*args, **kwargs)
else:
with start_transaction(op=func.__name__, name=func.__name__):
return func(*args, **kwargs)
return wrapper
@sentry_trace
def b():
for i in range(1000):
print(i)
@sentry_trace
def c():
sleep(2)
print(1)
@sentry_trace
def a():
sleep(1)
b()
c()
if __name__ == '__main__':
a()
启动此代码后,您可以看到交易a与孩子b和c的基本信息