-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
ref(browser): Don't use Breadcrumbs integration in send event flow #5024
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ | ||
/* eslint-disable max-lines */ | ||
import { getCurrentHub } from '@sentry/core'; | ||
import { Event, Integration } from '@sentry/types'; | ||
import { Integration } from '@sentry/types'; | ||
import { | ||
addInstrumentationHandler, | ||
getEventDescription, | ||
getGlobalObject, | ||
htmlTreeAsString, | ||
parseUrl, | ||
|
@@ -22,6 +21,8 @@ interface BreadcrumbsOptions { | |
xhr: boolean; | ||
} | ||
|
||
export const BREADCRUMB_INTEGRATION_ID = 'Breadcrumbs'; | ||
|
||
/** | ||
* Default Breadcrumbs instrumentations | ||
* TODO: Deprecated - with v6, this will be renamed to `Instrument` | ||
|
@@ -30,21 +31,24 @@ export class Breadcrumbs implements Integration { | |
/** | ||
* @inheritDoc | ||
*/ | ||
public static id: string = 'Breadcrumbs'; | ||
public static id: string = BREADCRUMB_INTEGRATION_ID; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public name: string = Breadcrumbs.id; | ||
|
||
/** JSDoc */ | ||
private readonly _options: BreadcrumbsOptions; | ||
/** | ||
* Options of the breadcrumbs integration. | ||
*/ | ||
// This field is public, because we use it in the browser client to check if the `sentry` option is enabled. | ||
public readonly options: Readonly<BreadcrumbsOptions>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This now means that |
||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public constructor(options?: Partial<BreadcrumbsOptions>) { | ||
this._options = { | ||
this.options = { | ||
console: true, | ||
dom: true, | ||
fetch: true, | ||
|
@@ -55,26 +59,6 @@ export class Breadcrumbs implements Integration { | |
}; | ||
} | ||
|
||
/** | ||
* Create a breadcrumb of `sentry` from the events themselves | ||
*/ | ||
public addSentryBreadcrumb(event: Event): void { | ||
if (!this._options.sentry) { | ||
return; | ||
} | ||
getCurrentHub().addBreadcrumb( | ||
{ | ||
category: `sentry.${event.type === 'transaction' ? 'transaction' : 'event'}`, | ||
event_id: event.event_id, | ||
level: event.level, | ||
message: getEventDescription(event), | ||
}, | ||
{ | ||
event, | ||
}, | ||
); | ||
} | ||
|
||
/** | ||
* Instrument browser built-ins w/ breadcrumb capturing | ||
* - Console API | ||
|
@@ -84,19 +68,19 @@ export class Breadcrumbs implements Integration { | |
* - History API | ||
*/ | ||
public setupOnce(): void { | ||
if (this._options.console) { | ||
if (this.options.console) { | ||
addInstrumentationHandler('console', _consoleBreadcrumb); | ||
} | ||
if (this._options.dom) { | ||
addInstrumentationHandler('dom', _domBreadcrumb(this._options.dom)); | ||
if (this.options.dom) { | ||
addInstrumentationHandler('dom', _domBreadcrumb(this.options.dom)); | ||
} | ||
if (this._options.xhr) { | ||
if (this.options.xhr) { | ||
addInstrumentationHandler('xhr', _xhrBreadcrumb); | ||
} | ||
if (this._options.fetch) { | ||
if (this.options.fetch) { | ||
addInstrumentationHandler('fetch', _fetchBreadcrumb); | ||
} | ||
if (this._options.history) { | ||
if (this.options.history) { | ||
addInstrumentationHandler('history', _historyBreadcrumb); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -258,6 +258,15 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> { | |||||
} | ||||||
} | ||||||
|
||||||
/** | ||||||
* Gets an installed integration by its `id`. | ||||||
* | ||||||
* @returns The installed integration or `undefined` if no integration with that `id` was installed. | ||||||
*/ | ||||||
public getIntegrationById(integrationId: string): Integration | undefined { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about making this should be generic over an Integration? This means the caller can define the value without needing a cast.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Honestly, I do not like it. I do not want to help people to disable TS checks. If you are sure that your code is right go ahead and cast it, because that is way more explicitly saying that you're doing some dangerous stuff than using a generic, which kind of hides the danger... |
||||||
return this._integrations[integrationId]; | ||||||
} | ||||||
|
||||||
/** | ||||||
* @inheritDoc | ||||||
*/ | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while I do now notice that there's a space missing I think this should actually be "its" because "it is" would definitely not fit here