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CAAC,GAAG,CAAC,UAAU;QACtB,4FAA4F;QAC5F,OAAO,CAAC,GAAG,CAAC,UAAU;QACtB,8EAA8E;QAC9E,OAAO,CAAC,GAAG,CAAC,qBAAqB;QACjC,OAAO,CAAC,GAAG,CAAC,wBAAwB;QACpC,OAAO,CAAC,GAAG,CAAC,wBAAwB;QACpC,OAAO,CAAC,GAAG,CAAC,2BAA2B;QACvC,6BAA6B;QAC7B,OAAO,CAAC,GAAG,CAAC,sBAAsB;QAClC,OAAO,CAAC,GAAG,CAAC,sBAAsB;QAClC,OAAO,CAAC,GAAG,CAAC,yBAAyB;QACrC,QAAQ,CACT,CAAC;AACJ,CAAC;AA5BD,4CA4BC;AAED;;GAEG;AACH,SAAS,oBAAoB;IAC3B,IAAM,GAAG,GAAG,oBAAa,EAAE,CAAC;IAC5B,GAAG,CAAC,YAAY,EAAE,CAAC;IACnB,8GAA8G;IAC9G,qFAAqF;IACrF,yDAAyD;IACzD,oEAAoE;IACpE,OAAO,CAAC,EAAE,CAAC,YAAY,EAAE;;QACvB,IAAM,OAAO,SAAG,GAAG,CAAC,QAAQ,EAAE,0CAAE,UAAU,EAAE,CAAC;QAC7C,IAAM,cAAc,GAAG,CAAC,qBAAa,CAAC,MAAM,EAAE,qBAAa,CAAC,OAAO,CAAC,CAAC;QACrE,kFAAkF;QAClF,iDAAiD;QACjD,yEAAyE;QACzE,gDAAgD;QAChD,IAAI,OAAO,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC;YAAE,GAAG,CAAC,UAAU,EAAE,CAAC;IAC5E,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { getCurrentHub, initAndBind, Integrations as CoreIntegrations } from '@sentry/core';\nimport { getMainCarrier, setHubOnCarrier } from '@sentry/hub';\nimport { SessionStatus } from '@sentry/types';\nimport { getGlobalObject } from '@sentry/utils';\nimport * as domain from 'domain';\n\nimport { NodeClient } from './client';\nimport { Console, Http, LinkedErrors, OnUncaughtException, OnUnhandledRejection } from './integrations';\nimport { NodeOptions } from './types';\n\nexport const defaultIntegrations = [\n // Common\n new CoreIntegrations.InboundFilters(),\n new CoreIntegrations.FunctionToString(),\n // Native Wrappers\n new Console(),\n new Http(),\n // Global Handlers\n new OnUncaughtException(),\n new OnUnhandledRejection(),\n // Misc\n new LinkedErrors(),\n];\n\n/**\n * The Sentry Node SDK Client.\n *\n * To use this SDK, call the {@link init} function as early as possible in the\n * main entry module. To set context information or send manual events, use the\n * provided methods.\n *\n * @example\n * ```\n *\n * const { init } = require('@sentry/node');\n *\n * init({\n * dsn: '__DSN__',\n * // ...\n * });\n * ```\n *\n * @example\n * ```\n *\n * const { configureScope } = require('@sentry/node');\n * configureScope((scope: Scope) => {\n * scope.setExtra({ battery: 0.7 });\n * scope.setTag({ user_mode: 'admin' });\n * scope.setUser({ id: '4711' });\n * });\n * ```\n *\n * @example\n * ```\n *\n * const { addBreadcrumb } = require('@sentry/node');\n * addBreadcrumb({\n * message: 'My Breadcrumb',\n * // ...\n * });\n * ```\n *\n * @example\n * ```\n *\n * const Sentry = require('@sentry/node');\n * Sentry.captureMessage('Hello, world!');\n * Sentry.captureException(new Error('Good bye'));\n * Sentry.captureEvent({\n * message: 'Manual',\n * stacktrace: [\n * // ...\n * ],\n * });\n * ```\n *\n * @see {@link NodeOptions} for documentation on configuration options.\n */\nexport function init(options: NodeOptions = {}): void {\n const carrier = getMainCarrier();\n const autoloadedIntegrations = carrier.__SENTRY__?.integrations || [];\n\n options.defaultIntegrations =\n options.defaultIntegrations === false\n ? []\n : [\n ...(Array.isArray(options.defaultIntegrations) ? options.defaultIntegrations : defaultIntegrations),\n ...autoloadedIntegrations,\n ];\n\n if (options.dsn === undefined && process.env.SENTRY_DSN) {\n options.dsn = process.env.SENTRY_DSN;\n }\n\n if (options.tracesSampleRate === undefined && process.env.SENTRY_TRACES_SAMPLE_RATE) {\n const tracesSampleRate = parseFloat(process.env.SENTRY_TRACES_SAMPLE_RATE);\n if (isFinite(tracesSampleRate)) {\n options.tracesSampleRate = tracesSampleRate;\n }\n }\n\n if (options.release === undefined) {\n const detectedRelease = getSentryRelease();\n if (detectedRelease !== undefined) {\n options.release = detectedRelease;\n } else {\n // If release is not provided, then we should disable autoSessionTracking\n options.autoSessionTracking = false;\n }\n }\n\n if (options.autoSessionTracking === undefined) {\n options.autoSessionTracking = false;\n }\n\n if (options.environment === undefined && process.env.SENTRY_ENVIRONMENT) {\n options.environment = process.env.SENTRY_ENVIRONMENT;\n }\n\n if (options.autoSessionTracking === undefined) {\n options.autoSessionTracking = true;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any\n if ((domain as any).active) {\n setHubOnCarrier(carrier, getCurrentHub());\n }\n\n initAndBind(NodeClient, options);\n\n if (options.autoSessionTracking) {\n startSessionTracking();\n }\n}\n\n/**\n * This is the getter for lastEventId.\n *\n * @returns The last event id of a captured event.\n */\nexport function lastEventId(): string | undefined {\n return getCurrentHub().lastEventId();\n}\n\n/**\n * A promise that resolves when all current events have been sent.\n * If you provide a timeout and the queue takes longer to drain the promise returns false.\n *\n * @param timeout Maximum time in ms the client should wait.\n */\nexport async function flush(timeout?: number): Promise<boolean> {\n const client = getCurrentHub().getClient<NodeClient>();\n if (client) {\n return client.flush(timeout);\n }\n return Promise.reject(false);\n}\n\n/**\n * A promise that resolves when all current events have been sent.\n * If you provide a timeout and the queue takes longer to drain the promise returns false.\n *\n * @param timeout Maximum time in ms the client should wait.\n */\nexport async function close(timeout?: number): Promise<boolean> {\n const client = getCurrentHub().getClient<NodeClient>();\n if (client) {\n return client.close(timeout);\n }\n return Promise.reject(false);\n}\n\n/**\n * Function that takes an instance of NodeClient and checks if autoSessionTracking option is enabled for that client\n */\nexport function isAutoSessionTrackingEnabled(client?: NodeClient): boolean {\n if (client === undefined) {\n return false;\n }\n const clientOptions: NodeOptions = client && client.getOptions();\n if (clientOptions && clientOptions.autoSessionTracking !== undefined) {\n return clientOptions.autoSessionTracking;\n }\n return false;\n}\n\n/**\n * Returns a release dynamically from environment variables.\n */\nexport function getSentryRelease(fallback?: string): string | undefined {\n // Always read first as Sentry takes this as precedence\n if (process.env.SENTRY_RELEASE) {\n return process.env.SENTRY_RELEASE;\n }\n\n // This supports the variable that sentry-webpack-plugin injects\n const global = getGlobalObject();\n if (global.SENTRY_RELEASE && global.SENTRY_RELEASE.id) {\n return global.SENTRY_RELEASE.id;\n }\n\n return (\n // GitHub Actions - https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables\n process.env.GITHUB_SHA ||\n // Netlify - https://docs.netlify.com/configure-builds/environment-variables/#build-metadata\n process.env.COMMIT_REF ||\n // Vercel - https://vercel.com/docs/v2/build-step#system-environment-variables\n process.env.VERCEL_GIT_COMMIT_SHA ||\n process.env.VERCEL_GITHUB_COMMIT_SHA ||\n process.env.VERCEL_GITLAB_COMMIT_SHA ||\n process.env.VERCEL_BITBUCKET_COMMIT_SHA ||\n // Zeit (now known as Vercel)\n process.env.ZEIT_GITHUB_COMMIT_SHA ||\n process.env.ZEIT_GITLAB_COMMIT_SHA ||\n process.env.ZEIT_BITBUCKET_COMMIT_SHA ||\n fallback\n );\n}\n\n/**\n * Enable automatic Session Tracking for the node process.\n */\nfunction startSessionTracking(): void {\n const hub = getCurrentHub();\n hub.startSession();\n // Emitted in the case of healthy sessions, error of `mechanism.handled: true` and unhandledrejections because\n // The 'beforeExit' event is not emitted for conditions causing explicit termination,\n // such as calling process.exit() or uncaught exceptions.\n // Ref: https://nodejs.org/api/process.html#process_event_beforeexit\n process.on('beforeExit', () => {\n const session = hub.getScope()?.getSession();\n const terminalStates = [SessionStatus.Exited, SessionStatus.Crashed];\n // Only call endSession, if the Session exists on Scope and SessionStatus is not a\n // Terminal Status i.e. Exited or Crashed because\n // \"When a session is moved away from ok it must not be updated anymore.\"\n // Ref: https://develop.sentry.dev/sdk/sessions/\n if (session && !terminalStates.includes(session.status)) hub.endSession();\n });\n}\n"]}
\No newline at end of file