From eeed3de5aecd5a2f5d8e405a43c2f42e0bb51777 Mon Sep 17 00:00:00 2001 From: Alexander Rodionov Date: Thu, 5 Oct 2023 15:29:57 +0400 Subject: [PATCH] refactor: reexport `Sentry` from utils --- src/Config/CliBuilder.ts | 13 ++++--------- src/Utils/Sentry.ts | 3 +++ src/Utils/index.ts | 1 + 3 files changed, 8 insertions(+), 9 deletions(-) create mode 100644 src/Utils/Sentry.ts diff --git a/src/Config/CliBuilder.ts b/src/Config/CliBuilder.ts index a9327fe5..39bff5f0 100644 --- a/src/Config/CliBuilder.ts +++ b/src/Config/CliBuilder.ts @@ -1,13 +1,8 @@ import { CliConfig, ConfigReader } from './ConfigReader'; -import { ClusterArgs, Helpers, logger, LogLevel } from '../Utils'; +import { ClusterArgs, Helpers, logger, LogLevel, Sentry } from '../Utils'; import { SystemConfigReader } from './SystemConfigReader'; import { CliInfo } from './CliInfo'; import { Arguments, Argv, CommandModule } from 'yargs'; -import { - init as initSentry, - runWithAsyncContext as runSentryWithAsyncContext, - setContext as setSentryContext -} from '@sentry/node'; export interface CliBuilderOptions { info: CliInfo; @@ -98,7 +93,7 @@ export class CliBuilder { const systemConfigReader = new SystemConfigReader(args.api as string); const systemConfig = await systemConfigReader.read(); - initSentry({ + Sentry.init({ attachStacktrace: true, dsn: systemConfig.sentryDsn, release: process.env.VERSION, @@ -115,8 +110,8 @@ export class CliBuilder { } }); - return runSentryWithAsyncContext(() => { - setSentryContext('args', args); + return Sentry.runWithAsyncContext(() => { + Sentry.setContext('args', args); return handler(args); }); diff --git a/src/Utils/Sentry.ts b/src/Utils/Sentry.ts new file mode 100644 index 00000000..e3a504ad --- /dev/null +++ b/src/Utils/Sentry.ts @@ -0,0 +1,3 @@ +import { init, setContext, runWithAsyncContext } from '@sentry/node'; + +export default { init, setContext, runWithAsyncContext }; diff --git a/src/Utils/index.ts b/src/Utils/index.ts index 332df095..8b1cce64 100644 --- a/src/Utils/index.ts +++ b/src/Utils/index.ts @@ -3,3 +3,4 @@ export * from './Helpers'; export * from './Logger'; export * from './Backoff'; export * from './Traceroute'; +export { default as Sentry } from './Sentry';