Rya*_*der 7 python performance sentry
Sentry 可以跟踪 celery 任务和 API 端点的性能 https://docs.sentry.io/product/performance/
我有一个由老太婆吃午饭的自定义脚本,并执行一组类似的任务
我想将sentry_sdk合并到我的脚本中以获取任务的性能跟踪
任何建议如何使用 https://getsentry.github.io/sentry-python/api.html#sentry_sdk.capture_event
小智 6
你不需要使用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()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
732 次 |
| 最近记录: |