@sentry/browser
Version:
Official Sentry SDK for browsers
116 lines (115 loc) • 3.89 kB
JavaScript
import { BrowserClient } from "./client.js";
import { breadcrumbsIntegration } from "./integrations/breadcrumbs.js";
import { browserApiErrorsIntegration } from "./integrations/browserapierrors.js";
import { browserSessionIntegration } from "./integrations/browsersession.js";
import { cultureContextIntegration } from "./integrations/culturecontext.js";
import { globalHandlersIntegration } from "./integrations/globalhandlers.js";
import { httpContextIntegration } from "./integrations/httpcontext.js";
import { linkedErrorsIntegration } from "./integrations/linkederrors.js";
import { defaultStackParser } from "./stack-parsers.js";
import { makeFetchTransport } from "./transports/fetch.js";
import { normalizeStringifyValue } from "./normalizeStringifyValue.js";
import { checkAndWarnIfIsEmbeddedBrowserExtension } from "./utils/detectBrowserExtension.js";
import { resolveBrowserTunnelOption } from "./utils/managedTunnel.js";
import { _INTERNAL_captureOptionsSetByUser, consoleIntegration, conversationIdIntegration, dedupeIntegration, eventFiltersIntegration, functionToStringIntegration, getIntegrationsToSetup, initAndBind, setNormalizeStringifier, stackParserFromStackParserOptions } from "@sentry/core";
// src/sdk.ts
/** Get the default integrations for the browser SDK. */
function getDefaultIntegrations(_options) {
/**
* Note: Please make sure this stays in sync with Angular SDK, which re-exports
* `getDefaultIntegrations` but with an adjusted set of integrations.
*/
return [
eventFiltersIntegration(),
functionToStringIntegration(),
conversationIdIntegration(),
browserApiErrorsIntegration(),
breadcrumbsIntegration(),
consoleIntegration(),
globalHandlersIntegration(),
linkedErrorsIntegration(),
dedupeIntegration(),
httpContextIntegration(),
cultureContextIntegration(),
browserSessionIntegration()
];
}
/**
* The Sentry Browser SDK Client.
*
* To use this SDK, call the {@link init} function as early as possible when
* loading the web page. To set context information or send manual events, use
* the provided methods.
*
* @example
*
* ```
*
* import { init } from '@sentry/browser';
*
* init({
* dsn: '__DSN__',
* // ...
* });
* ```
*
* @example
* ```
*
* import { addBreadcrumb } from '@sentry/browser';
* addBreadcrumb({
* message: 'My Breadcrumb',
* // ...
* });
* ```
*
* @example
*
* ```
*
* import * as Sentry from '@sentry/browser';
* Sentry.captureMessage('Hello, world!');
* Sentry.captureException(new Error('Good bye'));
* Sentry.captureEvent({
* message: 'Manual',
* stacktrace: [
* // ...
* ],
* });
* ```
*
* @see {@link BrowserOptions} for documentation on configuration options.
*/
function init(userOptions = {}) {
const options = _INTERNAL_captureOptionsSetByUser(userOptions);
const shouldDisableBecauseIsBrowserExtenstion = !options.skipBrowserExtensionCheck && checkAndWarnIfIsEmbeddedBrowserExtension();
let defaultIntegrations = options.defaultIntegrations == null ? getDefaultIntegrations(options) : options.defaultIntegrations;
const integrations = getIntegrationsToSetup({
integrations: options.integrations,
defaultIntegrations
});
const clientOptions = {
...options,
...resolveBrowserTunnelOption(options),
enabled: shouldDisableBecauseIsBrowserExtenstion ? false : options.enabled,
stackParser: stackParserFromStackParserOptions(options.stackParser || defaultStackParser),
integrations,
transport: options.transport || makeFetchTransport
};
setNormalizeStringifier(normalizeStringifyValue);
return initAndBind(BrowserClient, clientOptions);
}
/**
* This function is here to be API compatible with the loader.
* @hidden
*/
function forceLoad() {}
/**
* This function is here to be API compatible with the loader.
* @hidden
*/
function onLoad(callback) {
callback();
}
export { forceLoad, getDefaultIntegrations, init, onLoad };
//# sourceMappingURL=sdk.js.map