我正试图将堆栈驱动程序.错误-js库作为一个模块集成到Vue项目中。
代码和设置:
在package.json中
"stackdriver-errors-js": "^0.2.0"在bootstrap.js中
import errorHandler from './error/error-reporting';错误-报告in
import { StackdriverErrorReporter } from 'stackdriver-errors-js';
let errorHandler;
errorHandler = new StackdriverErrorReporter();
errorHandler.start({
key: "{{.Config.StackDriverApiKey}}",
projectId: "{{.Config.StackDriverProject}}",
service: "{{.Config.GoogleCloudProjectID}}",
version: "{{.Copacknfig.GaeEnv}}",
disabled: false
});
export default errorHandler;实际错误
我现在得到的错误是(控制台输出和测试)。
[vue-devtools] Ready. Detected Vue v2.4.2
(function testErrorReporting() {window.onerror(null, null, null, null, new Error('Test: Something broke!'));})();
stackdriver-errors.js:109 Uncaught ReferenceError: StackTrace is not defined
at StackdriverErrorReporter.webpackJsonp.556.StackdriverErrorReporter.report (stackdriver-errors.js:109)
at window.onerror (stackdriver-errors.js:67)
at testErrorReporting (<anonymous>:1:40)
at <anonymous>:1:111和行(stackdriver-errors.js:109)
...
StackTrace.fromError(err).then(function(stack){
...发布于 2017-12-07 15:08:53
如果不加载stackdriver-errors-concat.min.js文件,还需要手动加载stacktrace-js模块。
stackdriver-errors期望有一个StackTrace对象。
发布于 2018-01-16 15:18:13
由于您想要使用的库是实验性的,因此不能在生产环境中使用,所以最好使用经过测试和验证以供生产使用的不同库。
我建议使用另一个图书馆,它包括与Node.js和JavaScript的堆栈驱动程序错误报告相关的特性。
首先,通过运行以下命令来安装依赖项:
npm install --save @google-cloud/error-reporting这将自动将依赖项添加到package.json中。
在error-reporting.js中,可以通过将其添加到代码(所有参数都是可选的)来添加依赖性:
var errors = require('@google-cloud/error-reporting')({
projectId: 'my-project-id',
keyFilename: '/path/to/keyfile.json',
credentials: require('./path/to/keyfile.json'),
// if true library will attempt to report errors to the service regardless
// of the value of NODE_ENV
// defaults to false
ignoreEnvironmentCheck: false,
// determines the logging level internal to the library; levels range 0-5
// where 0 indicates no logs should be reported and 5 indicates all logs
// should be reported
// defaults to 2 (warnings)
logLevel: 2,
// determines whether or not unhandled rejections are reported to the
// error-reporting console
reportUnhandledRejections: true,
serviceContext: {
service: 'my-service',
version: 'my-service-version'
}
});之后,使用此代码测试Stackdriver是否正确地报告了错误:
errors.report(new Error('Something broke!'));请注意,该库目前正处于测试阶段,因此将来可能会对其进行一些更改。
https://stackoverflow.com/questions/47695055
复制相似问题