Skip to content

Commit

Permalink
ref(types): Deprecate Request type in favor of RequestEventData (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
mydea authored and onurtemizkan committed Nov 22, 2024
1 parent 1c69e8a commit 1347c78
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 13 deletions.
4 changes: 4 additions & 0 deletions docs/migration/draft-v9-migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@
## `@sentry/core`

- Deprecated `transactionNamingScheme` option in `requestDataIntegration`.

## `@sentry/types``

- Deprecated `Request` in favor of `RequestEventData`.
2 changes: 2 additions & 0 deletions packages/browser/src/exports.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export type {
Breadcrumb,
BreadcrumbHint,
// eslint-disable-next-line deprecation/deprecation
Request,
RequestEventData,
SdkInfo,
Event,
EventHint,
Expand Down
2 changes: 2 additions & 0 deletions packages/bun/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ export type {
Breadcrumb,
BreadcrumbHint,
PolymorphicRequest,
// eslint-disable-next-line deprecation/deprecation
Request,
RequestEventData,
SdkInfo,
Event,
EventHint,
Expand Down
2 changes: 2 additions & 0 deletions packages/cloudflare/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ export type {
Breadcrumb,
BreadcrumbHint,
PolymorphicRequest,
// eslint-disable-next-line deprecation/deprecation
Request,
RequestEventData,
SdkInfo,
Event,
EventHint,
Expand Down
2 changes: 2 additions & 0 deletions packages/deno/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ export type {
Breadcrumb,
BreadcrumbHint,
PolymorphicRequest,
// eslint-disable-next-line deprecation/deprecation
Request,
RequestEventData,
SdkInfo,
Event,
EventHint,
Expand Down
2 changes: 2 additions & 0 deletions packages/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ export type {
Breadcrumb,
BreadcrumbHint,
PolymorphicRequest,
// eslint-disable-next-line deprecation/deprecation
Request,
RequestEventData,
SdkInfo,
Event,
EventHint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { InstrumentationConfig } from '@opentelemetry/instrumentation';
import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
import { getRequestInfo } from '@opentelemetry/instrumentation-http';
import { addBreadcrumb, getClient, getIsolationScope, withIsolationScope } from '@sentry/core';
import type { PolymorphicRequest, Request, SanitizedRequestData } from '@sentry/types';
import type { PolymorphicRequest, RequestEventData, SanitizedRequestData } from '@sentry/types';
import {
getBreadcrumbLogLevelFromHttpStatusCode,
getSanitizedUrlString,
Expand Down Expand Up @@ -142,7 +142,7 @@ export class SentryHttpInstrumentation extends InstrumentationBase<SentryHttpIns
// This is non-standard, but may be set on e.g. Next.js or Express requests
const cookies = (request as PolymorphicRequest).cookies;

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

function getChunksSize(): number {
Expand Down
6 changes: 3 additions & 3 deletions packages/types/src/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { Measurements } from './measurement';
import type { Mechanism } from './mechanism';
import type { Primitive } from './misc';
import type { PolymorphicRequest } from './polymorphics';
import type { Request } from './request';
import type { RequestEventData } from './request';
import type { CaptureContext, Scope } from './scope';
import type { SdkInfo } from './sdkinfo';
import type { SeverityLevel } from './severity';
Expand All @@ -36,7 +36,7 @@ export interface Event {
dist?: string;
environment?: string;
sdk?: SdkInfo;
request?: Request;
request?: RequestEventData;
transaction?: string;
modules?: { [key: string]: string };
fingerprint?: string[];
Expand All @@ -56,7 +56,7 @@ export interface Event {
// Note: This is considered internal and is subject to change in minors
sdkProcessingMetadata?: { [key: string]: unknown } & {
request?: PolymorphicRequest;
normalizedRequest?: Request;
normalizedRequest?: RequestEventData;
dynamicSamplingContext?: Partial<DynamicSamplingContext>;
capturedSpanScope?: Scope;
capturedSpanIsolationScope?: Scope;
Expand Down
8 changes: 7 additions & 1 deletion packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ export type {
SendFeedbackParams,
UserFeedback,
} from './feedback';
export type { QueryParams, Request, SanitizedRequestData } from './request';
export type {
QueryParams,
RequestEventData,
// eslint-disable-next-line deprecation/deprecation
Request,
SanitizedRequestData,
} from './request';
export type { Runtime } from './runtime';
export type { CaptureContext, Scope, ScopeContext, ScopeData } from './scope';
export type { SdkInfo } from './sdkinfo';
Expand Down
9 changes: 7 additions & 2 deletions packages/types/src/request.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/**
* Request data included in an event as sent to Sentry.
* TODO(v9): Rename this to avoid confusion, because Request is also a native type.
*/
export interface Request {
export interface RequestEventData {
url?: string;
method?: string;
data?: any;
Expand All @@ -12,6 +11,12 @@ export interface Request {
headers?: { [key: string]: string };
}

/**
* Request data included in an event as sent to Sentry.
* @deprecated: This type will be removed in v9. Use `RequestEventData` instead.
*/
export type Request = RequestEventData;

export type QueryParams = string | { [key: string]: string } | Array<[string, string]>;

/**
Expand Down
11 changes: 7 additions & 4 deletions packages/utils/src/requestdata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
Event,
ExtractedNodeRequestData,
PolymorphicRequest,
Request,
RequestEventData,
TransactionSource,
WebFetchHeaders,
WebFetchRequest,
Expand Down Expand Up @@ -260,7 +260,7 @@ export function extractRequestData(
*/
export function addNormalizedRequestDataToEvent(
event: Event,
req: Request,
req: RequestEventData,
// This is non-standard data that is not part of the regular HTTP request
additionalData: { ipAddress?: string; user?: Record<string, unknown> },
options: AddRequestDataToEventOptions,
Expand Down Expand Up @@ -428,10 +428,13 @@ export function winterCGRequestToRequestData(req: WebFetchRequest): PolymorphicR
};
}

function extractNormalizedRequestData(normalizedRequest: Request, { include }: { include: string[] }): Request {
function extractNormalizedRequestData(
normalizedRequest: RequestEventData,
{ include }: { include: string[] },
): RequestEventData {
const includeKeys = include ? (Array.isArray(include) ? include : DEFAULT_REQUEST_INCLUDES) : [];

const requestData: Request = {};
const requestData: RequestEventData = {};
const headers = { ...normalizedRequest.headers };

if (includeKeys.includes('headers')) {
Expand Down
2 changes: 2 additions & 0 deletions packages/vercel-edge/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ export type {
Breadcrumb,
BreadcrumbHint,
PolymorphicRequest,
// eslint-disable-next-line deprecation/deprecation
Request,
RequestEventData,
SdkInfo,
Event,
EventHint,
Expand Down

0 comments on commit 1347c78

Please sign in to comment.