{"version":3,"file":"sentry.mjs","sources":["../../../server/src/services/sentry.ts"],"sourcesContent":["import type { Core } from '@strapi/strapi';\nimport * as Sentry from '@sentry/node';\nimport type { Config } from '../config';\n\nconst createSentryService = (strapi: Core.Strapi) => {\n  let isReady = false;\n  let instance: typeof Sentry | null = null;\n\n  // Retrieve user config and merge it with the default one\n  const config = strapi.config.get('plugin::sentry') as Config;\n\n  return {\n    /**\n     * Initialize Sentry service\n     */\n    init() {\n      // Make sure there isn't a Sentry instance already running\n      if (instance != null) {\n        return this;\n      }\n\n      // Don't init Sentry if no DSN was provided\n      if (!config.dsn) {\n        strapi.log.info('@strapi/plugin-sentry is disabled because no Sentry DSN was provided');\n        return this;\n      }\n\n      try {\n        Sentry.init({\n          dsn: config.dsn,\n          environment: strapi.config.get('environment'),\n          ...config.init,\n        });\n\n        // Store the successfully initialized Sentry instance\n        instance = Sentry;\n        isReady = true;\n      } catch {\n        strapi.log.warn('Could not set up Sentry, make sure you entered a valid DSN');\n      }\n\n      return this;\n    },\n\n    /**\n     * Expose Sentry instance through a getter\n     */\n    getInstance() {\n      return instance;\n    },\n\n    /**\n     * Higher level method to send exception events to Sentry\n     */\n    sendError(error: Error, configureScope?: (scope: Sentry.Scope) => void) {\n      // Make sure Sentry is ready\n      if (!isReady || !instance) {\n        strapi.log.warn(\"Sentry wasn't properly initialized, cannot send event\");\n        return;\n      }\n\n      instance.withScope((scope) => {\n        // Configure the Sentry scope using the provided callback\n        if (configureScope && config.sendMetadata) {\n          configureScope(scope);\n        }\n\n        // Actually send the Error to Sentry\n        instance?.captureException(error);\n      });\n    },\n  };\n};\n\nexport default ({ strapi }: { strapi: Core.Strapi }) => createSentryService(strapi);\n"],"names":["createSentryService","strapi","isReady","instance","config","get","init","dsn","log","info","Sentry","environment","warn","getInstance","sendError","error","configureScope","withScope","scope","sendMetadata","captureException"],"mappings":";;AAIA,MAAMA,sBAAsB,CAACC,MAAAA,GAAAA;AAC3B,IAAA,IAAIC,OAAAA,GAAU,K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