[sentry源码阅读] event请求与写入过程初步剖析

客户端向sentry服务发送一个错误日志在sentry内部被称为event,以js客户端为例,异常发送时的请求url为:

http://localhost:8000/api/2/store/?sentry_version=7&sentry_client=raven-js%2F3.8.1&sentry_key=36db8da42fa84f83bac146be5096815c

sentry后台基于django框架,将所有的url分为两类,api.endpoints包处理以/api/0开头的请求,web.frontend包处理其他请求。以上url请求被转给web.frontend包下的view处理,在web.urls.py文件中,查看到如下代码,发现该url被转给StoreView

# in web.urls.py

urlpatterns += patterns(
    '',
    # Store endpoints first since they are the most active
    url(r'^api/store/$', api.StoreView.as_view(),
        name='sentry-api-store'),
    url(r'^api/(?P<project_id>[\w_-]+)/store/$', api.StoreView.as_view(),
        name='sentry-api-store'),
    url(r'^api/(?P<project_id>\d+)/csp-report/$', api.CspReportView.as_view(),
        name='sentry-api-csp-report'),


StoreView:

StoreView类中,有get、post两个方法,这两个方法都会调用process()方法。process()方法是处理请求的入口方法,请求的处理大体步骤为:

1、过滤请求

if helper.should_filter(project, data, ip_address=remote_addr):
这段代码检查请求字符串data携带的字段,决定是否过滤该请求。

2、限流

if rate_limit is None or rate_limit.is_limited:
这段代码RateLimit对象判定当前是否限流,如果限流,请求被直接丢弃。

3、查看该请求是否已经被处理过,以及过滤请求中敏感字段:

if scrub_data:
    # We filter data immediately before it ever gets into the queue
    sensitive_fields_key = 'sentry:sensitive_fields'

同时在缓存中判断该请求是否已经存在:

cache_key = 'ev:%s:%s' % (project.id, event_id,)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值