Skip to content

Commit aadbcb9

Browse files
committed
fix circular dependency
1 parent df0283d commit aadbcb9

File tree

5 files changed

+147
-145
lines changed

5 files changed

+147
-145
lines changed

packages/core/src/scope.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import type {
2424
import { dateTimestampInSeconds, generatePropagationContext, isPlainObject, logger, uuid4 } from '@sentry/utils';
2525

2626
import { updateSession } from './session';
27-
import { mergeSdkProcessingMetadata } from './utils/applyScopeDataToEvent';
27+
import { mergeSdkProcessingMetadata } from './utils/mergeSdkProcessingMetadata';
2828
import { _getSpanForScope, _setSpanForScope } from './utils/spanOnScope';
2929

3030
/**

packages/core/src/utils/applyScopeDataToEvent.ts

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Breadcrumb, Event, ScopeData, Span } from '@sentry/types';
22
import { arrayify, dropUndefinedKeys } from '@sentry/utils';
33
import { getDynamicSamplingContextFromSpan } from '../tracing/dynamicSamplingContext';
4+
import { mergeSdkProcessingMetadata } from './mergeSdkProcessingMetadata';
45
import { getRootSpan, spanToJSON, spanToTraceContext } from './spanUtils';
56

67
/**
@@ -116,35 +117,6 @@ export function mergeArray<Prop extends 'breadcrumbs' | 'fingerprint'>(
116117
event[prop] = merged.length ? merged : undefined;
117118
}
118119

119-
/**
120-
* Merge new SDK processing metadata into existing data.
121-
* New data will overwrite existing data.
122-
* `normalizedRequest` is special handled and will also be merged.
123-
*/
124-
export function mergeSdkProcessingMetadata(
125-
sdkProcessingMetadata: ScopeData['sdkProcessingMetadata'],
126-
newSdkProcessingMetadata: ScopeData['sdkProcessingMetadata'],
127-
): ScopeData['sdkProcessingMetadata'] {
128-
// We want to merge `normalizedRequest` to avoid some partial entry on the scope
129-
// overwriting potentially more complete data on the isolation scope
130-
const normalizedRequestBefore = sdkProcessingMetadata['normalizedRequest'];
131-
const normalizedRequest = newSdkProcessingMetadata['normalizedRequest'];
132-
133-
const newData = {
134-
...sdkProcessingMetadata,
135-
...newSdkProcessingMetadata,
136-
};
137-
138-
if (normalizedRequestBefore || normalizedRequest) {
139-
newData['normalizedRequest'] = {
140-
...(normalizedRequestBefore || {}),
141-
...(normalizedRequest || {}),
142-
};
143-
}
144-
145-
return newData;
146-
}
147-
148120
function applyDataToEvent(event: Event, data: ScopeData): void {
149121
const { extra, tags, user, contexts, level, transactionName } = data;
150122

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import type { ScopeData } from '@sentry/types';
2+
3+
/**
4+
* Merge new SDK processing metadata into existing data.
5+
* New data will overwrite existing data.
6+
* `normalizedRequest` is special handled and will also be merged.
7+
*/
8+
export function mergeSdkProcessingMetadata(
9+
sdkProcessingMetadata: ScopeData['sdkProcessingMetadata'],
10+
newSdkProcessingMetadata: ScopeData['sdkProcessingMetadata'],
11+
): ScopeData['sdkProcessingMetadata'] {
12+
// We want to merge `normalizedRequest` to avoid some partial entry on the scope
13+
// overwriting potentially more complete data on the isolation scope
14+
const normalizedRequestBefore = sdkProcessingMetadata['normalizedRequest'];
15+
const normalizedRequest = newSdkProcessingMetadata['normalizedRequest'];
16+
17+
const newData = {
18+
...sdkProcessingMetadata,
19+
...newSdkProcessingMetadata,
20+
};
21+
22+
if (normalizedRequestBefore || normalizedRequest) {
23+
newData['normalizedRequest'] = {
24+
...(normalizedRequestBefore || {}),
25+
...(normalizedRequest || {}),
26+
};
27+
}
28+
29+
return newData;
30+
}

packages/core/test/lib/utils/applyScopeDataToEvent.test.ts

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
mergeAndOverwriteScopeData,
66
mergeArray,
77
mergeScopeData,
8-
mergeSdkProcessingMetadata,
98
} from '../../../src/utils/applyScopeDataToEvent';
109

1110
describe('mergeArray', () => {
@@ -194,120 +193,6 @@ describe('mergeScopeData', () => {
194193
});
195194
});
196195

197-
describe('mergeSdkProcessingMetadata', () => {
198-
it('works with empty objects', () => {
199-
const oldData = {};
200-
const newData = {};
201-
202-
const actual = mergeSdkProcessingMetadata(oldData, newData);
203-
204-
expect(actual).toEqual({});
205-
expect(actual).not.toBe(oldData);
206-
expect(actual).not.toBe(newData);
207-
});
208-
209-
it('works with arbitrary data', () => {
210-
const oldData = {
211-
old1: 'old1',
212-
old2: 'old2',
213-
obj: { key: 'value' },
214-
};
215-
const newData = {
216-
new1: 'new1',
217-
old2: 'new2',
218-
obj: { key2: 'value2' },
219-
};
220-
221-
const actual = mergeSdkProcessingMetadata(oldData, newData);
222-
223-
expect(actual).toEqual({
224-
old1: 'old1',
225-
old2: 'new2',
226-
new1: 'new1',
227-
obj: { key2: 'value2' },
228-
});
229-
expect(actual).not.toBe(oldData);
230-
expect(actual).not.toBe(newData);
231-
});
232-
233-
it('merges normalizedRequest', () => {
234-
const oldData = {
235-
old1: 'old1',
236-
normalizedRequest: {
237-
url: 'oldUrl',
238-
method: 'oldMethod',
239-
},
240-
};
241-
const newData = {
242-
new1: 'new1',
243-
normalizedRequest: {
244-
url: 'newUrl',
245-
headers: {},
246-
},
247-
};
248-
249-
const actual = mergeSdkProcessingMetadata(oldData, newData);
250-
251-
expect(actual).toEqual({
252-
old1: 'old1',
253-
new1: 'new1',
254-
normalizedRequest: {
255-
url: 'newUrl',
256-
method: 'oldMethod',
257-
headers: {},
258-
},
259-
});
260-
});
261-
262-
it('keeps existing normalizedRequest', () => {
263-
const oldData = {
264-
old1: 'old1',
265-
normalizedRequest: {
266-
url: 'oldUrl',
267-
method: 'oldMethod',
268-
},
269-
};
270-
const newData = {
271-
new1: 'new1',
272-
};
273-
274-
const actual = mergeSdkProcessingMetadata(oldData, newData);
275-
276-
expect(actual).toEqual({
277-
old1: 'old1',
278-
new1: 'new1',
279-
normalizedRequest: {
280-
url: 'oldUrl',
281-
method: 'oldMethod',
282-
},
283-
});
284-
});
285-
286-
it('adds new normalizedRequest', () => {
287-
const oldData = {
288-
old1: 'old1',
289-
};
290-
const newData = {
291-
new1: 'new1',
292-
normalizedRequest: {
293-
url: 'newUrl',
294-
method: 'newMethod',
295-
},
296-
};
297-
298-
const actual = mergeSdkProcessingMetadata(oldData, newData);
299-
300-
expect(actual).toEqual({
301-
old1: 'old1',
302-
new1: 'new1',
303-
normalizedRequest: {
304-
url: 'newUrl',
305-
method: 'newMethod',
306-
},
307-
});
308-
});
309-
});
310-
311196
describe('applyScopeDataToEvent', () => {
312197
it("doesn't apply scope.transactionName to transaction events", () => {
313198
const data: ScopeData = {
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import { mergeSdkProcessingMetadata } from '../../../src/utils/mergeSdkProcessingMetadata';
2+
3+
describe('mergeSdkProcessingMetadata', () => {
4+
it('works with empty objects', () => {
5+
const oldData = {};
6+
const newData = {};
7+
8+
const actual = mergeSdkProcessingMetadata(oldData, newData);
9+
10+
expect(actual).toEqual({});
11+
expect(actual).not.toBe(oldData);
12+
expect(actual).not.toBe(newData);
13+
});
14+
15+
it('works with arbitrary data', () => {
16+
const oldData = {
17+
old1: 'old1',
18+
old2: 'old2',
19+
obj: { key: 'value' },
20+
};
21+
const newData = {
22+
new1: 'new1',
23+
old2: 'new2',
24+
obj: { key2: 'value2' },
25+
};
26+
27+
const actual = mergeSdkProcessingMetadata(oldData, newData);
28+
29+
expect(actual).toEqual({
30+
old1: 'old1',
31+
old2: 'new2',
32+
new1: 'new1',
33+
obj: { key2: 'value2' },
34+
});
35+
expect(actual).not.toBe(oldData);
36+
expect(actual).not.toBe(newData);
37+
});
38+
39+
it('merges normalizedRequest', () => {
40+
const oldData = {
41+
old1: 'old1',
42+
normalizedRequest: {
43+
url: 'oldUrl',
44+
method: 'oldMethod',
45+
},
46+
};
47+
const newData = {
48+
new1: 'new1',
49+
normalizedRequest: {
50+
url: 'newUrl',
51+
headers: {},
52+
},
53+
};
54+
55+
const actual = mergeSdkProcessingMetadata(oldData, newData);
56+
57+
expect(actual).toEqual({
58+
old1: 'old1',
59+
new1: 'new1',
60+
normalizedRequest: {
61+
url: 'newUrl',
62+
method: 'oldMethod',
63+
headers: {},
64+
},
65+
});
66+
});
67+
68+
it('keeps existing normalizedRequest', () => {
69+
const oldData = {
70+
old1: 'old1',
71+
normalizedRequest: {
72+
url: 'oldUrl',
73+
method: 'oldMethod',
74+
},
75+
};
76+
const newData = {
77+
new1: 'new1',
78+
};
79+
80+
const actual = mergeSdkProcessingMetadata(oldData, newData);
81+
82+
expect(actual).toEqual({
83+
old1: 'old1',
84+
new1: 'new1',
85+
normalizedRequest: {
86+
url: 'oldUrl',
87+
method: 'oldMethod',
88+
},
89+
});
90+
});
91+
92+
it('adds new normalizedRequest', () => {
93+
const oldData = {
94+
old1: 'old1',
95+
};
96+
const newData = {
97+
new1: 'new1',
98+
normalizedRequest: {
99+
url: 'newUrl',
100+
method: 'newMethod',
101+
},
102+
};
103+
104+
const actual = mergeSdkProcessingMetadata(oldData, newData);
105+
106+
expect(actual).toEqual({
107+
old1: 'old1',
108+
new1: 'new1',
109+
normalizedRequest: {
110+
url: 'newUrl',
111+
method: 'newMethod',
112+
},
113+
});
114+
});
115+
});

0 commit comments

Comments
 (0)