feat: Integrate Sentry to backend (#270)
* feat: Integrate Sentry to backend * update lock * update .env --------- Co-authored-by: Rotimi Best <[email protected]>
This commit is contained in:
co-authored by
Rotimi Best
parent
9c066c79be
commit
2413120e95
@@ -16,3 +16,6 @@ SMTP_HOST=
|
|||||||
SMTP_USER=
|
SMTP_USER=
|
||||||
SMTP_PASSWORD=
|
SMTP_PASSWORD=
|
||||||
SMTP_PORT=
|
SMTP_PORT=
|
||||||
|
|
||||||
|
# Sentry DNS
|
||||||
|
SENTRY_DNS=
|
||||||
Generated
+11
@@ -2878,6 +2878,17 @@
|
|||||||
"resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.1.0.tgz",
|
||||||
"integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ=="
|
"integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ=="
|
||||||
},
|
},
|
||||||
|
"node_modules/node-abi": {
|
||||||
|
"version": "3.59.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.59.0.tgz",
|
||||||
|
"integrity": "sha512-HyyfzvTLCE8b1SX2nWimlra8cibEsypcSu/Az4SXMhWhtuctkwAX7qsEYNjUOIoYtPV884oN3wtYTN+iZKBtvw==",
|
||||||
|
"dependencies": {
|
||||||
|
"semver": "^7.3.5"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/node-fetch": {
|
"node_modules/node-fetch": {
|
||||||
"version": "2.6.12",
|
"version": "2.6.12",
|
||||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.12.tgz",
|
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.12.tgz",
|
||||||
|
|||||||
@@ -21,6 +21,8 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-sdk/client-s3": "^3.388.0",
|
"@aws-sdk/client-s3": "^3.388.0",
|
||||||
"@aws-sdk/lib-storage": "^3.535.0",
|
"@aws-sdk/lib-storage": "^3.535.0",
|
||||||
|
"@sentry/node": "^7.110.1",
|
||||||
|
"@sentry/profiling-node": "^7.110.1",
|
||||||
"@supabase/supabase-js": "^2.32.0",
|
"@supabase/supabase-js": "^2.32.0",
|
||||||
"@types/nodemailer": "^6.4.11",
|
"@types/nodemailer": "^6.4.11",
|
||||||
"axios": "^1.4.0",
|
"axios": "^1.4.0",
|
||||||
|
|||||||
+28
-3
@@ -4,6 +4,8 @@ const express = require('express');
|
|||||||
const rateLimit = require('express-rate-limit');
|
const rateLimit = require('express-rate-limit');
|
||||||
const cors = require('cors');
|
const cors = require('cors');
|
||||||
const bodyParser = require('body-parser');
|
const bodyParser = require('body-parser');
|
||||||
|
const sentry = require('@sentry/node');
|
||||||
|
const { ProfilingIntegration } = require('@sentry/profiling-node');
|
||||||
|
|
||||||
const uploadVideo = require('./src/routes/uploadVideo');
|
const uploadVideo = require('./src/routes/uploadVideo');
|
||||||
const downloadCertificate = require('./src/routes/downloadCertificate');
|
const downloadCertificate = require('./src/routes/downloadCertificate');
|
||||||
@@ -12,14 +14,19 @@ const downloadCourse = require('./src/routes/downloadCourse');
|
|||||||
const katex = require('./src/routes/katex');
|
const katex = require('./src/routes/katex');
|
||||||
const sendEmail = require('./src/routes/sendEmail');
|
const sendEmail = require('./src/routes/sendEmail');
|
||||||
|
|
||||||
|
sentry.init({
|
||||||
|
dsn: process.env.SENTRY_DNS || '',
|
||||||
|
integrations: [new ProfilingIntegration()],
|
||||||
|
tracesSampleRate: 1.0,
|
||||||
|
profilesSampleRate: 1.0
|
||||||
|
});
|
||||||
|
|
||||||
// Express server
|
// Express server
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
const port = process.env.PORT || 3002;
|
const port = process.env.PORT || 3002;
|
||||||
|
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
app.use(bodyParser.urlencoded({ extended: true }));
|
app.use(bodyParser.urlencoded({ extended: true }));
|
||||||
|
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
|
||||||
// Rate limiting middleware
|
// Rate limiting middleware
|
||||||
@@ -30,6 +37,11 @@ const limiter = rateLimit({
|
|||||||
|
|
||||||
app.use(limiter);
|
app.use(limiter);
|
||||||
|
|
||||||
|
// Integrate Sentry middleware
|
||||||
|
app.use(sentry.Handlers.requestHandler());
|
||||||
|
app.use(sentry.Handlers.errorHandler());
|
||||||
|
|
||||||
|
// Register routes
|
||||||
app.use('/downloadCertificate', downloadCertificate);
|
app.use('/downloadCertificate', downloadCertificate);
|
||||||
app.use('/downloadLesson', downloadLesson);
|
app.use('/downloadLesson', downloadLesson);
|
||||||
app.use('/downloadCourse', downloadCourse);
|
app.use('/downloadCourse', downloadCourse);
|
||||||
@@ -41,10 +53,23 @@ app.get('/', (req, res) => {
|
|||||||
res.send('Welcome to ClassroomIO');
|
res.send('Welcome to ClassroomIO');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Start server
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
console.log(`ClassroomIO Backend listening on port ${port}!`);
|
console.log(`ClassroomIO Backend listening on port ${port}!`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Handle uncaught exceptions
|
||||||
process.on('uncaughtException', (err) => {
|
process.on('uncaughtException', (err) => {
|
||||||
console.error('Uncaught error, err');
|
console.error('Uncaught error', err);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Error-handling middleware
|
||||||
|
app.use((error, req, res, next) => {
|
||||||
|
console.error('Exception error caught:', error);
|
||||||
|
|
||||||
|
// Capture and send the error to Sentry
|
||||||
|
sentry.captureException(error);
|
||||||
|
|
||||||
|
// Respond with a 500 Internal Server Error
|
||||||
|
res.status(500).json({ error: 'Internal Server Error' });
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ CLOUDFLARE_ACCESS_KEY=""
|
|||||||
CLOUDFLARE_ACCOUNT_ID=""
|
CLOUDFLARE_ACCOUNT_ID=""
|
||||||
CLOUDFLARE_BUCKET_DOMAIN=""
|
CLOUDFLARE_BUCKET_DOMAIN=""
|
||||||
CLOUDFLARE_SECRET_ACCESS_KEY=""
|
CLOUDFLARE_SECRET_ACCESS_KEY=""
|
||||||
|
SENTRY_DNS=""
|
||||||
```
|
```
|
||||||
|
|
||||||
<Callout type="info" emoji="ℹ️">
|
<Callout type="info" emoji="ℹ️">
|
||||||
|
|||||||
Generated
+34
@@ -48,6 +48,12 @@ importers:
|
|||||||
'@aws-sdk/lib-storage':
|
'@aws-sdk/lib-storage':
|
||||||
specifier: ^3.535.0
|
specifier: ^3.535.0
|
||||||
version: 3.658.1(@aws-sdk/[email protected])
|
version: 3.658.1(@aws-sdk/[email protected])
|
||||||
|
'@sentry/node':
|
||||||
|
specifier: ^7.110.1
|
||||||
|
version: 7.119.0
|
||||||
|
'@sentry/profiling-node':
|
||||||
|
specifier: ^7.110.1
|
||||||
|
version: 7.119.0
|
||||||
'@supabase/supabase-js':
|
'@supabase/supabase-js':
|
||||||
specifier: ^2.32.0
|
specifier: ^2.32.0
|
||||||
version: 2.45.4
|
version: 2.45.4
|
||||||
@@ -3730,6 +3736,27 @@ packages:
|
|||||||
localforage: 1.10.0
|
localforage: 1.10.0
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
|
/@sentry/[email protected]:
|
||||||
|
resolution: {integrity: sha512-9PFzN8xS6U0oZCflpVxS2SSIsHkCaj7qYBlsvHj4CTGWfao9ImwrU6+smy4qoG6oxwPfoVb5pOOMb4WpWOvXcQ==}
|
||||||
|
engines: {node: '>=8'}
|
||||||
|
dependencies:
|
||||||
|
'@sentry-internal/tracing': 7.119.0
|
||||||
|
'@sentry/core': 7.119.0
|
||||||
|
'@sentry/integrations': 7.119.0
|
||||||
|
'@sentry/types': 7.119.0
|
||||||
|
'@sentry/utils': 7.119.0
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/@sentry/[email protected]:
|
||||||
|
resolution: {integrity: sha512-KEJ2kFVWDmg2qi7y24PuSqerlW+iDK4C6pDXpXV6h+GEekUXsnRSAqtKc5H6LJqVGe8ljgFqPy75XIkM1qPBzw==}
|
||||||
|
engines: {node: '>=8.0.0'}
|
||||||
|
hasBin: true
|
||||||
|
requiresBuild: true
|
||||||
|
dependencies:
|
||||||
|
detect-libc: 2.0.3
|
||||||
|
node-abi: 3.68.0
|
||||||
|
dev: false
|
||||||
|
|
||||||
/@sentry/[email protected]:
|
/@sentry/[email protected]:
|
||||||
resolution: {integrity: sha512-BnNsYL+X5I4WCH6wOpY6HQtp4MgVt0NVlhLUsEyrvMUiTs0bPkDBrulsgZQBUKJsbOr3l9nHrFoNVB/0i6WNLA==}
|
resolution: {integrity: sha512-BnNsYL+X5I4WCH6wOpY6HQtp4MgVt0NVlhLUsEyrvMUiTs0bPkDBrulsgZQBUKJsbOr3l9nHrFoNVB/0i6WNLA==}
|
||||||
engines: {node: '>=12'}
|
engines: {node: '>=12'}
|
||||||
@@ -11544,6 +11571,13 @@ packages:
|
|||||||
- supports-color
|
- supports-color
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
|
/[email protected]:
|
||||||
|
resolution: {integrity: sha512-7vbj10trelExNjFSBm5kTvZXXa7pZyKWx9RCKIyqe6I9Ev3IzGpQoqBP3a+cOdxY+pWj6VkP28n/2wWysBHD/A==}
|
||||||
|
engines: {node: '>=10'}
|
||||||
|
dependencies:
|
||||||
|
semver: 7.6.3
|
||||||
|
dev: false
|
||||||
|
|
||||||
/[email protected]:
|
/[email protected]:
|
||||||
resolution: {integrity: sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==}
|
resolution: {integrity: sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==}
|
||||||
engines: {node: '>=10.5.0'}
|
engines: {node: '>=10.5.0'}
|
||||||
|
|||||||
Reference in New Issue
Block a user