在哨兵文档中,thera是使用说明来将哨兵与Angular2 CLI集成,但是缺少将哨兵与阿格里拉2-webpack-先发集成的指令。如何做好呢?
发布于 2017-03-18 17:36:06
我给出了来自2017年3月8日[55d4325]的最新版本的angular2-webpack-初学者的答案。在此解决方案中,仅在产品构建(normal和AoT)中启用Sentry,它还将在控制台中抛出异常(但不像开发生成那样抛出“完全功能”异常)。指示:
首先转到项目目录,然后在控制台中运行:
npm install raven-js --save第二,创建文件:./src/app/app.sentry.ts
import * as Raven from 'raven-js'; // http://sentry.io
import { ErrorHandler } from '@angular/core';
// below 'if' is needed to activate sentry ONLY in production mode.
// (without this, import statement in environment.ts initialize sentry in dev)
if ('production' === ENV)
{
Raven // Sentry configuration http://sentry.io
.config('https://xxxxxxxxxxxxxxxxxxxxxxxxxx@sentry.io/yyyyyy')
.install(); // where xxx..xxx= your sentry key, yyyy= sentry project id
}
export class RavenErrorHandler implements ErrorHandler {
public handleError(err: any): void {
Raven.captureException(err.originalError);
console.error(err); // show err in browser console for production build
}
}
export const SENTRY_PROVIDER = { provide: ErrorHandler, useClass: RavenErrorHandler };最后一步:编辑文件./src/app/environment.ts并添加2行代码--这是我们在上面创建的带有导入文件的顶层行。
import * as Sentry from './app.sentry';
... 以及if ('production'==ENV)语句中文件的上middel部分中的一行:
...
let _decorateModuleRef = <T>(value: T): T => { return value; };
if ('production' === ENV) {
enableProdMode();
PROVIDERS.push(Sentry.SENTRY_PROVIDER); // !!!-> SENTRY NEW SECOND CODE LINE
// Production
_decorateModuleRef = (modRef: any) => {
disableDebugTools();
return modRef;
};
PROVIDERS = [
...PROVIDERS,
// custom providers in production
];
}
...仅此而已:)
我还在哨兵集线器中发布了这个解决方案,但我不确定它们是否包含在哨兵文档中。
https://stackoverflow.com/questions/42877653
复制相似问题