Sentry 照着官网搭建好之后,想要看到效果,须要业务接入。盘了一下手里项目,决定以X项目为切入点开刀。本想按照 官方API 接入便可,谁料道路之曲折有点出乎想象。
javascript
本文记录实战过程当中的思路,以及遇到的实际问题,拿出来跟你们分享。html
以上两张图描述的是sentry工做原理以及云上部署方案。前端
Docker的确能够实现快速搭建sentry服务,可是忽略一个大前提,这一切都是在一台台机器部署一个sentry!vue
DSN 是sentry 的一个重要概念,能够理解是服务准入的标记java
A value which we call a DSN ... it’s actually just a representation of the configuration required by the Sentry SDKsreact
AUTH TOKEN 是sentry的另外一个重要概念,能够理解是```sentry-cli``命令行调用的钥匙。webpack
考虑到上面的顾虑,申请了两台机器,但随之问题就来了。nginx
onpremise
目录,不一样目录中启动service,达到单台机器多个实例的效果。
从官网提供的sentry.io服务来看,只有一个,DSN 和 一个AUTH TOKEN ,因此推测应该还有别的方案。调研中...web
若是有相同经历的朋友,必定留言指导一下啊docker
<script src="https://cdn.ravenjs.com/3.26.4/raven.min.js" crossorigin="anonymous"></script>
<script>Raven.config('https://3042a92815a94e15ae949b717464c470@sentry.io/1401863').install();</script>
复制代码
# 固然也能够CDN方式接入,具体可参见官方文档
import Vue from 'vue';
import Raven from 'raven-js';
import RavenVue from 'raven-js/plugins/vue';
Raven
.config('https://9128da56fafa4fd4bb7d3e38e3577395@sentry.io/sentry//1')
.addPlugin(RavenVue, Vue)
.install();
复制代码
react
和 san
项目都是控制台直接报错,可采用以前设定的技术方案。sentry-webpack-plugin
便可完成(只是能够上传单个机器,须要一个AUTH TOKEN , 多个机器还未解决)<html>
<head>
<title>TEST Page</title>
<script src="https://cdn.ravenjs.com/3.26.4/raven.min.js" crossorigin="anonymous"></script>
<script>Raven.config('https://3042a92815a94e15ae949b717464c470@sentry.io/1401863').install();</script>
</head>
...
</html>
复制代码
compiler.hooks.compilation.tap
报错:Cannot read property 'compilation' of undefined
// 页面插入元素插件
class HTMLinsertPlugin {
constructor(options) {
this.options = options.scripts;
}
apply(compiler) {
compiler.hooks.compilation.tap('HTMLinsertPlugin', compilation => {
// Hook into `htmlWebpackPluginAlterAssetTags`
// !! Careful this will change in the upcoming html webpack plugin version !!
compilation.hooks.htmlWebpackPluginAlterAssetTags.tapAsync('HTMLinsertPlugin',
// You can use either `head` or `body` and either `push` or `unshift`:
(htmlPluginData, callback) => {
this.options.forEach(ele => {
htmlPluginData.head.push(ele);
});
// htmlPluginData.head.push();
callback(null, htmlPluginData);
}
);
});
}
}
复制代码
new HtmlWebpackPlugin({
...
sentryCDN: 'https://cdn.ravenjs.com/3.26.4/raven.min.js',
sentryScript:'Raven.config('https://3042a92815a94e15ae949b717464c470@sentry.io/1401863').install();'
})
复制代码
<script type="text/javascript" src="<%= htmlWebpackPlugin.options.sentryCDN %>"></script>
<script type="text/javascript">
<%= htmlWebpackPlugin.options.sentryScript %>
</script>
复制代码
就在欢呼官方提供的sentry-webpack-plugin
强大的时候,再次遇到了问题。公司流程提交代码后,会指定公机器进行编译,而这台机器是没法访问外网的,致使编译后上传sentry服务的时候失败。好在找到一台能够访问外网的机器进行编译。
域名须要经过nginx proxy_pass
到本机
Root URL. sentry建立好以后有一件事是设置root_url,这个将会影响DSN
https://sentry.io/sentry
https://9128da56fafa412312312338e3577395@sentry.io/sentry/1
,https://sentry.io/sentry/api/1/store/?sentry_version=7
.sentryclirc
https://sentry.io
因而
# /sentry 上报接口
location ^~ /sentry/ {
proxy_pass http://localhost:9000/;
}
# 非 /sentry uri 正常访问
location / {
proxy_pass http://localhost:9000;
}
复制代码
Sentry虽然已经开源,可是X项目接入过程当中仍是遇到了不少问题,但愿你们能够交流,互相避免踩坑。让咱们的页面在线上更加稳定