我们有一个集成了Sentry的Node.js项目,最近我们决定增加对源地图的支持。我们已经发布了功能正常工作,并且使用正确的代码行将异常报告给Sentry,但是没有例外代码摘录。
我们使用哨兵webpack插件(https://www.npmjs.com/package/@sentry/webpack-plugin),其配置如下:
new SentryWebpackPlugin({
release: process.env.SENTRY_RELEASE,
include: './build',
ignore: ['node_modules', 'webpack.config.js'],
setCommits: {
repo: 'ORG/REPO_NAME',
auto: true
},
configFile: 'sentryconfig.properties'
})
并使用以下代码初始化Sentry:
import * as Sentry from '@sentry/node';
import { RewriteFrames, Dedupe, Transaction } from '@sentry/integrations';
import config from '../config';
Sentry.init({
dsn: config.sentry.dsn,
release: process.env.SENTRY_RELEASE,
environment: config.environment,
integrations: [
...Sentry.defaultIntegrations,
new RewriteFrames({ root: __dirname }),
new Dedupe(),
new Transaction()
],
maxBreadcrumbs: 50,
attachStacktrace: true
});
然后以这种方式抛出测试错误:
server.use(Sentry.Handlers.requestHandler());
server.get('/generate/error', () => {
throw Error('server test error for sentry');
});
server.use(Sentry.Handlers.errorHandler());
此设置有什么问题?是否可以在Sentry中发生错误的地方显示代码?