客户端向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,)