/
sentinel.mjs
52 lines (46 loc) · 1.62 KB
/
sentinel.mjs
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
52
// https://github.com/getsentry/sentry-javascript/blob/develop/MIGRATION.md#nextjs-sdk
import { isPrimary } from './callosum.mjs';
import { log as _log, need } from './utilitas.mjs';
const _NEED = ['@sentry/node', '@sentry/profiling-node'];
const log = (content) => _log(content, import.meta.url);
let sentry;
const init = async (options) => {
if (options) {
sentry = await need('@sentry/node');
const integrations = [
sentry.onUnhandledRejectionIntegration({ mode: 'strict' }),
...options?.integrations || [],
];
// Disabled for now due to the following issue:
// https://github.com/getsentry/profiling-node/issues/171
// try {
// // https://docs.sentry.io/platforms/node/profiling/
// const { nodeProfilingIntegration } = await need(
// '@sentry/profiling-node', { raw: true }
// );
// integrations.push(nodeProfilingIntegration());
// } catch (e) { log('Sentry Profiling is not available.'); }
sentry.init({
tracesSampleRate: 1.0, profilesSampleRate: 1.0,
debug: globalThis.debug, ...options || {}, integrations,
});
isPrimary && !options.silent && log(`Initialized, dsn: ${options.dsn}.`);
}
assert(sentry, 'Sentry has not been initialized.', 501);
return sentry;
};
export default init;
export {
_NEED,
init,
};
// Demo:
// (await utilitas.sentinel.init()).startSpan(
// {
// op: "rootSpan",
// name: "My root span",
// },
// async () => {
// // This function is the span's operation
// }
// );