4. 北京/上海/广州 0xFF Life's pathetic, go Pythonic!
起源
● 2010
● http://disqus.com/
● django-db-log (祖父)
● tl;dr Sentry and Raven
are StarCraft 2(星际争
霸 2) units.
● driven-by-open-source
commit 3c2e87573d3bd16f61cf08fece0638cc47a4fc22
Author: David Cramer <dcramer@gmail.com>
Date: Mon May 12 16:26:19 2008 +0000
initial working code
djangodblog/__init__.py | 35
+++++++++++++++++++++++++++++++++++
djangodblog/models.py | 36
++++++++++++++++++++++++++++++++++++
2 files changed, 71 insertions(+)
5. 北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Sentry 5
● 2012
● Protocol Version 3
● branch: 5.4.x-maint
6. 北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Sentry 6
● 2013
● Protocol Version 4
● Protocol Version 5
● Alerts
● Filters
7. 北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Sentry 7
● 2014
● Organizations
● TSDB
● Rules
● Web API
● Protocol Version 6
● BIGINT
● Help Pages
8. 北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Senty 8
● 2015 ?
● Most of the
application has
been overhauled
and rewritten on
top of React and
our web API.
● beta
9. 北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Sentry 是什么
● 一个错误记录和汇聚平台
○ Server: Sentry (The Sentry Open Source Server)
○ Client: The Raven Clients.
13. DEMO
1. Hosted Sentry
a. https://www.getsentry.
com/signup/
b. 14-day Free Trial
2. Sentry On Promise
a. https://docs.getsentry.
com/on-
premise/server/installati
on/
b. Sentry Internal
16. 北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Raven 102
● WSGI middleware
● raven/middleware.py
```
A WSGI middleware which will
attempt to capture any
uncaught exceptions and send
them to Sentry.
>>> from raven.base import Client
>>> application = Sentry
(application, Client())
```
23. 北京/上海/广州 0xFF Life's pathetic, go Pythonic!
HTTP Protocol
● 用户认证跟 Web 复用了
● /api/store
● GET/POST DATA
24. 北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Interface
An interface is a structured
representation of data, which may
render differently than the default
``extra`` metadata in an event.
● to_python
● get_api_context
● to_json
● get_path
● get_alias
● get_hash
● get_score
● ...
34. 北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Example
class Event(Model):
"""
An individual event.
"""
__core__ = False
...
time_spent = BoundedIntegerField(null=True)
data = NodeField(blank=True, null=True)
35. 北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Cache
● django
○ filesystem
○ memcached
○ local memory
○ dummy
● redis
● set
● get
● delete
● redis:
○ from nydus.db import create_cluster
○ 支持 cluster
○ 重写了 rb,但还没有在已发布的版本里使用
36. 北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Example
● Cache 与 Model
○ db/models/manager.py
○ class BaseManager(Manager)
● get_from_cache
● updated by signal
● deleted by signal
37. 北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Buffer
This is useful in situations where a single event
might be happening so fast that the queue can't
keep up with the updates.
● InProcess (no buffer)
● Redis
● 降低 MySQL 数据的 QPS (写)
● 支持 Cluster Redis
● Redis 2.6.12 or newer
41. 北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Notifications
● Rules
○ An event is first seen (the first event in a rollup)
○ An event changes state from resolved to unresolved
● State
○ Unresolved
○ Resolved
○ Muted
● Condition
● Action
42. 北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Tagging Events
● Event 分类
● We’ll automatically index all tags
for an event, as well as the
frequency and the last time a
value has been seen.
● TagValue
● GroupTagValue
● Added by buffer
44. 北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Web Profile
● ?prof=1
● DEBUG
● super user
● src/sentry/utils/debug.py
def can(self, request):
if 'prof' not in request.GET:
return False
if settings.DEBUG:
return True
if hasattr(request, 'user') and
request.user.is_superuser:
return True
return False
45. 北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Sentry to Sentry
● 自举
● DISABLE_RAVEN
● default: project id == 1
● src/sentry/utils/raven.py
52. 北京/上海/广州 0xFF Life's pathetic, go Pythonic!
升级
● 5.x-maint support UDP
● but 7.x not
● We have to backport UDP to 7.x
● 幸好原来的接口还在
❏ src/sentry/conf/server.py:
❏ #socket.setdefaulttimeout(5)
❏ src/sentry/coreapi.py:
❏ insert_data_to_database_sync (async to
sync,Redis 内存放大太厉害,因为 cache
原因)