sentry 是一个方便的错误异常追踪系统,同时社区也提供了openresty 的lua 包,使用docker-compose 进行测试

备注: sentry 部分的配置来自官方文档

环境准备

  • docker-compose 文件
# NOTE: This docker-compose.yml is meant to be just an example of how
# you could accomplish this on your own. It is not intended to work in
# all use-cases and must be adapted to fit your needs. This is merely
# a guideline. # See docs.getsentry.com/on-premise/server/ for full
# instructions version: '3.4' x-defaults: &defaults
restart: unless-stopped
build: .
depends_on:
- redis
- postgres
- memcached
- smtp
env_file: .env
environment:
SENTRY_MEMCACHED_HOST: memcached
SENTRY_REDIS_HOST: redis
SENTRY_POSTGRES_HOST: postgres
SENTRY_EMAIL_HOST: smtp
volumes:
- sentry-data:/var/lib/sentry/files services:
smtp:
restart: unless-stopped
image: tianon/exim4 memcached:
restart: unless-stopped
image: memcached:1.5-alpine redis:
restart: unless-stopped
image: redis:3.2-alpine postgres:
restart: unless-stopped
image: postgres:9.5
ports:
- "5432:5432"
volumes:
- sentry-postgres:/var/lib/postgresql/data web:
<<: *defaults
ports:
- '9000:9000'
openresty:
build:
context: ./
dockerfile: ./Dockerfile-nginx
ports:
- "8080:80"
volumes:
- "./nginx_lua/:/opt/app/"
- "./nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf"
cron:
<<: *defaults
command: run cron worker:
<<: *defaults
command: run worker volumes:
sentry-data:
external: true
sentry-postgres:
external: true
  • openresty 配置
    nginx.conf
worker_processes 1;
user root;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
lua_code_cache off;
lua_need_request_body on;
gzip on;
resolver 127.0.0.11 ipv6=off;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
lua_package_path '/opt/app/?.lua;;';
server {
listen 80;
server_name localhost;
charset utf-8;
default_type text/html;
location / {
default_type text/plain;
content_by_lua_block {
require("sentry/init")()
}
}
location = /favicon.ico {
root /opt/app/static;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
} }
}

dockerfile 配置
主要是添加了raven 包

FROM openresty/openresty:alpine-fat
LABEL author="1141591465@qq.com"
RUN /usr/local/openresty/luajit/bin/luarocks install resty-raven
EXPOSE 80

调用代码

主要来自github 文档,同时这个是一个简单的测试,注意lua 包的问题,当前测试支持的只是旧版本的dsn 方式
新版本的运行有问题
nginx_lua/sentry/init.lua

local raven = require "raven"

function init()
-- http://pub:secret@127.0.0.1:8080/sentry/proj-id
local rvn = raven:new("http://092b2e429b4c480e83c2e7f18890b8f2:e41f2a264e5e47329d0026e99ae825b1@web:9000/2", {
tags = { foo = "bar" },
}) -- Send a message to sentry
local id, err = rvn:captureMessage(
"Sentry is a realtime event logging and aggregation platform.",
{ tags = { abc = "def" } } -- optional
)
if not id then
print(err)
end -- Send an exception to sentry
local exception = {{
["type"]= "SyntaxError",
["value"]= "Wattttt!",
["module"]= "__builtins__"
}}
local id, err = rvn:captureException(
exception,
{ tags = { abc = "def" } } -- optional
)
if not id then
print(err)
end -- Catch an exception and send it to sentry
function bad_func(n)
return not_defined_func(n)
end -- variable 'ok' should be false, and an exception will be sent to sentry
local ok = rvn:call(bad_func, 1)
end return init

环境启动

主要是sentry的启动,因为sentry 启动稍有点费事,依赖数据库以及key 的生成,基本流程如下:

  • sentry 启动
    来自官方文档,就懒得翻译了
  1. docker volume create --name=sentry-data && docker volume create --name=sentry-postgres - Make our local database and sentry volumes
    Docker volumes have to be created manually, as they are declared as external to be more durable.
  2. cp -n .env.example .env - create env config file
  3. docker-compose build - Build and tag the Docker services
  4. docker-compose run --rm web config generate-secret-key - Generate a secret key.
    Add it to .env as SENTRY_SECRET_KEY.
  5. docker-compose run --rm web upgrade - Build the database.
    Use the interactive prompts to create a user account.
  6. docker-compose up -d - Lift all services (detached/background mode).
  7. Access your instance at localhost:9000!
  • openresty 启动
    在启动sentry 的时候openresty 对应的镜像以及以及依赖的raven 已经同时处理了,基本可以不用管了

测试效果

打开http://localhsot:8080 即可

  • sentry 日志效果

说明

当前lua raven 支持的dsn 版本有点老,新版本的有问题,但是总的来说还是很不错的,在实际openresty 项目的开发中,可以作为一个
可选的问题分析方案,同时sentry 的功能还是很强大的,我们可以继承git 以及问题管理系统

参考资料

https://github.com/rongfengliang/openresty-sentry-docker-compose
https://github.com/UseFedora/raven-lua
https://github.com/getsentry/onpremise

 
 
 
 

openresty 集成 sentry 异常系统的更多相关文章

  1. .net core 集成 sentry 进行异常报警

    .net core 集成 sentry 进行异常报警 Intro Sentry 是一个实时事件日志记录和汇集的平台.其专注于错误监控以及提取一切事后处理所需信息而不依赖于麻烦的用户反馈.它分为客户端和 ...

  2. hive集成sentry

    1.安装配置sentry 详细步骤见上一篇安装配置sentry 2.配置hive 2.1 Hive-server2集成Sentry 在 /etc/hive/conf/hive-site.xml中添加: ...

  3. 【flask】项目集成Sentry收集线上错误日志

    flask集成sentry分为4个步骤: 首先在sentry官网注册1个账号 然后创建1个新的项目,这里我选择的是flask,这会得到一些关于sdk的使用说明 接下来创建一个简单的flask项目使用s ...

  4. 11月23日《奥威Power-BI报表集成到其他系统》腾讯课堂开课啦

    听说明天全国各地区都要冷到爆了,要是天气冷到可以放假就好了.想象一下大冷天的一定要在被窝里度过才对嘛,索性明天晚上来个相约吧,相约在被窝里看奥威Power-BI公开课如何?        上周奥威公开 ...

  5. 支付宝sdk集成,报系统繁忙 请稍后再试(ALI64)

    移动快捷支付,往往需要集成支付宝的sdk,集成的过程相对简单,只要按照支付宝的文档,进行操作一般不会出问题.            下面主要说明一下,集成sdk后报"系统繁忙 请稍后再试(A ...

  6. CloudStack 4.2 新功能:集成SNMP进行系统监控(原理篇)

    作者微博:http://weibo.com/tianchunfeng CloudStack 4.2 版本发布在即,相信不久后对 4.2 版本新功能(共有13个)的介绍会逐渐多起来.因为无论是从架构底层 ...

  7. FineReport集成到AWS系统中的方案

    本人实施了北京炎黄盈动的BPM及OA系统,主要目标是对业务流程进行控制和管理,加快Oracle JDE的业务前端录单速度和弥补JDE在流程控制方面的不足,实现BPM数据能与JDE无缝互相结合,经过3个 ...

  8. hive集成sentry的sql使用语法

    Sentry权限控制通过Beeline(Hiveserver2 SQL 命令行接口)输入Grant 和 Revoke语句来配置.语法跟现在的一些主流的关系数据库很相似.需要注意的是:当sentry服务 ...

  9. impala集成sentry

    1.安装配置sentry 详细步骤见上一篇安装配置sentry. 2.配置impala 注:以下配置未集成kerberos安全认证 在/etc/imapla/conf目录下创建sentry-site. ...

随机推荐

  1. 数据库编程测试机试 QQ

    创建QQ数据库 #创建数据库 CREATE DATABASE QQ #创建表名 并且添加列 DROP TABLE IF EXISTS `dbo.BaseInfo`; CREATE TABLE `stu ...

  2. ORM版学员管理系统1

    ORM版学员管理系统 班级表 表结构 class Class(models.Model): id = models.AutoField(primary_key=True) # 主键 cname = m ...

  3. (C/C++学习笔记) 七. 类型转换

    七. 类型转换 ● 隐式类型转换 隐式类型转换 implicit type conversions #include<iostream> using namespace std; void ...

  4. C++基础知识:异常处理

    1.C++中的异常处理(1)C++ 中提供了 try和catch语句块对可能产生异常的代码进行分开处理  -try语句块处理正常逻辑  -catch语句块处理异常(2)C++ 语言中通过 throw语 ...

  5. 平行四边形 css实现

    首先将 display 设置为  inline-block 或block: 在应用skew(): transform:skewX(-45deg); 但是也会导致平行四边形内的文字倾斜如下 我们可以给文 ...

  6. 7series 逻辑单元理解(更新中)

    7series 逻辑单元理解 ug768和ug799文档介绍了7系列芯片中包含的基本逻辑单元,对其中常用的单元,进行下分析. 1.IOBUF单元 (1)真值表 (2)用途 the  design  e ...

  7. JSP组件Telerik UI for JSP发布R1 2019 SP1|附下载

    Telerik UI for JSP拥有由Kendo UI for jQuery支持的40+ JSP组件,同时通过Kendo UI for jQuery的支持能使用JSP封装包构建现代的HTML5和J ...

  8. UNITY3d在移动设备上的一些优化实战

    项目进入了中期之后,就需要对程序在移动设备上的表现做分析评估和针对性的优化了,首先前期做优化,很多瓶颈没表现出来,能做的东西不多,而且很多指标会凭预想,如果太后期做优化又会太晚,到时发现一些问题改起来 ...

  9. python+appium+yaml安卓UI自动化测试分享

    一.实现数据与代码分离,维护成本较低,先看看自动化结构,大体如下: testyaml管理用例,实现数据与代码分离,一个模块一个文件夹 public 存放公共文件,如读取配置文件.启动appium服务. ...

  10. Oracle数据库三种备份方案

    Oracle数据库有三种标准的备份方法,它们分别是导出/导入(EXP/IMP).热备份和冷备份.导出备件是一种逻辑备份,冷备份和热备份是物理备份. 一. 导出/导入(Export/Import) 利用 ...