1.系统环境
腾讯云centos7 64
2.安装docker
curl -fsSL https://get.docker.com/ | sh
3.安装docker-compose
sudo curl -L https://github.com/docker/compose/releases/download/1.22.0-rc2/docker-compose-Linux-x86_64 > /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
4.根据官方推荐方法安装sentry
git clone https://github.com/getsentry/onpremise.git
cd onpremise
mkdir -p data/{sentry,postgres} - Make our local database and sentry config directories. This directory is bind-mounted with postgres so you don't lose state!
docker-compose build - Build and tag the Docker services
docker-compose run --rm web config generate-secret-key - Generate a secret key. Add it to docker-compose.yml in base as SENTRY_SECRET_KEY.
docker-compose run --rm web upgrade - Build the database. Use the interactive prompts to create a user account.
docker-compose up -d - Lift all services (detached/background mode).
Access your instance at localhost:9000!
上面主要是通过创建一个network并且把sentry所需要的一些服务全部集中到这个network中,并且初始化到数据库等等工作...
ps:注意 2g内存一下机器在migration中肯定会失败。测试至少4g的机子才能跑起来。建议将有个搭建完成的sentry 进入postgres的容器内导出postgres的数据库再导入到2g的机器中,这样子就可以完成安装。。。过程也比较艰辛。。期间尝试过改写migration命令 限制内存使用等方法均失败。。。
5.sentry创建监控项目
sentry9.0的界面还是非常不错,功能也很强大。
6.小程序端引入上报sdk
sentry的官方是没有任何关于小程序的前端sdk
本想自己造个简单的轮子。google一波发现原来有赞已经根据JavaScript版本的sdk改出来了小程序的版本。
在onlauch中
onerror中拦截未catch到的错误
7.封装在本地请求动作中
return new Promise((resolve, reject) => {
let data = obj.data
let jwtToken=wx.getStorageSync("jwtToken")
let object = {
success: res => {
if(res.statusCode===200){
//此处封装检查代码
if(res.data.status_code!=200){
reject(res.data)
}else{
resolve(res.data)
}
}else{
Raven.captureMessage(JSON.stringify(res), {
level: 'warning'
});
reject(res)
}
},
fail: res => {
reject(res)
Raven.captureMessage(JSON.stringify(res), {
level: 'error'
});
},
method: 'POST',
header:{
"content-type":"application/json",
"Authorization":"Bearer "+jwtToken
},
data: Object.assign({}, obj.data),
}
wx.request(Object.assign({}, obj,object))
})
}
ps:当然还可以通过根据小程序的特性使用getCurrentPages().getApp().global等发送用户报错时的一些信息。更方便复现错误。
更多上报方式 包括增添用户信息方式详见