@sentry/browser
- Version 8.52.0
- Published
- 1.07 MB
- 5 dependencies
- MIT license
Install
npm i @sentry/browser
yarn add @sentry/browser
pnpm add @sentry/browser
Overview
Official Sentry SDK for browsers
Index
Variables
Functions
- breadcrumbsIntegration()
- browserApiErrorsIntegration()
- browserProfilingIntegration()
- browserSessionIntegration()
- browserTracingIntegration()
- buildLaunchDarklyFlagUsedHandler()
- captureUserFeedback()
- contextLinesIntegration()
- createUserFeedbackEnvelope()
- eventFromException()
- eventFromMessage()
- exceptionFromError()
- forceLoad()
- getDefaultIntegrations()
- globalHandlersIntegration()
- httpClientIntegration()
- httpContextIntegration()
- init()
- instrumentOutgoingRequests()
- launchDarklyIntegration()
- lazyLoadIntegration()
- linkedErrorsIntegration()
- makeBrowserOfflineTransport()
- makeFetchTransport()
- onLoad()
- openFeatureIntegration()
- reportingObserverIntegration()
- showReportDialog()
- spotlightBrowserIntegration()
- startBrowserTracingNavigationSpan()
- startBrowserTracingPageLoadSpan()
- unleashIntegration()
Classes
Interfaces
Type Aliases
Variables
variable chromeStackLineParser
const chromeStackLineParser: StackLineParser;
variable defaultRequestInstrumentationOptions
const defaultRequestInstrumentationOptions: RequestInstrumentationOptions;
variable defaultStackLineParsers
const defaultStackLineParsers: StackLineParser[];
variable defaultStackParser
const defaultStackParser: any;
variable featureFlagsIntegration
const featureFlagsIntegration: IntegrationFn<FeatureFlagsIntegration>;
Sentry integration for buffering feature flags manually with an API, and capturing them on error events. We recommend you do this on each flag evaluation. Flags are buffered per Sentry scope and limited to 100 per event.
See the [feature flag documentation](https://develop.sentry.dev/sdk/expected-features/#feature-flags) for more information.
Example 1
import * as Sentry from '@sentry/browser';import { type FeatureFlagsIntegration } from '@sentry/browser';// SetupSentry.init(..., integrations: [Sentry.featureFlagsIntegration()])// Verifyconst flagsIntegration = Sentry.getClient()?.getIntegrationByName<FeatureFlagsIntegration>('FeatureFlags');if (flagsIntegration) {flagsIntegration.addFeatureFlag('my-flag', true);} else {// check your setup}Sentry.captureException(Exception('broke')); // 'my-flag' should be captured to this Sentry event.
variable feedbackAsyncIntegration
const feedbackAsyncIntegration: any;
An integration to add user feedback to your application, while loading most of the code lazily only when it's needed.
variable feedbackIntegration
const feedbackIntegration: any;
Add a widget to capture user feedback to your application.
variable feedbackSyncIntegration
const feedbackSyncIntegration: any;
Add a widget to capture user feedback to your application.
variable geckoStackLineParser
const geckoStackLineParser: StackLineParser;
variable metrics
const metrics: Metrics;
The metrics API is used to capture custom metrics in Sentry.
Deprecated
The Sentry metrics beta has ended. This export will be removed in a future release.
variable opera10StackLineParser
const opera10StackLineParser: StackLineParser;
variable opera11StackLineParser
const opera11StackLineParser: StackLineParser;
variable WINDOW
const WINDOW: any;
variable winjsStackLineParser
const winjsStackLineParser: StackLineParser;
Functions
function breadcrumbsIntegration
breadcrumbsIntegration: ( options?: Partial<BreadcrumbsOptions> | undefined) => any;
function browserApiErrorsIntegration
browserApiErrorsIntegration: ( options?: Partial<BrowserApiErrorsOptions> | undefined) => any;
Wrap timer functions and event targets to catch errors and provide better meta data.
function browserProfilingIntegration
browserProfilingIntegration: () => any;
function browserSessionIntegration
browserSessionIntegration: () => any;
When added, automatically creates sessions which allow you to track adoption and crashes (crash free rate) in your Releases in Sentry. More information: https://docs.sentry.io/product/releases/health/
Note: In order for session tracking to work, you need to set up Releases: https://docs.sentry.io/product/releases/
function browserTracingIntegration
browserTracingIntegration: (_options?: Partial<BrowserTracingOptions>) => { name: string; afterAllSetup(client: Client<any>): void;};
The Browser Tracing integration automatically instruments browser pageload/navigation actions as transactions, and captures requests, metrics and errors as spans.
The integration can be configured with a variety of options, and can be extended to use any routing library.
We explicitly export the proper type here, as this has to be extended in some cases.
function buildLaunchDarklyFlagUsedHandler
buildLaunchDarklyFlagUsedHandler: () => LDInspectionFlagUsedHandler;
LaunchDarkly hook that listens for flag evaluations and updates the
flags
context in our Sentry scope. This needs to be registered as an 'inspector' in LaunchDarkly initialize() options, separately fromlaunchDarklyIntegration
. Both are needed to collect feature flags on error.
function captureUserFeedback
captureUserFeedback: (feedback: UserFeedback) => void;
Captures user feedback and sends it to Sentry.
Deprecated
Use
captureFeedback
instead.
function contextLinesIntegration
contextLinesIntegration: (options?: ContextLinesOptions | undefined) => any;
Collects source context lines around the lines of stackframes pointing to JS embedded in the current page's HTML.
This integration DOES NOT work for stack frames pointing to JS files that are loaded by the browser. For frames pointing to files, context lines are added during ingestion and symbolication by attempting to download the JS files to the Sentry backend.
Use this integration if you have inline JS code in HTML pages that can't be accessed by our backend (e.g. due to a login-protected page).
function createUserFeedbackEnvelope
createUserFeedbackEnvelope: ( feedback: UserFeedback, { metadata, tunnel, dsn, }: { metadata: SdkMetadata | undefined; tunnel: string | undefined; dsn: DsnComponents | undefined; }) => EventEnvelope;
Creates an envelope from a user feedback.
function eventFromException
eventFromException: ( stackParser: StackParser, exception: unknown, hint?: EventHint, attachStacktrace?: boolean) => PromiseLike<Event>;
Creates an Event from all inputs to
captureException
and non-primitive inputs tocaptureMessage
.
function eventFromMessage
eventFromMessage: ( stackParser: StackParser, message: ParameterizedString, level?: SeverityLevel, hint?: EventHint, attachStacktrace?: boolean) => PromiseLike<Event>;
Builds and Event from a Message
function exceptionFromError
exceptionFromError: (stackParser: StackParser, ex: Error) => Exception;
This function creates an exception from a JavaScript Error
function forceLoad
forceLoad: () => void;
This function is here to be API compatible with the loader.
function getDefaultIntegrations
getDefaultIntegrations: (options: Options) => Integration[];
Get the default integrations for the browser SDK.
function globalHandlersIntegration
globalHandlersIntegration: ( options?: Partial<GlobalHandlersIntegrations> | undefined) => any;
function httpClientIntegration
httpClientIntegration: (options?: Partial<HttpClientOptions> | undefined) => any;
Create events for failed client side HTTP requests.
function httpContextIntegration
httpContextIntegration: () => any;
Collects information about HTTP request headers and attaches them to the event.
function init
init: (browserOptions?: BrowserOptions) => Client | undefined;
The Sentry Browser SDK Client.
To use this SDK, call the init function as early as possible when loading the web page. To set context information or send manual events, use the provided methods.
Example 1
import { init } from '@sentry/browser';init({dsn: '__DSN__',// ...});Example 2
import { addBreadcrumb } from '@sentry/browser';addBreadcrumb({message: 'My Breadcrumb',// ...});Example 3
import * as Sentry from '@sentry/browser';Sentry.captureMessage('Hello, world!');Sentry.captureException(new Error('Good bye'));Sentry.captureEvent({message: 'Manual',stacktrace: [// ...],});See Also
BrowserOptions for documentation on configuration options.
function instrumentOutgoingRequests
instrumentOutgoingRequests: ( client: Client, _options?: Partial<RequestInstrumentationOptions>) => void;
Registers span creators for xhr and fetch requests
function launchDarklyIntegration
launchDarklyIntegration: () => any;
Sentry integration for capturing feature flags from LaunchDarkly.
See the [feature flag documentation](https://develop.sentry.dev/sdk/expected-features/#feature-flags) for more information.
Example 1
import * as Sentry from '@sentry/browser';import {launchDarklyIntegration, buildLaunchDarklyFlagUsedInspector} from '@sentry/browser';import * as LaunchDarkly from 'launchdarkly-js-client-sdk';Sentry.init(..., integrations: [launchDarklyIntegration()])const ldClient = LaunchDarkly.initialize(..., {inspectors: [buildLaunchDarklyFlagUsedHandler()]});
function lazyLoadIntegration
lazyLoadIntegration: ( name: keyof typeof LazyLoadableIntegrations, scriptNonce?: string) => Promise<IntegrationFn>;
Lazy load an integration from the CDN. Rejects if the integration cannot be loaded.
function linkedErrorsIntegration
linkedErrorsIntegration: (options?: LinkedErrorsOptions | undefined) => any;
Aggregrate linked errors in an event.
function makeBrowserOfflineTransport
makeBrowserOfflineTransport: <T extends BaseTransportOptions>( createTransport?: (options: T) => Transport) => (options: T & BrowserOfflineTransportOptions) => Transport;
Creates a transport that uses IndexedDb to store events when offline.
function makeFetchTransport
makeFetchTransport: ( options: BrowserTransportOptions, nativeFetch?: typeof WINDOW.fetch | undefined) => Transport;
Creates a Transport that uses the Fetch API to send events to Sentry.
function onLoad
onLoad: (callback: () => void) => void;
This function is here to be API compatible with the loader.
function openFeatureIntegration
openFeatureIntegration: () => any;
function reportingObserverIntegration
reportingObserverIntegration: ( options?: ReportingObserverOptions | undefined) => any;
Reporting API integration - https://w3c.github.io/reporting/
function showReportDialog
showReportDialog: (options?: ReportDialogOptions) => void;
Present the user with a report dialog.
Parameter options
Everything is optional, we try to fetch all info need from the global scope.
function spotlightBrowserIntegration
spotlightBrowserIntegration: ( options?: Partial<SpotlightConnectionOptions> | undefined) => any;
Use this integration to send errors and transactions to Spotlight.
Learn more about spotlight at https://spotlightjs.com
function startBrowserTracingNavigationSpan
startBrowserTracingNavigationSpan: ( client: Client, spanOptions: StartSpanOptions) => Span | undefined;
Manually start a navigation span. This will only do something if a browser tracing integration has been setup.
function startBrowserTracingPageLoadSpan
startBrowserTracingPageLoadSpan: ( client: Client, spanOptions: StartSpanOptions, traceOptions?: { sentryTrace?: string | undefined; baggage?: string | undefined }) => Span | undefined;
Manually start a page load span. This will only do something if a browser tracing integration integration has been setup.
If you provide a custom
traceOptions
object, it will be used to continue the trace instead of the default behavior, which is to look it up on the tags.
function unleashIntegration
unleashIntegration: (args_0: { unleashClientClass: UnleashClientClass }) => any;
Sentry integration for capturing feature flag evaluations from the Unleash SDK.
See the [feature flag documentation](https://develop.sentry.dev/sdk/expected-features/#feature-flags) for more information.
Example 1
import { UnleashClient } from 'unleash-proxy-client';import * as Sentry from '@sentry/browser';Sentry.init({dsn: '___PUBLIC_DSN___',integrations: [Sentry.unleashIntegration({unleashClientClass: UnleashClient})],});const unleash = new UnleashClient(...);unleash.start();unleash.isEnabled('my-feature');unleash.getVariant('other-feature');Sentry.captureException(new Error('something went wrong'));
Classes
class BrowserClient
class BrowserClient extends BaseClient<BrowserClientOptions> {}
The Sentry Browser SDK Client.
See Also
BrowserOptions for documentation on configuration options.
SentryClient for usage documentation.
constructor
constructor(options: any);
Creates a new Browser SDK instance.
Parameter options
Configuration options for this SDK.
method captureUserFeedback
captureUserFeedback: (feedback: UserFeedback) => void;
Sends user feedback to Sentry.
Deprecated
Use
captureFeedback
instead.
method eventFromException
eventFromException: (exception: unknown, hint?: EventHint) => PromiseLike<Event>;
method eventFromMessage
eventFromMessage: ( message: ParameterizedString, level?: SeverityLevel, hint?: EventHint) => PromiseLike<Event>;
class OpenFeatureIntegrationHook
class OpenFeatureIntegrationHook implements OpenFeatureHook {}
OpenFeature Hook class implementation.
Interfaces
interface FeatureFlagsIntegration
interface FeatureFlagsIntegration extends Integration {}
property addFeatureFlag
addFeatureFlag: (name: string, value: unknown) => void;
interface ReportDialogOptions
interface ReportDialogOptions {}
All properties the report dialog supports
property dsn
dsn?: DsnLike;
property errorFormEntry
errorFormEntry?: string;
property errorGeneric
errorGeneric?: string;
property eventId
eventId?: string;
property labelClose
labelClose?: string;
property labelComments
labelComments?: string;
property labelEmail
labelEmail?: string;
property labelName
labelName?: string;
property labelSubmit
labelSubmit?: string;
property lang
lang?: string;
property subtitle
subtitle?: string;
property subtitle2
subtitle2?: string;
property successMessage
successMessage?: string;
property title
title?: string;
property user
user?: { email?: string; name?: string;};
method onClose
onClose: (this: void) => void;
Callback after reportDialog closed
method onLoad
onLoad: (this: void) => void;
Callback after reportDialog showed up
index signature
[key: string]: any;
interface RequestInstrumentationOptions
interface RequestInstrumentationOptions {}
Options for Request Instrumentation
property enableHTTPTimings
enableHTTPTimings: boolean;
If true, Sentry will capture http timings and add them to the corresponding http spans.
Default: true
property traceFetch
traceFetch: boolean;
Flag to disable patching all together for fetch requests.
Default: true
property tracePropagationTargets
tracePropagationTargets?: Array<string | RegExp>;
List of strings and/or Regular Expressions used to determine which outgoing requests will have
sentry-trace
andbaggage
headers attached.**Default:** If this option is not provided, tracing headers will be attached to all outgoing requests. If you are using a browser SDK, by default, tracing headers will only be attached to outgoing requests to the same origin.
**Disclaimer:** Carelessly setting this option in browser environments may result into CORS errors! Only attach tracing headers to requests to the same origin, or to requests to services you can control CORS headers of. Cross-origin requests, meaning requests to a different domain, for example a request to
https://api.example.com/
while you're onhttps://example.com/
, take special care. If you are attaching headers to cross-origin requests, make sure the backend handling the request returns a"Access-Control-Allow-Headers: sentry-trace, baggage"
header to ensure your requests aren't blocked.If you provide a
tracePropagationTargets
array, the entries you provide will be matched against the entire URL of the outgoing request. If you are using a browser SDK, the entries will also be matched against the pathname of the outgoing requests. This is so you can have matchers for relative requests, for example,/^\/api/
if you want to trace requests to your/api
routes on the same domain.If any of the two match any of the provided values, tracing headers will be attached to the outgoing request. Both, the string values, and the RegExes you provide in the array will match if they partially match the URL or pathname.
Examples: -
tracePropagationTargets: [/^\/api/]
and request tohttps://same-origin.com/api/posts
: - Tracing headers will be attached because the request is sent to the same origin and the regex matches the pathname "/api/posts". -tracePropagationTargets: [/^\/api/]
and request tohttps://different-origin.com/api/posts
: - Tracing headers will not be attached because the pathname will only be compared when the request target lives on the same origin. -tracePropagationTargets: [/^\/api/, 'https://external-api.com']
and request tohttps://external-api.com/v1/data
: - Tracing headers will be attached because the request URL matches the string'https://external-api.com'
.
property traceXHR
traceXHR: boolean;
Flag to disable patching all together for xhr requests.
Default: true
property trackFetchStreamPerformance
trackFetchStreamPerformance: boolean;
Flag to disable tracking of long-lived streams, like server-sent events (SSE) via fetch. Do not enable this in case you have live streams or very long running streams.
Disabled by default since it can lead to issues with streams using the
cancel()
api (https://github.com/getsentry/sentry-javascript/issues/13950)Default: false
method shouldCreateSpanForRequest
shouldCreateSpanForRequest: (this: void, url: string) => boolean;
This function will be called before creating a span for a request with the given url. Return false if you don't want a span for the given url.
Default: (url: string) => true
Type Aliases
type BrowserOptions
type BrowserOptions = Options<BrowserTransportOptions> & BrowserClientReplayOptions & BrowserClientProfilingOptions & { /** * Important: Only set this option if you know what you are doing! * * By default, the SDK will check if `Sentry.init` is called in a browser extension. * In case it is, it will stop initialization and log a warning * because browser extensions require a different Sentry initialization process: * https://docs.sentry.io/platforms/javascript/best-practices/shared-environments/ * * Setting up the SDK in a browser extension with global error monitoring is not recommended * and will likely flood you with errors from other web sites or extensions. This can heavily * impact your quota and cause interference with your and other Sentry SDKs in shared environments. * * If this check wrongfully flags your setup as a browser extension, you can set this * option to `true` to skip the check. * * @default false */ skipBrowserExtensionCheck?: boolean; };
Configuration options for the Sentry Browser SDK.
See Also
@sentry/core Options for more information.
Package Files (30)
- build/npm/types/client.d.ts
- build/npm/types/eventbuilder.d.ts
- build/npm/types/feedbackAsync.d.ts
- build/npm/types/feedbackSync.d.ts
- build/npm/types/helpers.d.ts
- build/npm/types/index.d.ts
- build/npm/types/integrations/breadcrumbs.d.ts
- build/npm/types/integrations/browserapierrors.d.ts
- build/npm/types/integrations/browsersession.d.ts
- build/npm/types/integrations/contextlines.d.ts
- build/npm/types/integrations/featureFlags/featureFlagsIntegration.d.ts
- build/npm/types/integrations/featureFlags/launchdarkly/integration.d.ts
- build/npm/types/integrations/featureFlags/openfeature/integration.d.ts
- build/npm/types/integrations/featureFlags/unleash/integration.d.ts
- build/npm/types/integrations/globalhandlers.d.ts
- build/npm/types/integrations/httpclient.d.ts
- build/npm/types/integrations/httpcontext.d.ts
- build/npm/types/integrations/linkederrors.d.ts
- build/npm/types/integrations/reportingobserver.d.ts
- build/npm/types/integrations/spotlight.d.ts
- build/npm/types/metrics.d.ts
- build/npm/types/profiling/integration.d.ts
- build/npm/types/sdk.d.ts
- build/npm/types/stack-parsers.d.ts
- build/npm/types/tracing/browserTracingIntegration.d.ts
- build/npm/types/tracing/request.d.ts
- build/npm/types/transports/fetch.d.ts
- build/npm/types/transports/offline.d.ts
- build/npm/types/userfeedback.d.ts
- build/npm/types/utils/lazyLoadIntegration.d.ts
Dependencies (5)
Dev Dependencies (2)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@sentry/browser
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@sentry/browser)
- HTML<a href="https://www.jsdocs.io/package/@sentry/browser"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 4807 ms. - Missing or incorrect documentation? Open an issue for this package.