11/* eslint-disable @typescript-eslint/no-unsafe-member-access */
22/* eslint-disable max-lines */
33import { getCurrentHub } from '@sentry/core' ;
4- import { Event , Integration } from '@sentry/types' ;
4+ import { Integration } from '@sentry/types' ;
55import {
66 addInstrumentationHandler ,
7- getEventDescription ,
87 getGlobalObject ,
98 htmlTreeAsString ,
109 parseUrl ,
@@ -22,6 +21,8 @@ interface BreadcrumbsOptions {
2221 xhr : boolean ;
2322}
2423
24+ export const BREADCRUMB_INTEGRATION_ID = 'Breadcrumbs' ;
25+
2526/**
2627 * Default Breadcrumbs instrumentations
2728 * TODO: Deprecated - with v6, this will be renamed to `Instrument`
@@ -30,21 +31,24 @@ export class Breadcrumbs implements Integration {
3031 /**
3132 * @inheritDoc
3233 */
33- public static id : string = 'Breadcrumbs' ;
34+ public static id : string = BREADCRUMB_INTEGRATION_ID ;
3435
3536 /**
3637 * @inheritDoc
3738 */
3839 public name : string = Breadcrumbs . id ;
3940
40- /** JSDoc */
41- private readonly _options : BreadcrumbsOptions ;
41+ /**
42+ * Options of the breadcrumbs integration.
43+ */
44+ // This field is public, because we use it in the browser client to check if the `sentry` option is enabled.
45+ public readonly options : Readonly < BreadcrumbsOptions > ;
4246
4347 /**
4448 * @inheritDoc
4549 */
4650 public constructor ( options ?: Partial < BreadcrumbsOptions > ) {
47- this . _options = {
51+ this . options = {
4852 console : true ,
4953 dom : true ,
5054 fetch : true ,
@@ -55,26 +59,6 @@ export class Breadcrumbs implements Integration {
5559 } ;
5660 }
5761
58- /**
59- * Create a breadcrumb of `sentry` from the events themselves
60- */
61- public addSentryBreadcrumb ( event : Event ) : void {
62- if ( ! this . _options . sentry ) {
63- return ;
64- }
65- getCurrentHub ( ) . addBreadcrumb (
66- {
67- category : `sentry.${ event . type === 'transaction' ? 'transaction' : 'event' } ` ,
68- event_id : event . event_id ,
69- level : event . level ,
70- message : getEventDescription ( event ) ,
71- } ,
72- {
73- event,
74- } ,
75- ) ;
76- }
77-
7862 /**
7963 * Instrument browser built-ins w/ breadcrumb capturing
8064 * - Console API
@@ -84,19 +68,19 @@ export class Breadcrumbs implements Integration {
8468 * - History API
8569 */
8670 public setupOnce ( ) : void {
87- if ( this . _options . console ) {
71+ if ( this . options . console ) {
8872 addInstrumentationHandler ( 'console' , _consoleBreadcrumb ) ;
8973 }
90- if ( this . _options . dom ) {
91- addInstrumentationHandler ( 'dom' , _domBreadcrumb ( this . _options . dom ) ) ;
74+ if ( this . options . dom ) {
75+ addInstrumentationHandler ( 'dom' , _domBreadcrumb ( this . options . dom ) ) ;
9276 }
93- if ( this . _options . xhr ) {
77+ if ( this . options . xhr ) {
9478 addInstrumentationHandler ( 'xhr' , _xhrBreadcrumb ) ;
9579 }
96- if ( this . _options . fetch ) {
80+ if ( this . options . fetch ) {
9781 addInstrumentationHandler ( 'fetch' , _fetchBreadcrumb ) ;
9882 }
99- if ( this . _options . history ) {
83+ if ( this . options . history ) {
10084 addInstrumentationHandler ( 'history' , _historyBreadcrumb ) ;
10185 }
10286 }
0 commit comments