Skip to content

Commit ef83bfc

Browse files
authored
ref(types): Deprecate Request type in favor of RequestEventData (#14317)
The type `Request` is very misleading and overloaded, so let's rename it to something clearer. I opted with `RequestEventData`, but happy to hear other ideas as well. Closes #14300
1 parent a374baf commit ef83bfc

File tree

12 files changed

+43
-13
lines changed

12 files changed

+43
-13
lines changed

docs/migration/draft-v9-migration-guide.md

+4
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@
1111
## `@sentry/core`
1212

1313
- Deprecated `transactionNamingScheme` option in `requestDataIntegration`.
14+
15+
## `@sentry/types``
16+
17+
- Deprecated `Request` in favor of `RequestEventData`.

packages/browser/src/exports.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
export type {
22
Breadcrumb,
33
BreadcrumbHint,
4+
// eslint-disable-next-line deprecation/deprecation
45
Request,
6+
RequestEventData,
57
SdkInfo,
68
Event,
79
EventHint,

packages/bun/src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ export type {
22
Breadcrumb,
33
BreadcrumbHint,
44
PolymorphicRequest,
5+
// eslint-disable-next-line deprecation/deprecation
56
Request,
7+
RequestEventData,
68
SdkInfo,
79
Event,
810
EventHint,

packages/cloudflare/src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ export type {
22
Breadcrumb,
33
BreadcrumbHint,
44
PolymorphicRequest,
5+
// eslint-disable-next-line deprecation/deprecation
56
Request,
7+
RequestEventData,
68
SdkInfo,
79
Event,
810
EventHint,

packages/deno/src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ export type {
22
Breadcrumb,
33
BreadcrumbHint,
44
PolymorphicRequest,
5+
// eslint-disable-next-line deprecation/deprecation
56
Request,
7+
RequestEventData,
68
SdkInfo,
79
Event,
810
EventHint,

packages/node/src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ export type {
144144
Breadcrumb,
145145
BreadcrumbHint,
146146
PolymorphicRequest,
147+
// eslint-disable-next-line deprecation/deprecation
147148
Request,
149+
RequestEventData,
148150
SdkInfo,
149151
Event,
150152
EventHint,

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { InstrumentationConfig } from '@opentelemetry/instrumentation';
66
import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
77
import { getRequestInfo } from '@opentelemetry/instrumentation-http';
88
import { addBreadcrumb, getClient, getIsolationScope, withIsolationScope } from '@sentry/core';
9-
import type { PolymorphicRequest, Request, SanitizedRequestData } from '@sentry/types';
9+
import type { PolymorphicRequest, RequestEventData, SanitizedRequestData } from '@sentry/types';
1010
import {
1111
getBreadcrumbLogLevelFromHttpStatusCode,
1212
getSanitizedUrlString,
@@ -142,7 +142,7 @@ export class SentryHttpInstrumentation extends InstrumentationBase<SentryHttpIns
142142
// This is non-standard, but may be set on e.g. Next.js or Express requests
143143
const cookies = (request as PolymorphicRequest).cookies;
144144

145-
const normalizedRequest: Request = {
145+
const normalizedRequest: RequestEventData = {
146146
url: absoluteUrl,
147147
method: request.method,
148148
query_string: extractQueryParams(request),
@@ -347,7 +347,7 @@ function getBreadcrumbData(request: http.ClientRequest): Partial<SanitizedReques
347347
* we monkey patch `req.on('data')` to intercept the body chunks.
348348
* This way, we only read the body if the user also consumes the body, ensuring we do not change any behavior in unexpected ways.
349349
*/
350-
function patchRequestToCaptureBody(req: IncomingMessage, normalizedRequest: Request): void {
350+
function patchRequestToCaptureBody(req: IncomingMessage, normalizedRequest: RequestEventData): void {
351351
const chunks: Buffer[] = [];
352352

353353
function getChunksSize(): number {

packages/types/src/event.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type { Measurements } from './measurement';
99
import type { Mechanism } from './mechanism';
1010
import type { Primitive } from './misc';
1111
import type { PolymorphicRequest } from './polymorphics';
12-
import type { Request } from './request';
12+
import type { RequestEventData } from './request';
1313
import type { CaptureContext, Scope } from './scope';
1414
import type { SdkInfo } from './sdkinfo';
1515
import type { SeverityLevel } from './severity';
@@ -36,7 +36,7 @@ export interface Event {
3636
dist?: string;
3737
environment?: string;
3838
sdk?: SdkInfo;
39-
request?: Request;
39+
request?: RequestEventData;
4040
transaction?: string;
4141
modules?: { [key: string]: string };
4242
fingerprint?: string[];
@@ -56,7 +56,7 @@ export interface Event {
5656
// Note: This is considered internal and is subject to change in minors
5757
sdkProcessingMetadata?: { [key: string]: unknown } & {
5858
request?: PolymorphicRequest;
59-
normalizedRequest?: Request;
59+
normalizedRequest?: RequestEventData;
6060
dynamicSamplingContext?: Partial<DynamicSamplingContext>;
6161
capturedSpanScope?: Scope;
6262
capturedSpanIsolationScope?: Scope;

packages/types/src/index.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,13 @@ export type {
8787
SendFeedbackParams,
8888
UserFeedback,
8989
} from './feedback';
90-
export type { QueryParams, Request, SanitizedRequestData } from './request';
90+
export type {
91+
QueryParams,
92+
RequestEventData,
93+
// eslint-disable-next-line deprecation/deprecation
94+
Request,
95+
SanitizedRequestData,
96+
} from './request';
9197
export type { Runtime } from './runtime';
9298
export type { CaptureContext, Scope, ScopeContext, ScopeData } from './scope';
9399
export type { SdkInfo } from './sdkinfo';

packages/types/src/request.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/**
22
* Request data included in an event as sent to Sentry.
3-
* TODO(v9): Rename this to avoid confusion, because Request is also a native type.
43
*/
5-
export interface Request {
4+
export interface RequestEventData {
65
url?: string;
76
method?: string;
87
data?: any;
@@ -12,6 +11,12 @@ export interface Request {
1211
headers?: { [key: string]: string };
1312
}
1413

14+
/**
15+
* Request data included in an event as sent to Sentry.
16+
* @deprecated: This type will be removed in v9. Use `RequestEventData` instead.
17+
*/
18+
export type Request = RequestEventData;
19+
1520
export type QueryParams = string | { [key: string]: string } | Array<[string, string]>;
1621

1722
/**

packages/utils/src/requestdata.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type {
33
Event,
44
ExtractedNodeRequestData,
55
PolymorphicRequest,
6-
Request,
6+
RequestEventData,
77
TransactionSource,
88
WebFetchHeaders,
99
WebFetchRequest,
@@ -260,7 +260,7 @@ export function extractRequestData(
260260
*/
261261
export function addNormalizedRequestDataToEvent(
262262
event: Event,
263-
req: Request,
263+
req: RequestEventData,
264264
// This is non-standard data that is not part of the regular HTTP request
265265
additionalData: { ipAddress?: string; user?: Record<string, unknown> },
266266
options: AddRequestDataToEventOptions,
@@ -428,10 +428,13 @@ export function winterCGRequestToRequestData(req: WebFetchRequest): PolymorphicR
428428
};
429429
}
430430

431-
function extractNormalizedRequestData(normalizedRequest: Request, { include }: { include: string[] }): Request {
431+
function extractNormalizedRequestData(
432+
normalizedRequest: RequestEventData,
433+
{ include }: { include: string[] },
434+
): RequestEventData {
432435
const includeKeys = include ? (Array.isArray(include) ? include : DEFAULT_REQUEST_INCLUDES) : [];
433436

434-
const requestData: Request = {};
437+
const requestData: RequestEventData = {};
435438
const headers = { ...normalizedRequest.headers };
436439

437440
if (includeKeys.includes('headers')) {

packages/vercel-edge/src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ export type {
22
Breadcrumb,
33
BreadcrumbHint,
44
PolymorphicRequest,
5+
// eslint-disable-next-line deprecation/deprecation
56
Request,
7+
RequestEventData,
68
SdkInfo,
79
Event,
810
EventHint,

0 commit comments

Comments
 (0)