Skip to content

Commit 0a4b49f

Browse files
committed
fix for node-experimental
1 parent 9b5bcb5 commit 0a4b49f

File tree

2 files changed

+19
-79
lines changed

2 files changed

+19
-79
lines changed

packages/node-experimental/src/sdk/scope.ts

Lines changed: 12 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
import { notifyEventProcessors } from '@sentry/core';
21
import { OpenTelemetryScope } from '@sentry/opentelemetry';
3-
import type {
4-
Attachment,
5-
Breadcrumb,
6-
Client,
7-
Event,
8-
EventHint,
9-
EventProcessor,
10-
Severity,
11-
SeverityLevel,
12-
} from '@sentry/types';
2+
import type { Attachment, Breadcrumb, Client, Event, EventHint, Severity, SeverityLevel } from '@sentry/types';
133
import { uuid4 } from '@sentry/utils';
144

155
import { getGlobalCarrier } from './globals';
@@ -116,13 +106,7 @@ export class Scope extends OpenTelemetryScope implements ScopeInterface {
116106

117107
/** @inheritdoc */
118108
public getAttachments(): Attachment[] {
119-
const data = getGlobalScope().getScopeData();
120-
const isolationScopeData = this._getIsolationScope().getScopeData();
121-
const scopeData = this.getScopeData();
122-
123-
// Merge data together, in order
124-
mergeData(data, isolationScopeData);
125-
mergeData(data, scopeData);
109+
const data = this.getScopeData();
126110

127111
return data.attachments;
128112
}
@@ -200,7 +184,7 @@ export class Scope extends OpenTelemetryScope implements ScopeInterface {
200184
}
201185

202186
/** Get all relevant data for this scope. */
203-
public getScopeData(): ScopeData {
187+
public getPerScopeData(): ScopeData {
204188
const {
205189
_breadcrumbs,
206190
_attachments,
@@ -230,63 +214,17 @@ export class Scope extends OpenTelemetryScope implements ScopeInterface {
230214
};
231215
}
232216

233-
/**
234-
* Applies data from the scope to the event and runs all event processors on it.
235-
*
236-
* @param event Event
237-
* @param hint Object containing additional information about the original exception, for use by the event processors.
238-
* @hidden
239-
*/
240-
public applyToEvent(
241-
event: Event,
242-
hint: EventHint = {},
243-
additionalEventProcessors: EventProcessor[] = [],
244-
): PromiseLike<Event | null> {
245-
const data = getGlobalScope().getScopeData();
246-
const isolationScopeData = this._getIsolationScope().getScopeData();
247-
const scopeData = this.getScopeData();
217+
/** @inheritdoc */
218+
public getScopeData(): ScopeData {
219+
const data = getGlobalScope().getPerScopeData();
220+
const isolationScopeData = this._getIsolationScope().getPerScopeData();
221+
const scopeData = this.getPerScopeData();
248222

249223
// Merge data together, in order
250224
mergeData(data, isolationScopeData);
251225
mergeData(data, scopeData);
252226

253-
// Apply the data
254-
const { extra, tags, user, contexts, level, sdkProcessingMetadata, breadcrumbs, fingerprint, eventProcessors } =
255-
data;
256-
257-
mergePropKeep(event, 'extra', extra);
258-
mergePropKeep(event, 'tags', tags);
259-
mergePropKeep(event, 'user', user);
260-
mergePropKeep(event, 'contexts', contexts);
261-
mergePropKeep(event, 'sdkProcessingMetadata', sdkProcessingMetadata);
262-
event.sdkProcessingMetadata = {
263-
...event.sdkProcessingMetadata,
264-
propagationContext: this._propagationContext,
265-
};
266-
267-
mergeArray(event, 'breadcrumbs', breadcrumbs);
268-
mergeArray(event, 'fingerprint', fingerprint);
269-
270-
if (level) {
271-
event.level = level;
272-
}
273-
274-
const allEventProcessors = [...additionalEventProcessors, ...eventProcessors];
275-
276-
// Apply additional things to the event
277-
if (this._transactionName) {
278-
event.transaction = this._transactionName;
279-
}
280-
281-
return notifyEventProcessors(allEventProcessors, event, hint);
282-
}
283-
284-
/**
285-
* Get all breadcrumbs attached to this scope.
286-
* @internal
287-
*/
288-
public getBreadcrumbs(): Breadcrumb[] {
289-
return this._breadcrumbs;
227+
return data;
290228
}
291229

292230
/** Get the isolation scope for this scope. */
@@ -308,6 +246,7 @@ export function mergeData(data: ScopeData, mergeData: ScopeData): void {
308246
fingerprint,
309247
eventProcessors,
310248
attachments,
249+
propagationContext,
311250
} = mergeData;
312251

313252
mergePropOverwrite(data, 'extra', extra);
@@ -335,6 +274,8 @@ export function mergeData(data: ScopeData, mergeData: ScopeData): void {
335274
if (attachments.length) {
336275
data.attachments = [...data.attachments, ...attachments];
337276
}
277+
278+
data.propagationContext = { ...data.propagationContext, ...propagationContext };
338279
}
339280

340281
/**

packages/node-experimental/test/sdk/scope.test.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { applyScopeDataToEvent } from '@sentry/core';
12
import type { Attachment, Breadcrumb, Client, EventProcessor } from '@sentry/types';
23
import { Scope, getIsolationScope } from '../../src';
34
import { getGlobalScope, mergeArray, mergeData, mergePropKeep, mergePropOverwrite } from '../../src/sdk/scope';
@@ -295,8 +296,7 @@ describe('Unit | Scope', () => {
295296
extra: { extra1: 'aa', extra2: 'bb', extra3: 'bb' },
296297
contexts: { os: { name: 'os2' }, culture: { display_name: 'name1' } },
297298
attachments: [attachment1, attachment2, attachment3],
298-
// This is not merged, we always use the one from the scope here anyhow
299-
propagationContext: { spanId: '1', traceId: '1' },
299+
propagationContext: { spanId: '2', traceId: '2' },
300300
sdkProcessingMetadata: { aa: 'aa', bb: 'bb', cc: 'bb' },
301301
fingerprint: ['aa', 'bb', 'cc'],
302302
});
@@ -309,7 +309,8 @@ describe('Unit | Scope', () => {
309309

310310
const scope = new Scope();
311311

312-
const event = await scope.applyToEvent({ message: 'foo' });
312+
const event = { message: 'foo' };
313+
applyScopeDataToEvent(event, scope.getScopeData());
313314

314315
expect(event).toEqual({
315316
message: 'foo',
@@ -357,11 +358,9 @@ describe('Unit | Scope', () => {
357358
isolationScope.addEventProcessor(eventProcessor3);
358359
globalScope.setSDKProcessingMetadata({ bb: 'bb' });
359360

360-
const event = await scope.applyToEvent({
361-
message: 'foo',
362-
breadcrumbs: [breadcrumb4],
363-
fingerprint: ['dd'],
364-
});
361+
const event = { message: 'foo', breadcrumbs: [breadcrumb4], fingerprint: ['dd'] };
362+
363+
applyScopeDataToEvent(event, scope.getScopeData());
365364

366365
expect(event).toEqual({
367366
message: 'foo',

0 commit comments

Comments
 (0)