SlideShare a Scribd company logo
1 of 66
Download to read offline
Dive into Sentry
The modern error logging and aggregation platform
XTao
09.19.2015 Beijing
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
徐涛
● @ 豆瓣
● (?:产品开发|运维)工程师
● (?:CODE|DevOps|Git|Python)
● 2014 PyConChina Beijing
● https://blog.xtao.me
❏ Douban: @xtaooooo
❏ Twitter: @xtao
❏ Github: @xtao
Sentry 概述
Sentry 毕业于 Disqus
https://engineering.disqus.com/
Sentry 历史
Sentry 是什么
DEMO
北京/上海/广州 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(+)
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Sentry 5
● 2012
● Protocol Version 3
● branch: 5.4.x-maint
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Sentry 6
● 2013
● Protocol Version 4
● Protocol Version 5
● Alerts
● Filters
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Sentry 7
● 2014
● Organizations
● TSDB
● Rules
● Web API
● Protocol Version 6
● BIGINT
● Help Pages
北京/上海/广州 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
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Sentry 是什么
● 一个错误记录和汇聚平台
○ Server: Sentry (The Sentry Open Source Server)
○ Client: The Raven Clients.
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
为什么要用 Sentry
● 详细的错误息
○ 某一行代码 (Python)
○ 某一个变量 (Python)
● 详细错误分类
○ Tag
● 提醒
● 合理的重复错误处理
● 支持多种语言
○ 对 Python 支持好
❏ 额外的收获
❏ 入门
❏ 一个很好的 Django 项目,如果你要
学习如何使用 Django 的话,可以读
一下 Sentry 的源码
❏ 进阶
❏ Sentry 应该算是一个中型 Web 项目
了,如果你缺少 Web 项目开发经
验,也可以从源码中获取一些经验
❏ 开源
❏ 一个 Python 开源 Web 应用的示
例,数据迁移还是靠谱的
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Sentry - 服务端(7.x)
● Backend
○ Python
○ Django
○ Celery
● Frontend
○ JQuery
○ Backbone
○ Underscore
○ Bootstrap
○ Moment
● Database
○ MySQL
○ PostgreSQL
● KV
○ Cassandra
○ Riak
○ Redis
● Queue
○ Redis
○ RabbitMQ
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Raven - 官方支持的 Client
● Python
● JavaScript
● Node.js
● PHP
● Ruby
● Objective-C
● Java
● C#
● Go
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
Sentry 使用
如何提交错误
Raven
DSN
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Raven 101
pip install raven --upgrade
from raven import Client
client = Client('___DSN___')
try:
1 / 0
except ZeroDivisionError:
client.captureException()
def handle_request(request):
client.context.merge({'user': {
'email': request.user.email
}})
try:
...
finally:
client.context.clear()
北京/上海/广州 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())
```
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
DSN 101
'{PROTOCOL}://{PUBLIC_KEY}:{SECRET_KEY}@{HOST}/{PATH}{PROJECT_ID}'
http://c44a73655e50454581da995bbedd392a:
8d29447e0e8241b9a178fd726fb07190@onimaru.intra.douban.com/10
udp://c44a73655e50454581da995bbedd392a:
8d29447e0e8241b9a178fd726fb07190@onimaru-udp.intra.douban.com:
4008/10
Sentry 特性
(๑•̀ㅂ•́)‫✧و‬ (つд⊂)
Event
Group
Protocol
Interface
TSDB
Buffer
Cache
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Event
● HTTP(DATA)
● UDP(DATA) ● EventManager ● Project
● Event
● Group
● EventMapping
○ event_id: uuid.uuid4().
hex
● UserReport
○ 用户反馈 Sentry 问题
● post_process_group.delay
● index_event.delay
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Group
● hashes
○ checksum (provided by client)
○ fingerprint / (default + fingerprint)
○ default (first interface ordered by score)
● find group
○ find group at GroupHash by hash
○ first matched group
● sample event (count, time)
● regression (resolved event)
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Protocol
● CLIENT_RESERVED_ATTRS = (
● 'project',
● 'event_id',
● 'message',
● 'checksum',
● 'culprit',
● 'fingerprint',
● 'level',
● 'time_spent',
● 'logger',
{
"event_id": "fc6d8c0c43fc4630ad850ee518f1b9d0",
"culprit": "my.module.function_name",
"timestamp": "2011-05-02T17:41:36",
"message": "SyntaxError: Wattttt!"
"sentry.interfaces.Exception": {
"type": "SyntaxError":
"value": "Wattttt!",
"module": "__builtins__"
}
}
● 'server_name',
● 'site',
● 'timestamp',
● 'extra',
● 'modules',
● 'tags',
● 'platform',
● 'release',
● )
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
UDP Protocol
"AUTHnnDATA"
● AUTH
○ "Sentry key=value, key=value, …"
● DATA
○ json string
○ zlib
○ base64
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
HTTP Protocol
● 用户认证跟 Web 复用了
● /api/store
● GET/POST DATA
北京/上海/广州 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
● ...
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Interface - Exception
● 标准的 Python 异常
● type, value, module
● stacktrace == sentry.interfaces.
Stacktrace
>>> {
>>> "type": "ValueError",
>>> "value": "My exception value",
>>> "module": "__builtins__"
>>> "stacktrace": {
>>> # see sentry.interfaces.Stacktrace
>>> }
>>> }
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Interface - Message
● message (<= 1000)
● params
>>> {
>>> "message": "My raw message
with interpreted strings like %s",
>>> "params": ["this"]
>>> }
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Interface - HTTP
● 常用的 HTTP 参数 >>> {
>>> "url": "http://absolute.uri/foo",
>>> "method": "POST",
>>> "data": {
>>> "foo": "bar"
>>> },
>>> "query_string": "hello=world",
>>> "cookies": "foo=bar",
>>> "headers": {
>>> "Content-Type": "text/html"
>>> },
>>> "env": {
>>> "REMOTE_ADDR": "192.168.0.1"
>>> }
>>> }
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Interface - Query
● 用于记录 SQL >>> {
>>> "query": "SELECT 1"
>>> "engine": "psycopg2"
>>> }
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Interface - Template
● A rendered template (generally
used like a single frame in a
stacktrace).
● The attributes ``filename``,
``context_line``, and ``lineno`` are
required.
>>> {
>>> "abs_path": "/real/file/name.html"
>>> "filename": "file/name.html",
>>> "pre_context": [
>>> "line1",
>>> "line2"
>>> ],
>>> "context_line": "line3",
>>> "lineno": 3,
>>> "post_context": [
>>> "line4",
>>> "line5"
>>> ],
>>> }
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Interface - User
● 定义一个用户 >>> {
>>> "id": "unique_id",
>>> "username": "my_user",
>>> "email": "foo@example.com"
>>> "ip_address": "127.0.0.1",
>>> "optional": "value"
>>> }
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Interface - Stacktrace
● Python Frame
>>> {
>>> "frames": [{
>>> "abs_path": "/real/file/name.py"
>>> "filename": "file/name.py",
>>> "function": "myfunction",
>>> "vars": {
>>> "key": "value"
>>> },
>>> "pre_context": [
>>> "line1",
>>> "line2"
>>> ],
>>> "context_line": "line3",
>>> "lineno": 3,
>>> "in_app": true,
>>> "post_context": [
>>> "line4",
>>> "line5"
>>> ],
>>> }],
>>> "frames_omitted": [13, 56]
>>> }
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
TSDB - 时序数据库
● Dummy (none)
● InMemory (defaultdict)
● Redis (hashes)
Redis:
{
"TSDBModel:epoch:shard": {
"Key": Count
}
}
# rollups must be ordered from highest
granularity to lowest
SENTRY_TSDB_ROLLUPS = (
# (time in seconds, samples to keep)
(10, 360), # 60 minutes at 10 seconds
(3600, 24 * 7), # 7 days at 1 hour
(3600 * 24, 60), # 60 days at 1 day
)
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
NodeStore - KV 数据库
● riak
● cassandra
● django (node table)
● 用于和数据一起存储一些特殊信息(比如不
适合存在数据库里的大文本等)
● validate
● create
● delete
● delete_multi
● get
● get_multi
● set
● set_multi
● generate_id
● cleanup
北京/上海/广州 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)
北京/上海/广州 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,但还没有在已发布的版本里使用
北京/上海/广州 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
北京/上海/广州 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
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Buffer Internal
● 生产者
● incr
●
● 'b:k:%s:%s' (hashmap, key_expire = 60 * 60
# 1 hour)
○ 'm'
○ 'f'
○ 'l+%s'
○ 'e+%s'
● 'b:p' (Sorted sets)
● 消费者
● process pending
● process
'flush-buffers': {
'task': 'sentry.tasks.process_buffer.process_pending',
'schedule': timedelta(seconds=10),
'options': {
'expires': 10,
'queue': 'counters-0',
}
},
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Membership
Roles
● Member *:read
● Admin *:write
● Owner *:delete
Scoping has access to all teams
● 跟 GitHub 类似的组织结构以及权限控制
● Organization - Owner, Admin, Member
● Team - (Role, Project)
● Project
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Sensitive Data
● 'password',
● 'secret',
● 'passwd',
● 'authorization',
● 'api_key',
● 'apikey',
● 'access_token',
● DEFAULT_SCRUBBED_FIELDS
北京/上海/广州 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
北京/上海/广州 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
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Rollups & Sampling
● Rollups
○ Raven.captureException(ex, {fingerprint: ['my', 'custom', 'fingerprint']})
○ Raven.captureException(ex, {fingerprint: ['{{ default }}', 'other', 'data']})
● Sampling
○ Count
○ Time
北京/上海/广州 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
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Sentry to Sentry
● 自举
● DISABLE_RAVEN
● default: project id == 1
● src/sentry/utils/raven.py
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
PostgreSQL & Gevent
● psycopg2
● src/sentry/utils/gevent.py
● Sentry 官方使用的应该是这个数据库,有非阻塞的 patch,支持异步
Sentry
@douban
有料
其中充斥着不少嘈点
问题
部署
监控
调优
Tips
“自己解决不了的
问题,不要指望工
具能帮你解决”
乔治@豆瓣
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Monitor
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
豆瓣
● 应用
○ Python (大部分)
○ Javascript (前端)
○ Go (少部分)
○ C++/C/Java (少量)
● 错误
○ devtools (DIY, 已废弃)
○ Sentry
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
问题
● 已经部署了一套 Sentry
● 5.x 使用 UDP 协议
● 测试以及线上,有丢错误情况
● 且比较明显
● 但是这时还没有针对 Sentry 的监控
● 开始研究黑盒
● UDP Worker CPU 使用率比较高
● UDP 是用 DNS 做负载均衡
● DNS 因为 cache 问题,导致负载不平衡
● 使用 Random 改善了 cache 带来的隐患
● 查看 Worker 代码
● Gevent / Eventlet 使用错误,没有 Monkey
Patch
● 5.x 数据库压力较大,需要做合并写
北京/上海/广州 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
原因)
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Insert Queue
● insert_data_to_database - cache
● preprocess_event - queue
● save_event - queue
●
● insert_data_to_database_sync - queue
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
部署情况
● HTTP x 4 (默认 Sentry 是用 Gunicorn 管理 Worker 的)
● UDP x 4 (开启了 Gevent,收到包后,扔到队列)
● Celery x 4 (Task consumer, 默认是开启 CPU_NUM 个 Worker)
● Celery Beat x 1
● Cron:cleanup 21 (只保留 21 天的数据)
● HTTP 前面用 LVS + Nginx 做负载均衡
● UDP 用 DNS 做负载均衡
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
内部配置
● LDAP
○ 我们用的用户帐号系统
○ 配置一下 Sentry 即可
● MAIL
○ 配置 Sentry 邮件服务器
● IRC
○ sentry-irc
○ 因为我们使用了 ircbot,稍微改了一下这个插件代码
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Why UDP
● 快
● 应用不需要关心 Sentry 服务是否正常
● 即使 Sentry 出问题,也不影响应用
● 可以观察系统 UDP 丢包情况,判断 UDP 服务是否正常
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Celery
● 芹菜
● 还没有吃透
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
DBA
● Redis
○ Memory
○ QPS
○ CPU
○ Queue Size
● MySQL
○ QPS
■ update
■ insert
■ delete
■ select
○ thread
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
Sentry
● Statsd
○ celery worker cpu
○ udp worker cpu
○ http worker cpu
● App 内统计
○ task 执行时间
○ task 执行数量
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
UDP Received Packet (Sentry)
● udp worker
● 收包后记录
● d = sock.recvfrom(self.BUF_SIZE)
● statsd.increment(STATSD_KEY_RECV)
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
UDP Received Packet (Kernel)
● UDP Server 收到的包数 (by diamond)
● ~ $ sudo /sbin/iptables -t filter -I INPUT -i lan -p udp --dport 4008 -j ACCEPT
● ~ $ sudo /sbin/iptables -L INPUT 1 -nvx
● 52308183 414772916064 ACCEPT udp -- lan * 0.0.0.0/0
0.0.0.0/0 udp dpt:4008
● pkts (UDP 完整包数,底层已经处理了分包问题)
● bts
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
UDP Dropped Packets (Kernel)
● cat /proc/net/udp
● sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode ref pointer drops
● 41: 00000000:80CE 00000000:0000 07 00000000:00000000 00:00000000 00000000 6561 0 4110825944 2 ffff8809c23e5e40 0
● cat /proc/net/snmp
● Udp: InDatagrams NoPorts InErrors OutDatagrams RcvbufErrors SndbufErrors
● Udp: 5416706536 993028 290598311 22725578190 4662160 1318
● UdpLite: InDatagrams NoPorts InErrors OutDatagrams RcvbufErrors SndbufErrors
● UdpLite: 0 0 0 0 0 0
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
TIPS
● Webhooks:
○ 默认禁止访问内网 IP, 需要更改一下配置
● Timezone
○ SENTRY_DEFAULT_TIME_ZONE = 'Asia/Shanghai' 设置用户默认时区
● Public
○ SENTRY_PUBLIC = False 这个权限有点问题,不要开启
● Register
○ SENTRY_FEATURES['auth:register'] = False 禁止自己注册
北京/上海/广州 0xFF Life's pathetic, go Pythonic!
下一步计划
● 项目错误统计(QPS,Sentry 提供的图还不能满足需求)
● Profile 工具,有助于分析 Worker 瓶颈 (Celery)
● 应对雪崩式错误的处理方案(压测 Sentry)
● 尝试一下 MySQL + Redis + Gevent
Jobs
● 2016 校招
● always 社招
● TO: ruby@douban.com
● 当然 python 也可以
● TO: python@douban.com
● 如果你想试试 js 也可以尝试
● TO: js@douban.com
● 详情: http://jobs.douban.com
北京/上海/广州 0xFF Life's pathetic, go Pythonic!

More Related Content

What's hot

You didnt see it’s coming? "Dawn of hardened Windows Kernel"
You didnt see it’s coming? "Dawn of hardened Windows Kernel" You didnt see it’s coming? "Dawn of hardened Windows Kernel"
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
Peter Hlavaty
 
Defcon Moscow #0x0A - Mikhail Firstov "Hacking routers as Web Hacker"
Defcon Moscow #0x0A - Mikhail Firstov "Hacking routers as Web Hacker"Defcon Moscow #0x0A - Mikhail Firstov "Hacking routers as Web Hacker"
Defcon Moscow #0x0A - Mikhail Firstov "Hacking routers as Web Hacker"
Defcon Moscow
 
XFLTReaT: A New Dimension in Tunneling (Shakacon 2017)
XFLTReaT: A New Dimension in Tunneling (Shakacon 2017)XFLTReaT: A New Dimension in Tunneling (Shakacon 2017)
XFLTReaT: A New Dimension in Tunneling (Shakacon 2017)
Balazs Bucsay
 
Linuxday.at - Lightning Talk
Linuxday.at - Lightning TalkLinuxday.at - Lightning Talk
Linuxday.at - Lightning Talk
Jan Gehring
 

What's hot (20)

Fluentd at HKOScon
Fluentd at HKOSconFluentd at HKOScon
Fluentd at HKOScon
 
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsEffizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
 
rsyslog meets docker
rsyslog meets dockerrsyslog meets docker
rsyslog meets docker
 
Rihards Olups - Encrypting Daemon Traffic With Zabbix 3.0
Rihards Olups - Encrypting Daemon Traffic With Zabbix 3.0Rihards Olups - Encrypting Daemon Traffic With Zabbix 3.0
Rihards Olups - Encrypting Daemon Traffic With Zabbix 3.0
 
Finding Needles in Haystacks
Finding Needles in HaystacksFinding Needles in Haystacks
Finding Needles in Haystacks
 
Pwning with powershell
Pwning with powershellPwning with powershell
Pwning with powershell
 
Introduction of ShinoBOT (Black Hat USA 2013 Arsenal)
Introduction of ShinoBOT (Black Hat USA 2013 Arsenal)Introduction of ShinoBOT (Black Hat USA 2013 Arsenal)
Introduction of ShinoBOT (Black Hat USA 2013 Arsenal)
 
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
You didnt see it’s coming? "Dawn of hardened Windows Kernel" You didnt see it’s coming? "Dawn of hardened Windows Kernel"
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
 
Power of linked list
Power of linked listPower of linked list
Power of linked list
 
How do event loops work in Python?
How do event loops work in Python?How do event loops work in Python?
How do event loops work in Python?
 
Defcon Moscow #0x0A - Mikhail Firstov "Hacking routers as Web Hacker"
Defcon Moscow #0x0A - Mikhail Firstov "Hacking routers as Web Hacker"Defcon Moscow #0x0A - Mikhail Firstov "Hacking routers as Web Hacker"
Defcon Moscow #0x0A - Mikhail Firstov "Hacking routers as Web Hacker"
 
XFLTReaT: A New Dimension in Tunneling (Shakacon 2017)
XFLTReaT: A New Dimension in Tunneling (Shakacon 2017)XFLTReaT: A New Dimension in Tunneling (Shakacon 2017)
XFLTReaT: A New Dimension in Tunneling (Shakacon 2017)
 
The internet of $h1t
The internet of $h1tThe internet of $h1t
The internet of $h1t
 
Get-Help: An intro to PowerShell and how to Use it for Evil
Get-Help: An intro to PowerShell and how to Use it for EvilGet-Help: An intro to PowerShell and how to Use it for Evil
Get-Help: An intro to PowerShell and how to Use it for Evil
 
Injection on Steroids: Codeless code injection and 0-day techniques
Injection on Steroids: Codeless code injection and 0-day techniquesInjection on Steroids: Codeless code injection and 0-day techniques
Injection on Steroids: Codeless code injection and 0-day techniques
 
Non-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsNon-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.js
 
Veil-Ordnance
Veil-OrdnanceVeil-Ordnance
Veil-Ordnance
 
Jwt == insecurity?
Jwt == insecurity?Jwt == insecurity?
Jwt == insecurity?
 
Linuxday.at - Lightning Talk
Linuxday.at - Lightning TalkLinuxday.at - Lightning Talk
Linuxday.at - Lightning Talk
 
The Veil-Framework
The Veil-FrameworkThe Veil-Framework
The Veil-Framework
 

Viewers also liked

DjangoCon 2013 - How to Write Fast and Efficient Unit Tests in Django
DjangoCon 2013 - How to Write Fast and Efficient Unit Tests in DjangoDjangoCon 2013 - How to Write Fast and Efficient Unit Tests in Django
DjangoCon 2013 - How to Write Fast and Efficient Unit Tests in Django
Casey Kinsey
 
OpenStack Horizon: Controlling the Cloud using Django
OpenStack Horizon: Controlling the Cloud using DjangoOpenStack Horizon: Controlling the Cloud using Django
OpenStack Horizon: Controlling the Cloud using Django
David Lapsley
 

Viewers also liked (12)

Introduction to sentry
Introduction to sentryIntroduction to sentry
Introduction to sentry
 
Sentry - An Introduction
Sentry - An Introduction Sentry - An Introduction
Sentry - An Introduction
 
Introduction openstack-horizon
Introduction openstack-horizonIntroduction openstack-horizon
Introduction openstack-horizon
 
DjangoCon 2013 - How to Write Fast and Efficient Unit Tests in Django
DjangoCon 2013 - How to Write Fast and Efficient Unit Tests in DjangoDjangoCon 2013 - How to Write Fast and Efficient Unit Tests in Django
DjangoCon 2013 - How to Write Fast and Efficient Unit Tests in Django
 
Secure Search - Using Apache Sentry to Add Authentication and Authorization S...
Secure Search - Using Apache Sentry to Add Authentication and Authorization S...Secure Search - Using Apache Sentry to Add Authentication and Authorization S...
Secure Search - Using Apache Sentry to Add Authentication and Authorization S...
 
OpenStack Horizon: Controlling the Cloud using Django
OpenStack Horizon: Controlling the Cloud using DjangoOpenStack Horizon: Controlling the Cloud using Django
OpenStack Horizon: Controlling the Cloud using Django
 
Apache Sentry for Hadoop security
Apache Sentry for Hadoop securityApache Sentry for Hadoop security
Apache Sentry for Hadoop security
 
Hadoop Security: Overview
Hadoop Security: OverviewHadoop Security: Overview
Hadoop Security: Overview
 
Efficient Django
Efficient DjangoEfficient Django
Efficient Django
 
Hadoop and Data Access Security
Hadoop and Data Access SecurityHadoop and Data Access Security
Hadoop and Data Access Security
 
12 tips on Django Best Practices
12 tips on Django Best Practices12 tips on Django Best Practices
12 tips on Django Best Practices
 
Hadoop Security Architecture
Hadoop Security ArchitectureHadoop Security Architecture
Hadoop Security Architecture
 

Similar to Dive into sentry

支撐英雄聯盟戰績網的那條巨蟒
支撐英雄聯盟戰績網的那條巨蟒支撐英雄聯盟戰績網的那條巨蟒
支撐英雄聯盟戰績網的那條巨蟒
Toki Kanno
 
Intravert Server side processing for Cassandra
Intravert Server side processing for CassandraIntravert Server side processing for Cassandra
Intravert Server side processing for Cassandra
Edward Capriolo
 

Similar to Dive into sentry (20)

Go debugging and troubleshooting tips - from real life lessons at SignalFx
Go debugging and troubleshooting tips - from real life lessons at SignalFxGo debugging and troubleshooting tips - from real life lessons at SignalFx
Go debugging and troubleshooting tips - from real life lessons at SignalFx
 
Javascript Everywhere
Javascript EverywhereJavascript Everywhere
Javascript Everywhere
 
Building High Performance Android Applications in Java and C++
Building High Performance Android Applications in Java and C++Building High Performance Android Applications in Java and C++
Building High Performance Android Applications in Java and C++
 
Catch a spider monkey
Catch a spider monkeyCatch a spider monkey
Catch a spider monkey
 
Python在豆瓣的应用
Python在豆瓣的应用Python在豆瓣的应用
Python在豆瓣的应用
 
支撐英雄聯盟戰績網的那條巨蟒
支撐英雄聯盟戰績網的那條巨蟒支撐英雄聯盟戰績網的那條巨蟒
支撐英雄聯盟戰績網的那條巨蟒
 
Continuous delivery w projekcie open source - Marcin Stachniuk
Continuous delivery w projekcie open source - Marcin StachniukContinuous delivery w projekcie open source - Marcin Stachniuk
Continuous delivery w projekcie open source - Marcin Stachniuk
 
Swift Install Workshop - OpenStack Conference Spring 2012
Swift Install Workshop - OpenStack Conference Spring 2012Swift Install Workshop - OpenStack Conference Spring 2012
Swift Install Workshop - OpenStack Conference Spring 2012
 
Intravert Server side processing for Cassandra
Intravert Server side processing for CassandraIntravert Server side processing for Cassandra
Intravert Server side processing for Cassandra
 
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
 
Scrapy workshop
Scrapy workshopScrapy workshop
Scrapy workshop
 
“warpdrive”, making Python web application deployment magically easy.
“warpdrive”, making Python web application deployment magically easy.“warpdrive”, making Python web application deployment magically easy.
“warpdrive”, making Python web application deployment magically easy.
 
Tips and tricks for building high performance android apps using native code
Tips and tricks for building high performance android apps using native codeTips and tricks for building high performance android apps using native code
Tips and tricks for building high performance android apps using native code
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)
 
Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM Mechanics
 
node.js - Eventful JavaScript on the Server
node.js - Eventful JavaScript on the Servernode.js - Eventful JavaScript on the Server
node.js - Eventful JavaScript on the Server
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?
 
Get your teeth into Plack
Get your teeth into PlackGet your teeth into Plack
Get your teeth into Plack
 

More from Leo Zhou

1.4 go在数据存储上面的应用—毛剑
1.4 go在数据存储上面的应用—毛剑1.4 go在数据存储上面的应用—毛剑
1.4 go在数据存储上面的应用—毛剑
Leo Zhou
 
1.2 刘奇 go在分布式数据库中的应用
1.2 刘奇 go在分布式数据库中的应用1.2 刘奇 go在分布式数据库中的应用
1.2 刘奇 go在分布式数据库中的应用
Leo Zhou
 
Protocol libraries the right way
Protocol libraries the right wayProtocol libraries the right way
Protocol libraries the right way
Leo Zhou
 
特卖场景下的大数据平台和机器学习实践
特卖场景下的大数据平台和机器学习实践特卖场景下的大数据平台和机器学习实践
特卖场景下的大数据平台和机器学习实践
Leo Zhou
 
The net is dark and full of terrors - James Bennett
The net is dark and full of terrors - James BennettThe net is dark and full of terrors - James Bennett
The net is dark and full of terrors - James Bennett
Leo Zhou
 

More from Leo Zhou (20)

第三名 3rd zhyict
第三名 3rd zhyict第三名 3rd zhyict
第三名 3rd zhyict
 
异常检测在苏宁的实践
异常检测在苏宁的实践异常检测在苏宁的实践
异常检测在苏宁的实践
 
第二名 2nd 火眼金睛
第二名 2nd 火眼金睛第二名 2nd 火眼金睛
第二名 2nd 火眼金睛
 
第四名 4th H3C AI Institute
第四名 4th H3C AI Institute第四名 4th H3C AI Institute
第四名 4th H3C AI Institute
 
第一名 1st Bocoiops
第一名 1st Bocoiops第一名 1st Bocoiops
第一名 1st Bocoiops
 
第六名 6th Aurora
第六名 6th Aurora第六名 6th Aurora
第六名 6th Aurora
 
AI使能网络自动驾驶 AI Building Autonomous Driving Network
AI使能网络自动驾驶 AI Building Autonomous Driving NetworkAI使能网络自动驾驶 AI Building Autonomous Driving Network
AI使能网络自动驾驶 AI Building Autonomous Driving Network
 
2.2 go在阿里云cdn系统的应用
2.2 go在阿里云cdn系统的应用2.2 go在阿里云cdn系统的应用
2.2 go在阿里云cdn系统的应用
 
1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb
 
1.4 go在数据存储上面的应用—毛剑
1.4 go在数据存储上面的应用—毛剑1.4 go在数据存储上面的应用—毛剑
1.4 go在数据存储上面的应用—毛剑
 
1.2 刘奇 go在分布式数据库中的应用
1.2 刘奇 go在分布式数据库中的应用1.2 刘奇 go在分布式数据库中的应用
1.2 刘奇 go在分布式数据库中的应用
 
Protocol libraries the right way
Protocol libraries the right wayProtocol libraries the right way
Protocol libraries the right way
 
美团数据库运维平台介绍
美团数据库运维平台介绍美团数据库运维平台介绍
美团数据库运维平台介绍
 
特卖场景下的大数据平台和机器学习实践
特卖场景下的大数据平台和机器学习实践特卖场景下的大数据平台和机器学习实践
特卖场景下的大数据平台和机器学习实践
 
我的互联网运维理论与实践
我的互联网运维理论与实践我的互联网运维理论与实践
我的互联网运维理论与实践
 
如何选择 Docker 监控方案
如何选择 Docker 监控方案如何选择 Docker 监控方案
如何选择 Docker 监控方案
 
美团数据库运维平台介绍
美团数据库运维平台介绍美团数据库运维平台介绍
美团数据库运维平台介绍
 
The net is dark and full of terrors - James Bennett
The net is dark and full of terrors - James BennettThe net is dark and full of terrors - James Bennett
The net is dark and full of terrors - James Bennett
 
Hypothesis randomised testing for django
Hypothesis randomised testing for djangoHypothesis randomised testing for django
Hypothesis randomised testing for django
 
NoSQL@VIP — 唯品会NoSQL平台⾃动化发展及运维经验分享
NoSQL@VIP — 唯品会NoSQL平台⾃动化发展及运维经验分享NoSQL@VIP — 唯品会NoSQL平台⾃动化发展及运维经验分享
NoSQL@VIP — 唯品会NoSQL平台⾃动化发展及运维经验分享
 

Recently uploaded

Recently uploaded (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

Dive into sentry

  • 1. Dive into Sentry The modern error logging and aggregation platform XTao 09.19.2015 Beijing
  • 2. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! 徐涛 ● @ 豆瓣 ● (?:产品开发|运维)工程师 ● (?:CODE|DevOps|Git|Python) ● 2014 PyConChina Beijing ● https://blog.xtao.me ❏ Douban: @xtaooooo ❏ Twitter: @xtao ❏ Github: @xtao
  • 3. Sentry 概述 Sentry 毕业于 Disqus https://engineering.disqus.com/ Sentry 历史 Sentry 是什么 DEMO
  • 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.
  • 10. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! 为什么要用 Sentry ● 详细的错误息 ○ 某一行代码 (Python) ○ 某一个变量 (Python) ● 详细错误分类 ○ Tag ● 提醒 ● 合理的重复错误处理 ● 支持多种语言 ○ 对 Python 支持好 ❏ 额外的收获 ❏ 入门 ❏ 一个很好的 Django 项目,如果你要 学习如何使用 Django 的话,可以读 一下 Sentry 的源码 ❏ 进阶 ❏ Sentry 应该算是一个中型 Web 项目 了,如果你缺少 Web 项目开发经 验,也可以从源码中获取一些经验 ❏ 开源 ❏ 一个 Python 开源 Web 应用的示 例,数据迁移还是靠谱的
  • 11. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! Sentry - 服务端(7.x) ● Backend ○ Python ○ Django ○ Celery ● Frontend ○ JQuery ○ Backbone ○ Underscore ○ Bootstrap ○ Moment ● Database ○ MySQL ○ PostgreSQL ● KV ○ Cassandra ○ Riak ○ Redis ● Queue ○ Redis ○ RabbitMQ
  • 12. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! Raven - 官方支持的 Client ● Python ● JavaScript ● Node.js ● PHP ● Ruby ● Objective-C ● Java ● C# ● Go
  • 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
  • 15. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! Raven 101 pip install raven --upgrade from raven import Client client = Client('___DSN___') try: 1 / 0 except ZeroDivisionError: client.captureException() def handle_request(request): client.context.merge({'user': { 'email': request.user.email }}) try: ... finally: client.context.clear()
  • 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()) ```
  • 17. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! DSN 101 '{PROTOCOL}://{PUBLIC_KEY}:{SECRET_KEY}@{HOST}/{PATH}{PROJECT_ID}' http://c44a73655e50454581da995bbedd392a: 8d29447e0e8241b9a178fd726fb07190@onimaru.intra.douban.com/10 udp://c44a73655e50454581da995bbedd392a: 8d29447e0e8241b9a178fd726fb07190@onimaru-udp.intra.douban.com: 4008/10
  • 19. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! Event ● HTTP(DATA) ● UDP(DATA) ● EventManager ● Project ● Event ● Group ● EventMapping ○ event_id: uuid.uuid4(). hex ● UserReport ○ 用户反馈 Sentry 问题 ● post_process_group.delay ● index_event.delay
  • 20. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! Group ● hashes ○ checksum (provided by client) ○ fingerprint / (default + fingerprint) ○ default (first interface ordered by score) ● find group ○ find group at GroupHash by hash ○ first matched group ● sample event (count, time) ● regression (resolved event)
  • 21. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! Protocol ● CLIENT_RESERVED_ATTRS = ( ● 'project', ● 'event_id', ● 'message', ● 'checksum', ● 'culprit', ● 'fingerprint', ● 'level', ● 'time_spent', ● 'logger', { "event_id": "fc6d8c0c43fc4630ad850ee518f1b9d0", "culprit": "my.module.function_name", "timestamp": "2011-05-02T17:41:36", "message": "SyntaxError: Wattttt!" "sentry.interfaces.Exception": { "type": "SyntaxError": "value": "Wattttt!", "module": "__builtins__" } } ● 'server_name', ● 'site', ● 'timestamp', ● 'extra', ● 'modules', ● 'tags', ● 'platform', ● 'release', ● )
  • 22. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! UDP Protocol "AUTHnnDATA" ● AUTH ○ "Sentry key=value, key=value, …" ● DATA ○ json string ○ zlib ○ base64
  • 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 ● ...
  • 25. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! Interface - Exception ● 标准的 Python 异常 ● type, value, module ● stacktrace == sentry.interfaces. Stacktrace >>> { >>> "type": "ValueError", >>> "value": "My exception value", >>> "module": "__builtins__" >>> "stacktrace": { >>> # see sentry.interfaces.Stacktrace >>> } >>> }
  • 26. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! Interface - Message ● message (<= 1000) ● params >>> { >>> "message": "My raw message with interpreted strings like %s", >>> "params": ["this"] >>> }
  • 27. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! Interface - HTTP ● 常用的 HTTP 参数 >>> { >>> "url": "http://absolute.uri/foo", >>> "method": "POST", >>> "data": { >>> "foo": "bar" >>> }, >>> "query_string": "hello=world", >>> "cookies": "foo=bar", >>> "headers": { >>> "Content-Type": "text/html" >>> }, >>> "env": { >>> "REMOTE_ADDR": "192.168.0.1" >>> } >>> }
  • 28. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! Interface - Query ● 用于记录 SQL >>> { >>> "query": "SELECT 1" >>> "engine": "psycopg2" >>> }
  • 29. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! Interface - Template ● A rendered template (generally used like a single frame in a stacktrace). ● The attributes ``filename``, ``context_line``, and ``lineno`` are required. >>> { >>> "abs_path": "/real/file/name.html" >>> "filename": "file/name.html", >>> "pre_context": [ >>> "line1", >>> "line2" >>> ], >>> "context_line": "line3", >>> "lineno": 3, >>> "post_context": [ >>> "line4", >>> "line5" >>> ], >>> }
  • 30. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! Interface - User ● 定义一个用户 >>> { >>> "id": "unique_id", >>> "username": "my_user", >>> "email": "foo@example.com" >>> "ip_address": "127.0.0.1", >>> "optional": "value" >>> }
  • 31. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! Interface - Stacktrace ● Python Frame >>> { >>> "frames": [{ >>> "abs_path": "/real/file/name.py" >>> "filename": "file/name.py", >>> "function": "myfunction", >>> "vars": { >>> "key": "value" >>> }, >>> "pre_context": [ >>> "line1", >>> "line2" >>> ], >>> "context_line": "line3", >>> "lineno": 3, >>> "in_app": true, >>> "post_context": [ >>> "line4", >>> "line5" >>> ], >>> }], >>> "frames_omitted": [13, 56] >>> }
  • 32. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! TSDB - 时序数据库 ● Dummy (none) ● InMemory (defaultdict) ● Redis (hashes) Redis: { "TSDBModel:epoch:shard": { "Key": Count } } # rollups must be ordered from highest granularity to lowest SENTRY_TSDB_ROLLUPS = ( # (time in seconds, samples to keep) (10, 360), # 60 minutes at 10 seconds (3600, 24 * 7), # 7 days at 1 hour (3600 * 24, 60), # 60 days at 1 day )
  • 33. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! NodeStore - KV 数据库 ● riak ● cassandra ● django (node table) ● 用于和数据一起存储一些特殊信息(比如不 适合存在数据库里的大文本等) ● validate ● create ● delete ● delete_multi ● get ● get_multi ● set ● set_multi ● generate_id ● cleanup
  • 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
  • 38. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! Buffer Internal ● 生产者 ● incr ● ● 'b:k:%s:%s' (hashmap, key_expire = 60 * 60 # 1 hour) ○ 'm' ○ 'f' ○ 'l+%s' ○ 'e+%s' ● 'b:p' (Sorted sets) ● 消费者 ● process pending ● process 'flush-buffers': { 'task': 'sentry.tasks.process_buffer.process_pending', 'schedule': timedelta(seconds=10), 'options': { 'expires': 10, 'queue': 'counters-0', } },
  • 39. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! Membership Roles ● Member *:read ● Admin *:write ● Owner *:delete Scoping has access to all teams ● 跟 GitHub 类似的组织结构以及权限控制 ● Organization - Owner, Admin, Member ● Team - (Role, Project) ● Project
  • 40. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! Sensitive Data ● 'password', ● 'secret', ● 'passwd', ● 'authorization', ● 'api_key', ● 'apikey', ● 'access_token', ● DEFAULT_SCRUBBED_FIELDS
  • 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
  • 43. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! Rollups & Sampling ● Rollups ○ Raven.captureException(ex, {fingerprint: ['my', 'custom', 'fingerprint']}) ○ Raven.captureException(ex, {fingerprint: ['{{ default }}', 'other', 'data']}) ● Sampling ○ Count ○ Time
  • 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
  • 46. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! PostgreSQL & Gevent ● psycopg2 ● src/sentry/utils/gevent.py ● Sentry 官方使用的应该是这个数据库,有非阻塞的 patch,支持异步
  • 49. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! Monitor
  • 50. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! 豆瓣 ● 应用 ○ Python (大部分) ○ Javascript (前端) ○ Go (少部分) ○ C++/C/Java (少量) ● 错误 ○ devtools (DIY, 已废弃) ○ Sentry
  • 51. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! 问题 ● 已经部署了一套 Sentry ● 5.x 使用 UDP 协议 ● 测试以及线上,有丢错误情况 ● 且比较明显 ● 但是这时还没有针对 Sentry 的监控 ● 开始研究黑盒 ● UDP Worker CPU 使用率比较高 ● UDP 是用 DNS 做负载均衡 ● DNS 因为 cache 问题,导致负载不平衡 ● 使用 Random 改善了 cache 带来的隐患 ● 查看 Worker 代码 ● Gevent / Eventlet 使用错误,没有 Monkey Patch ● 5.x 数据库压力较大,需要做合并写
  • 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 原因)
  • 53. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! Insert Queue ● insert_data_to_database - cache ● preprocess_event - queue ● save_event - queue ● ● insert_data_to_database_sync - queue
  • 54. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! 部署情况 ● HTTP x 4 (默认 Sentry 是用 Gunicorn 管理 Worker 的) ● UDP x 4 (开启了 Gevent,收到包后,扔到队列) ● Celery x 4 (Task consumer, 默认是开启 CPU_NUM 个 Worker) ● Celery Beat x 1 ● Cron:cleanup 21 (只保留 21 天的数据) ● HTTP 前面用 LVS + Nginx 做负载均衡 ● UDP 用 DNS 做负载均衡
  • 55. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! 内部配置 ● LDAP ○ 我们用的用户帐号系统 ○ 配置一下 Sentry 即可 ● MAIL ○ 配置 Sentry 邮件服务器 ● IRC ○ sentry-irc ○ 因为我们使用了 ircbot,稍微改了一下这个插件代码
  • 56. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! Why UDP ● 快 ● 应用不需要关心 Sentry 服务是否正常 ● 即使 Sentry 出问题,也不影响应用 ● 可以观察系统 UDP 丢包情况,判断 UDP 服务是否正常
  • 57. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! Celery ● 芹菜 ● 还没有吃透
  • 58. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! DBA ● Redis ○ Memory ○ QPS ○ CPU ○ Queue Size ● MySQL ○ QPS ■ update ■ insert ■ delete ■ select ○ thread
  • 59. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! Sentry ● Statsd ○ celery worker cpu ○ udp worker cpu ○ http worker cpu ● App 内统计 ○ task 执行时间 ○ task 执行数量
  • 60. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! UDP Received Packet (Sentry) ● udp worker ● 收包后记录 ● d = sock.recvfrom(self.BUF_SIZE) ● statsd.increment(STATSD_KEY_RECV)
  • 61. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! UDP Received Packet (Kernel) ● UDP Server 收到的包数 (by diamond) ● ~ $ sudo /sbin/iptables -t filter -I INPUT -i lan -p udp --dport 4008 -j ACCEPT ● ~ $ sudo /sbin/iptables -L INPUT 1 -nvx ● 52308183 414772916064 ACCEPT udp -- lan * 0.0.0.0/0 0.0.0.0/0 udp dpt:4008 ● pkts (UDP 完整包数,底层已经处理了分包问题) ● bts
  • 62. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! UDP Dropped Packets (Kernel) ● cat /proc/net/udp ● sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode ref pointer drops ● 41: 00000000:80CE 00000000:0000 07 00000000:00000000 00:00000000 00000000 6561 0 4110825944 2 ffff8809c23e5e40 0 ● cat /proc/net/snmp ● Udp: InDatagrams NoPorts InErrors OutDatagrams RcvbufErrors SndbufErrors ● Udp: 5416706536 993028 290598311 22725578190 4662160 1318 ● UdpLite: InDatagrams NoPorts InErrors OutDatagrams RcvbufErrors SndbufErrors ● UdpLite: 0 0 0 0 0 0
  • 63. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! TIPS ● Webhooks: ○ 默认禁止访问内网 IP, 需要更改一下配置 ● Timezone ○ SENTRY_DEFAULT_TIME_ZONE = 'Asia/Shanghai' 设置用户默认时区 ● Public ○ SENTRY_PUBLIC = False 这个权限有点问题,不要开启 ● Register ○ SENTRY_FEATURES['auth:register'] = False 禁止自己注册
  • 64. 北京/上海/广州 0xFF Life's pathetic, go Pythonic! 下一步计划 ● 项目错误统计(QPS,Sentry 提供的图还不能满足需求) ● Profile 工具,有助于分析 Worker 瓶颈 (Celery) ● 应对雪崩式错误的处理方案(压测 Sentry) ● 尝试一下 MySQL + Redis + Gevent
  • 65. Jobs ● 2016 校招 ● always 社招 ● TO: ruby@douban.com ● 当然 python 也可以 ● TO: python@douban.com ● 如果你想试试 js 也可以尝试 ● TO: js@douban.com ● 详情: http://jobs.douban.com
  • 66. 北京/上海/广州 0xFF Life's pathetic, go Pythonic!