Skip to content

Commit a80d35a

Browse files
committed
fix prepareEvent
1 parent c34e48c commit a80d35a

File tree

4 files changed

+34
-39
lines changed

4 files changed

+34
-39
lines changed

packages/browser/src/client.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,13 @@ export class BrowserClient extends BaseClient<BrowserClientOptions> {
105105
/**
106106
* @inheritDoc
107107
*/
108-
protected _prepareEvent(event: Event, hint: EventHint, scope?: Scope): PromiseLike<Event | null> {
108+
protected _prepareEvent(
109+
event: Event,
110+
hint: EventHint,
111+
currentScope: Scope,
112+
isolationScope: Scope,
113+
): PromiseLike<Event | null> {
109114
event.platform = event.platform || 'javascript';
110-
return super._prepareEvent(event, hint, scope);
115+
return super._prepareEvent(event, hint, currentScope, isolationScope);
111116
}
112117
}

packages/core/src/baseclient.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,11 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
216216

217217
const sdkProcessingMetadata = event.sdkProcessingMetadata || {};
218218
const capturedSpanScope: Scope | undefined = sdkProcessingMetadata.capturedSpanScope;
219+
const capturedSpanIsolationScope: Scope | undefined = sdkProcessingMetadata.capturedSpanIsolationScope;
219220

220-
this._process(this._captureEvent(event, hintWithEventId, capturedSpanScope || currentScope));
221+
this._process(
222+
this._captureEvent(event, hintWithEventId, capturedSpanScope || currentScope, capturedSpanIsolationScope),
223+
);
221224

222225
return hintWithEventId.event_id;
223226
}
@@ -676,8 +679,8 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
676679
protected _prepareEvent(
677680
event: Event,
678681
hint: EventHint,
679-
currentScope = getCurrentScope(),
680-
isolationScope = getIsolationScope(),
682+
currentScope: Scope,
683+
isolationScope: Scope,
681684
): PromiseLike<Event | null> {
682685
const options = this.getOptions();
683686
const integrations = Object.keys(this._integrations);
@@ -718,12 +721,17 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
718721
* @param hint
719722
* @param scope
720723
*/
721-
protected _captureEvent(event: Event, hint: EventHint = {}, scope?: Scope): PromiseLike<string | undefined> {
724+
protected _captureEvent(
725+
event: Event,
726+
hint: EventHint = {},
727+
currentScope = getCurrentScope(),
728+
isolationScope = getIsolationScope(),
729+
): PromiseLike<string | undefined> {
722730
if (DEBUG_BUILD && isErrorEvent(event)) {
723731
logger.log(`Captured error event \`${getPossibleEventMessages(event)[0] || '<unknown>'}\``);
724732
}
725733

726-
return this._processEvent(event, hint, scope).then(
734+
return this._processEvent(event, hint, currentScope, isolationScope).then(
727735
finalEvent => {
728736
return finalEvent.event_id;
729737
},
@@ -756,7 +764,12 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
756764
* @param currentScope A scope containing event metadata.
757765
* @returns A SyncPromise that resolves with the event or rejects in case event was/will not be send.
758766
*/
759-
protected _processEvent(event: Event, hint: EventHint, currentScope?: Scope): PromiseLike<Event> {
767+
protected _processEvent(
768+
event: Event,
769+
hint: EventHint,
770+
currentScope: Scope,
771+
isolationScope: Scope,
772+
): PromiseLike<Event> {
760773
const options = this.getOptions();
761774
const { sampleRate } = options;
762775

@@ -779,12 +792,9 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
779792
);
780793
}
781794

782-
const dataCategory: DataCategory = eventType === 'replay_event' ? 'replay' : eventType;
783-
784-
const sdkProcessingMetadata = event.sdkProcessingMetadata || {};
785-
const capturedSpanIsolationScope: Scope | undefined = sdkProcessingMetadata.capturedSpanIsolationScope;
795+
const dataCategory = (eventType === 'replay_event' ? 'replay' : eventType) satisfies DataCategory;
786796

787-
return this._prepareEvent(event, hint, currentScope, capturedSpanIsolationScope)
797+
return this._prepareEvent(event, hint, currentScope, isolationScope)
788798
.then(prepared => {
789799
if (prepared === null) {
790800
this.recordDroppedEvent('event_processor', dataCategory, event);
@@ -811,7 +821,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
811821
throw new SentryError(`${beforeSendLabel} returned \`null\`, will not send event.`, 'log');
812822
}
813823

814-
const session = currentScope && currentScope.getSession();
824+
const session = currentScope.getSession() || isolationScope.getSession();
815825
if (!isTransaction && session) {
816826
this._updateSessionFromEvent(session, processedEvent);
817827
}

packages/core/src/getCurrentHubShim.ts

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { addBreadcrumb } from './breadcrumbs';
22
import { getClient, getCurrentScope, getIsolationScope, withScope } from './currentScopes';
33
import {
44
captureEvent,
5+
captureSession,
56
endSession,
67
setContext,
78
setExtra,
@@ -55,15 +56,7 @@ export function getCurrentHubShim(): Hub {
5556

5657
startSession,
5758
endSession,
58-
captureSession(end?: boolean): void {
59-
// both send the update and pull the session from the scope
60-
if (end) {
61-
return endSession();
62-
}
63-
64-
// only send the update
65-
_sendSessionUpdate();
66-
},
59+
captureSession,
6760
};
6861
}
6962

@@ -78,16 +71,3 @@ export function getCurrentHubShim(): Hub {
7871
*/
7972
// eslint-disable-next-line deprecation/deprecation
8073
export const getCurrentHub = getCurrentHubShim;
81-
82-
/**
83-
* Sends the current Session on the scope
84-
*/
85-
function _sendSessionUpdate(): void {
86-
const scope = getIsolationScope();
87-
const client = getClient();
88-
89-
const session = scope.getSession();
90-
if (client && session) {
91-
client.captureSession(session);
92-
}
93-
}

packages/core/src/server-runtime-client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ export class ServerRuntimeClient<
166166
protected _prepareEvent(
167167
event: Event,
168168
hint: EventHint,
169-
scope?: Scope,
170-
isolationScope?: Scope,
169+
currentScope: Scope,
170+
isolationScope: Scope,
171171
): PromiseLike<Event | null> {
172172
if (this._options.platform) {
173173
event.platform = event.platform || this._options.platform;
@@ -184,7 +184,7 @@ export class ServerRuntimeClient<
184184
event.server_name = event.server_name || this._options.serverName;
185185
}
186186

187-
return super._prepareEvent(event, hint, scope, isolationScope);
187+
return super._prepareEvent(event, hint, currentScope, isolationScope);
188188
}
189189

190190
/** Extract trace information from scope */

0 commit comments

Comments
 (0)