Connect集成Sentry

我们的Connect集成只需要安装@ sentry / node,然后您可以像这样使用它:

const connect = require('connect');
const Sentry = require('@sentry/node');

// Must configure Sentry before doing anything else with it
Sentry.init({ dsn: 'https://<key>@sentry.io/<project>' });

function mainHandler(req, res) {
  throw new Error('Broke!');
}

function onError(err, req, res, next) {
  // The error id is attached to `res.sentry` to be returned
  // and optionally displayed to the user for support.
  res.statusCode = 500;
  res.end(res.sentry + '\n');
}

connect(
  // The request handler be the first item
  Sentry.Handlers.requestHandler(),

  connect.bodyParser(),
  connect.cookieParser(),
  mainHandler,

  // The error handler must be before any other error middleware
  Sentry.Handlers.errorHandler(),

  // Optional fallthrough error handler
  onError
).listen(3000);

猜你喜欢

转载自blog.csdn.net/u013702678/article/details/83176534