Skip to content

Commit 12902c5

Browse files
mydealforst
andauthored
ref(utils): Stop setting transaction in requestDataIntegration (#14306)
This is not really necessary anymore - it only sets this on transaction events, and those get the `transaction` in different places already anyhow. With this, we can also actually remove some other stuff. One method is exported from utils but not otherwise used, we can also drop this in v9. Finally, this was also the only place that used `route` on the request, so we can also get rid of this in `remix`, which is weird anyhow because we set it for errors there but don't even use it for them. --------- Co-authored-by: Luca Forstner <[email protected]>
1 parent bac6c93 commit 12902c5

File tree

6 files changed

+28
-107
lines changed

6 files changed

+28
-107
lines changed
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- For now this is just a place where we can dump migration guide notes for v9 -->
2+
3+
# Deprecations
4+
5+
## `@sentry/utils`
6+
7+
- Deprecated `AddRequestDataToEventOptions.transaction`. This option effectively doesn't do anything anymore, and will
8+
be removed in v9.
9+
- Deprecated `TransactionNamingScheme` type.
10+
11+
## `@sentry/core`
12+
13+
- Deprecated `transactionNamingScheme` option in `requestDataIntegration`.

packages/core/src/integrations/requestdata.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ export type RequestDataIntegrationOptions = {
2424
};
2525
};
2626

27-
/** Whether to identify transactions by parameterized path, parameterized path with method, or handler name */
27+
/**
28+
* Whether to identify transactions by parameterized path, parameterized path with method, or handler name.
29+
* @deprecated This option does not do anything anymore, and will be removed in v9.
30+
*/
31+
// eslint-disable-next-line deprecation/deprecation
2832
transactionNamingScheme?: TransactionNamingScheme;
2933
};
3034

@@ -110,6 +114,7 @@ function convertReqDataIntegrationOptsToAddReqDataOpts(
110114
integrationOptions: Required<RequestDataIntegrationOptions>,
111115
): AddRequestDataToEventOptions {
112116
const {
117+
// eslint-disable-next-line deprecation/deprecation
113118
transactionNamingScheme,
114119
include: { ip, user, ...requestOptions },
115120
} = integrationOptions;

packages/remix/src/utils/errors.ts

+1-18
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
import type { AppData, DataFunctionArgs, EntryContext, HandleDocumentRequestFunction } from '@remix-run/node';
2-
import {
3-
captureException,
4-
getActiveSpan,
5-
getClient,
6-
getRootSpan,
7-
handleCallbackErrors,
8-
spanToJSON,
9-
} from '@sentry/core';
2+
import { captureException, getClient, handleCallbackErrors } from '@sentry/core';
103
import type { Span } from '@sentry/types';
114
import { addExceptionMechanism, isPrimitive, logger, objectify } from '@sentry/utils';
125
import { DEBUG_BUILD } from './debug-build';
@@ -61,19 +54,9 @@ export async function captureRemixServerException(
6154
const objectifiedErr = objectify(err);
6255

6356
captureException(isResponse(objectifiedErr) ? await extractResponseError(objectifiedErr) : objectifiedErr, scope => {
64-
const activeSpan = getActiveSpan();
65-
const rootSpan = activeSpan && getRootSpan(activeSpan);
66-
const activeRootSpanName = rootSpan ? spanToJSON(rootSpan).description : undefined;
67-
6857
scope.setSDKProcessingMetadata({
6958
request: {
7059
...normalizedRequest,
71-
// When `route` is not defined, `RequestData` integration uses the full URL
72-
route: activeRootSpanName
73-
? {
74-
path: activeRootSpanName,
75-
}
76-
: undefined,
7760
},
7861
});
7962

packages/remix/src/utils/instrumentServer.ts

-3
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,6 @@ function wrapRequestHandler(
314314
isolationScope.setSDKProcessingMetadata({
315315
request: {
316316
...normalizedRequest,
317-
route: {
318-
path: name,
319-
},
320317
},
321318
});
322319

packages/utils/src/requestdata.ts

+6-24
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { getClientIPAddress, ipHeaderNames } from './vendor/getIpAddress';
2121
const DEFAULT_INCLUDES = {
2222
ip: false,
2323
request: true,
24-
transaction: true,
2524
user: true,
2625
};
2726
const DEFAULT_REQUEST_INCLUDES = ['cookies', 'data', 'headers', 'method', 'query_string', 'url'];
@@ -35,6 +34,8 @@ export type AddRequestDataToEventOptions = {
3534
include?: {
3635
ip?: boolean;
3736
request?: boolean | Array<(typeof DEFAULT_REQUEST_INCLUDES)[number]>;
37+
/** @deprecated This option will be removed in v9. It does not do anything anymore, the `transcation` is set in other places. */
38+
// eslint-disable-next-line deprecation/deprecation
3839
transaction?: boolean | TransactionNamingScheme;
3940
user?: boolean | Array<(typeof DEFAULT_USER_INCLUDES)[number]>;
4041
};
@@ -52,6 +53,9 @@ export type AddRequestDataToEventOptions = {
5253
};
5354
};
5455

56+
/**
57+
* @deprecated This type will be removed in v9. It is not in use anymore.
58+
*/
5559
export type TransactionNamingScheme = 'path' | 'methodPath' | 'handler';
5660

5761
/**
@@ -67,6 +71,7 @@ export type TransactionNamingScheme = 'path' | 'methodPath' | 'handler';
6771
* used instead of the request's route)
6872
*
6973
* @returns A tuple of the fully constructed transaction name [0] and its source [1] (can be either 'route' or 'url')
74+
* @deprecated This method will be removed in v9. It is not in use anymore.
7075
*/
7176
export function extractPathForTransaction(
7277
req: PolymorphicRequest,
@@ -102,23 +107,6 @@ export function extractPathForTransaction(
102107
return [name, source];
103108
}
104109

105-
function extractTransaction(req: PolymorphicRequest, type: boolean | TransactionNamingScheme): string {
106-
switch (type) {
107-
case 'path': {
108-
return extractPathForTransaction(req, { path: true })[0];
109-
}
110-
case 'handler': {
111-
return (req.route && req.route.stack && req.route.stack[0] && req.route.stack[0].name) || '<anonymous>';
112-
}
113-
case 'methodPath':
114-
default: {
115-
// if exist _reconstructedRoute return that path instead of route.path
116-
const customRoute = req._reconstructedRoute ? req._reconstructedRoute : undefined;
117-
return extractPathForTransaction(req, { path: true, method: true, customRoute })[0];
118-
}
119-
}
120-
}
121-
122110
function extractUserData(
123111
user: {
124112
[key: string]: unknown;
@@ -379,12 +367,6 @@ export function addRequestDataToEvent(
379367
}
380368
}
381369

382-
if (include.transaction && !event.transaction && event.type === 'transaction') {
383-
// TODO do we even need this anymore?
384-
// TODO make this work for nextjs
385-
event.transaction = extractTransaction(req, include.transaction);
386-
}
387-
388370
return event;
389371
}
390372

packages/utils/test/requestdata.test.ts

+2-61
Original file line numberDiff line numberDiff line change
@@ -369,67 +369,6 @@ describe('addRequestDataToEvent', () => {
369369
}
370370
});
371371
});
372-
373-
describe('transaction property', () => {
374-
describe('for transaction events', () => {
375-
beforeEach(() => {
376-
mockEvent.type = 'transaction';
377-
});
378-
379-
test('extracts method and full route path by default`', () => {
380-
const parsedRequest: Event = addRequestDataToEvent(mockEvent, mockReq);
381-
382-
expect(parsedRequest.transaction).toEqual('POST /routerMountPath/subpath/:parameterName');
383-
});
384-
385-
test('extracts method and full path by default when mountpoint is `/`', () => {
386-
mockReq.originalUrl = mockReq.originalUrl.replace('/routerMountpath', '');
387-
mockReq.baseUrl = '';
388-
389-
const parsedRequest: Event = addRequestDataToEvent(mockEvent, mockReq);
390-
391-
// `subpath/` is the full path here, because there's no router mount path
392-
expect(parsedRequest.transaction).toEqual('POST /subpath/:parameterName');
393-
});
394-
395-
test('fallback to method and `originalUrl` if route is missing', () => {
396-
delete mockReq.route;
397-
398-
const parsedRequest: Event = addRequestDataToEvent(mockEvent, mockReq);
399-
400-
expect(parsedRequest.transaction).toEqual('POST /routerMountPath/subpath/specificValue');
401-
});
402-
403-
test('can extract path only instead if configured', () => {
404-
const optionsWithPathTransaction = {
405-
include: {
406-
transaction: 'path',
407-
},
408-
} as const;
409-
410-
const parsedRequest: Event = addRequestDataToEvent(mockEvent, mockReq, optionsWithPathTransaction);
411-
412-
expect(parsedRequest.transaction).toEqual('/routerMountPath/subpath/:parameterName');
413-
});
414-
415-
test('can extract handler name instead if configured', () => {
416-
const optionsWithHandlerTransaction = {
417-
include: {
418-
transaction: 'handler',
419-
},
420-
} as const;
421-
422-
const parsedRequest: Event = addRequestDataToEvent(mockEvent, mockReq, optionsWithHandlerTransaction);
423-
424-
expect(parsedRequest.transaction).toEqual('parameterNameRouteHandler');
425-
});
426-
});
427-
it('transaction is not applied to non-transaction events', () => {
428-
const parsedRequest: Event = addRequestDataToEvent(mockEvent, mockReq);
429-
430-
expect(parsedRequest.transaction).toBeUndefined();
431-
});
432-
});
433372
});
434373

435374
describe('extractRequestData', () => {
@@ -763,6 +702,7 @@ describe('extractPathForTransaction', () => {
763702
expectedRoute: string,
764703
expectedSource: TransactionSource,
765704
) => {
705+
// eslint-disable-next-line deprecation/deprecation
766706
const [route, source] = extractPathForTransaction(req, options);
767707

768708
expect(route).toEqual(expectedRoute);
@@ -778,6 +718,7 @@ describe('extractPathForTransaction', () => {
778718
originalUrl: '/api/users/123/details',
779719
} as PolymorphicRequest;
780720

721+
// eslint-disable-next-line deprecation/deprecation
781722
const [route, source] = extractPathForTransaction(req, {
782723
path: true,
783724
method: true,

0 commit comments

Comments
 (0)