feat(tools): sentry apm and other telemetry (#49230)

This commit is contained in:
Mrugesh Mohapatra
2023-02-13 20:02:49 +05:30
committed by GitHub
parent 2b63eaa8bb
commit b4fa56be3e
3 changed files with 181 additions and 17 deletions

View File

@@ -2,6 +2,7 @@ const path = require('path');
require('dotenv').config({ path: path.resolve(__dirname, '../../../.env') });
const Sentry = require('@sentry/node');
const Tracing = require('@sentry/tracing');
const createDebugger = require('debug');
const _ = require('lodash');
const loopback = require('loopback');
@@ -14,16 +15,32 @@ const { setupPassport } = require('./component-passport');
const log = createDebugger('fcc:server');
const reqLogFormat = ':date[iso] :status :method :response-time ms - :url';
const app = loopback();
if (sentry.dsn === 'dsn_from_sentry_dashboard') {
log('Sentry reporting disabled unless DSN is provided.');
} else {
Sentry.init({
dsn: sentry.dsn
dsn: sentry.dsn,
integrations: [
new Sentry.Integrations.Http({ tracing: true }),
new Tracing.Integrations.Express({
app
})
],
// Capture 20% of transactions to avoid
// overwhelming Sentry and remain within
// the usage quota
tracesSampleRate: 0.2
});
log('Sentry initialized');
}
const app = loopback();
// RequestHandler creates a separate execution context using domains, so that every
// transaction/span/breadcrumb is attached to its own Hub instance
app.use(Sentry.Handlers.requestHandler());
// TracingHandler creates a trace for every incoming request
app.use(Sentry.Handlers.tracingHandler());
app.set('state namespace', '__fcc__');
app.set('port', process.env.API_PORT || 3000);