@sentry/core
Version:
Base implementation for all Sentry JavaScript SDKs
44 lines (43 loc) • 1.6 kB
JavaScript
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;
}
/**
* Logs a warning when a client that is not closed is bound to the current scope.
*/
function warnIfClientIsActive() {
const client = getClient();
if (client && !isClientClosed(client)) 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 { initAndBind, setCurrentClient, warnIfClientIsActive };
//# sourceMappingURL=sdk.js.map