UNPKG

@sentry/core

Version:
55 lines (54 loc) • 1.86 kB
import { isClientClosed } from "./client.js"; import { getClient, getCurrentScope } from "./currentScopes.js"; import { DEBUG_BUILD } from "./debug-build.js"; import { consoleSandbox, debug } from "./utils/debug-logger.js"; // src/sdk.ts /** * Internal function to create a new SDK client instance. The client is * installed and then bound to the current scope. * * @param clientClass The client class to instantiate. * @param options Options to pass to the client. */ function initAndBind(clientClass, options) { if (options.debug === true) { if (DEBUG_BUILD) debug.enable(); else consoleSandbox(() => { console.warn("[Sentry] Cannot initialize SDK with `debug` option using a non-debug bundle."); }); } warnIfClientIsActive(); getCurrentScope().update(options.initialScope); const client = new clientClass(options); setCurrentClient(client); client.init(); return client; } /** * Returns the client bound to the current scope, unless it is closed. * * @hidden */ function getActiveClient() { const client = getClient(); return client && !isClientClosed(client) ? client : void 0; } /** * Warns when `init()` runs while a client is still bound. The new client * replaces it, but the old client stays alive, so the two can mix state. * * @hidden */ function warnIfClientIsActive() { if (getActiveClient()) consoleSandbox(() => { console.warn("[Sentry] `Sentry.init()` was called more than once. The new client replaces the active client, but the active client is not closed, so state from both can mix. Call `Sentry.init()` only once, or call `await Sentry.close()` before you call it again."); }); } /** * Make the given client the current client. */ function setCurrentClient(client) { getCurrentScope().setClient(client); } export { getActiveClient, initAndBind, setCurrentClient, warnIfClientIsActive }; //# sourceMappingURL=sdk.js.map