Skip to content

Commit 5b58d6c

Browse files
committed
Revert "expose proper util to set normalized request"
This reverts commit 11150d2.
1 parent 11150d2 commit 5b58d6c

File tree

7 files changed

+28
-27
lines changed

7 files changed

+28
-27
lines changed

packages/core/src/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ export { hasTracingEnabled } from './utils/hasTracingEnabled';
6868
export { isSentryRequestUrl } from './utils/isSentryRequestUrl';
6969
export { handleCallbackErrors } from './utils/handleCallbackErrors';
7070
export { parameterize } from './utils/parameterize';
71-
export { setNormalizedRequest } from './utils/sdkProcessingMetadata';
7271
export {
7372
spanToTraceHeader,
7473
spanToJSON,

packages/core/src/scope.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +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/mergeSdkProcessingMetadata';
2728
import { _getSpanForScope, _setSpanForScope } from './utils/spanOnScope';
2829

2930
/**
@@ -479,7 +480,7 @@ class ScopeClass implements ScopeInterface {
479480
* @inheritDoc
480481
*/
481482
public setSDKProcessingMetadata(newData: { [key: string]: unknown }): this {
482-
this._sdkProcessingMetadata = { ...this._sdkProcessingMetadata, ...newData };
483+
this._sdkProcessingMetadata = mergeSdkProcessingMetadata(this._sdkProcessingMetadata, newData);
483484
return this;
484485
}
485486

packages/core/src/utils/applyScopeDataToEvent.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +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 './sdkProcessingMetadata';
4+
import { mergeSdkProcessingMetadata } from './mergeSdkProcessingMetadata';
55
import { getRootSpan, spanToJSON, spanToTraceContext } from './spanUtils';
66

77
/**

packages/core/src/utils/sdkProcessingMetadata.ts renamed to packages/core/src/utils/mergeSdkProcessingMetadata.ts

+1-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import type { Request, ScopeData } from '@sentry/types';
2-
import { getIsolationScope } from '../currentScopes';
1+
import type { ScopeData } from '@sentry/types';
32

43
/**
54
* Merge new SDK processing metadata into existing data.
@@ -29,19 +28,3 @@ export function mergeSdkProcessingMetadata(
2928

3029
return newData;
3130
}
32-
33-
/**
34-
* Set a normalizedRequest on the scope, ensuring it merges with potentially existing request data.
35-
* By default, this will put this data on the isolation scope,
36-
* but you can also pass a different scope to set the data on.
37-
*/
38-
export function setNormalizedRequest(normalizedRequest: Request, scope = getIsolationScope()): void {
39-
const normalizedRequestBefore = scope.getScopeData().sdkProcessingMetadata['normalizedRequest'];
40-
41-
const newNormalizedRequest = {
42-
...(normalizedRequestBefore || {}),
43-
...normalizedRequest,
44-
} satisfies Request;
45-
46-
scope.setSDKProcessingMetadata({ normalizedRequest: newNormalizedRequest });
47-
}

packages/core/test/lib/scope.test.ts

+21-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ describe('Scope', () => {
211211
expect(scope['_sdkProcessingMetadata'].dogs).toEqual('are great!');
212212
});
213213

214-
test('it overwrites data', () => {
214+
test('it overwrites arbitrary data', () => {
215215
const scope = new Scope();
216216
scope.setSDKProcessingMetadata({ dogs: 'are great!' });
217217
scope.setSDKProcessingMetadata({ dogs: 'are really great!' });
@@ -225,6 +225,26 @@ describe('Scope', () => {
225225
obj: { nested2: 'value2' },
226226
});
227227
});
228+
229+
test('it merges normalizedRequest data', () => {
230+
const scope = new Scope();
231+
scope.setSDKProcessingMetadata({
232+
normalizedRequest: {
233+
url: 'value1',
234+
method: 'value1',
235+
},
236+
});
237+
scope.setSDKProcessingMetadata({
238+
normalizedRequest: {
239+
url: 'value2',
240+
headers: {},
241+
},
242+
});
243+
244+
expect(scope['_sdkProcessingMetadata']).toEqual({
245+
normalizedRequest: { url: 'value2', method: 'value1', headers: {} },
246+
});
247+
});
228248
});
229249

230250
test('set and get propagation context', () => {

packages/core/test/lib/utils/sdkProcessingMetadata.test.ts renamed to packages/core/test/lib/utils/mergeSdkProcessingMetadata.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { mergeSdkProcessingMetadata } from '../../../src/utils/sdkProcessingMetadata';
1+
import { mergeSdkProcessingMetadata } from '../../../src/utils/mergeSdkProcessingMetadata';
22

33
describe('mergeSdkProcessingMetadata', () => {
44
it('works with empty objects', () => {

packages/node/src/integrations/http/SentryHttpInstrumentation.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { VERSION } from '@opentelemetry/core';
55
import type { InstrumentationConfig } from '@opentelemetry/instrumentation';
66
import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
77
import { getRequestInfo } from '@opentelemetry/instrumentation-http';
8-
import { addBreadcrumb, getClient, getIsolationScope, setNormalizedRequest, withIsolationScope } from '@sentry/core';
8+
import { addBreadcrumb, getClient, getIsolationScope, withIsolationScope } from '@sentry/core';
99
import type { PolymorphicRequest, Request, SanitizedRequestData } from '@sentry/types';
1010
import {
1111
getBreadcrumbLogLevelFromHttpStatusCode,
@@ -153,9 +153,7 @@ export class SentryHttpInstrumentation extends InstrumentationBase<SentryHttpIns
153153
patchRequestToCaptureBody(request, normalizedRequest);
154154

155155
// Update the isolation scope, isolate this request
156-
// TODO(v9): Stop setting `request`, we only rely on normalizedRequest anymore
157-
isolationScope.setSDKProcessingMetadata({ request });
158-
setNormalizedRequest(normalizedRequest, isolationScope);
156+
isolationScope.setSDKProcessingMetadata({ request, normalizedRequest });
159157

160158
const client = getClient<NodeClient>();
161159
if (client && client.getOptions().autoSessionTracking) {

0 commit comments

Comments
 (0)