forked from SmartDropLabs/smartdrop-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrorTracker.js
More file actions
51 lines (41 loc) · 992 Bytes
/
Copy patherrorTracker.js
File metadata and controls
51 lines (41 loc) · 992 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict';
const Sentry = require('@sentry/node');
const config = require('../config');
let initialized = false;
function init() {
const dsn = config.sentryDsn || process.env.SENTRY_DSN;
if (dsn) {
Sentry.init({
dsn,
environment: config.nodeEnv || 'development',
tracesSampleRate: 1.0,
});
initialized = true;
}
return initialized;
}
function isInitialized() {
return initialized;
}
function captureException(error, context = {}) {
if (!error) return null;
if (initialized) {
return Sentry.captureException(error, { extra: context });
}
return null;
}
function captureMessage(message, level = 'info', context = {}) {
if (!message) return null;
if (initialized) {
return Sentry.captureMessage(message, { level, extra: context });
}
return null;
}
// Auto-initialize on import if SENTRY_DSN is present in environment/config
init();
module.exports = {
init,
isInitialized,
captureException,
captureMessage,
};