Skip to content
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

fix(browser): Reassign lastEventId while eliminating duplicate events. #4021

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/browser/src/integrations/dedupe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ export class Dedupe implements Integration {
*/
public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void {
addGlobalEventProcessor((currentEvent: Event) => {
const self = getCurrentHub().getIntegration(Dedupe);
const hub = getCurrentHub();
const self = hub.getIntegration(Dedupe);

if (self) {
// Juuust in case something goes wrong
try {
if (self._shouldDropEvent(currentEvent, self._previousEvent)) {
if (self._previousEvent?.event_id) {
hub.setLastEventId(self._previousEvent?.event_id);
}
logger.warn(`Event dropped due to being a duplicate of previously captured event.`);
return null;
}
Expand Down
13 changes: 10 additions & 3 deletions packages/hub/src/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export class Hub implements HubInterface {
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
public captureException(exception: any, hint?: EventHint): string {
const eventId = (this._lastEventId = uuid4());
const eventId = this.setLastEventId(uuid4());
let finalHint = hint;

// If there's no explicit hint provided, mimic the same thing that would happen
Expand Down Expand Up @@ -217,7 +217,7 @@ export class Hub implements HubInterface {
* @inheritDoc
*/
public captureMessage(message: string, level?: Severity, hint?: EventHint): string {
const eventId = (this._lastEventId = uuid4());
const eventId = this.setLastEventId(uuid4());
let finalHint = hint;

// If there's no explicit hint provided, mimic the same thing that would happen
Expand Down Expand Up @@ -250,7 +250,7 @@ export class Hub implements HubInterface {
public captureEvent(event: Event, hint?: EventHint): string {
const eventId = uuid4();
if (event.type !== 'transaction') {
this._lastEventId = eventId;
this.setLastEventId(eventId);
}

this._invokeClient('captureEvent', event, {
Expand All @@ -267,6 +267,13 @@ export class Hub implements HubInterface {
return this._lastEventId;
}

/**
* @inheritDoc
*/
public setLastEventId(id: string): string {
return (this._lastEventId = id);
}

/**
* @inheritDoc
*/
Expand Down
7 changes: 7 additions & 0 deletions packages/types/src/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ export interface Hub {
*/
addBreadcrumb(breadcrumb: Breadcrumb, hint?: BreadcrumbHint): void;

/**
* This is the setter for lastEventId.
*
* @returns The event id which has set.
*/
setLastEventId(id: string): string;
onurtemizkan marked this conversation as resolved.
Show resolved Hide resolved

/**
* Updates user context information for future events.
*
Expand Down