Skip to content

Commit

Permalink
fix: fixed feature flag for sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
ageddesi committed Nov 29, 2022
1 parent df99dd0 commit 9003412
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ SCHEME=http
HOSTNAME=localhost:3000
RATELIMIT_WINDOWTIME=900000
RATELIMIT_WINDOWSIZE=10
SENTRY_DSN=https://23423423.ingest.sentry.io/234234
SENTRY_DSN=https://23423423.ingest.sentry.io/234234
ENABLE_SENTRY=false
ENABLE_RATE_LIMIT=false
37 changes: 21 additions & 16 deletions app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@ const app = express();

const constantPath = './src/modules/';
const routes = {};
/** DEFINE SENTRY LOGGING */
const Sentry = require('@sentry/node');
const SentryTracing = require('@sentry/tracing');
Sentry.init({
dsn: process.env.SENTRY_DSN,
tracesSampleRate: 1.0,
integrations: [
new Sentry.Integrations.Http({ tracing: true }),
new SentryTracing.Integrations.Express({
app,
}),
],
});
let Sentry = null;
if(process.env.ENABLE_SENTRY === 'true'){
/** DEFINE SENTRY LOGGING */
Sentry = require('@sentry/node');
const SentryTracing = require('@sentry/tracing');
Sentry.init({
dsn: process.env.SENTRY_DSN,
tracesSampleRate: 1.0,
integrations: [
new Sentry.Integrations.Http({ tracing: true }),
new SentryTracing.Integrations.Express({
app,
}),
],
});
}

fs.readdirSync(constantPath).forEach((module) => {
const apiRoutePath = `${constantPath}${module}/api/`;
Expand Down Expand Up @@ -52,9 +55,11 @@ app.get('/full-status', (req, res) => {
res.status(200).send(data);
});

app.use(Sentry.Handlers.errorHandler());
app.use(Sentry.Handlers.requestHandler());
app.use(Sentry.Handlers.tracingHandler());
if(process.env.ENABLE_SENTRY == "true"){
app.use(Sentry.Handlers.errorHandler());
app.use(Sentry.Handlers.requestHandler());
app.use(Sentry.Handlers.tracingHandler());
}
if (process.env.ENABLE_RATE_LIMIT === 'true') app.use(applicationRateLimiter); // enable RateLimiting
initSwagger(app); // setup Swagger
app.use(cors()); // enabling CORS for all requests
Expand Down

0 comments on commit 9003412

Please sign in to comment.