Repository navigation
ref(core): Add shared ServerRequestOptions type across runtimes
#25579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
isaacs
wants to merge
1
commit into
develop
from
isaacschlueter/js-3968-common-server-options-create-shared-type
+240
−12
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
packages/core/src/integrations/http/server-request-options.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| import type { Span } from '../../types/span'; | ||
| import type { MaxRequestBodySize } from '../../utils/request'; | ||
|
|
||
| /** | ||
| * Options that every integration for incoming HTTP requests should | ||
| * support, in each runtime. | ||
| * | ||
| * `TRequest` and `TResponse` are the request and response types that the | ||
| * runtime passes to callbacks: `HttpIncomingMessage` and | ||
| * `HttpServerResponse` for `node:http`, or the web `Request` and | ||
| * `Response` for `Deno.serve`, `Bun.serve` and Cloudflare. | ||
| * | ||
| * Runtime options types do not extend this type. Each one declares its | ||
| * own fields, with docs for that runtime, and uses | ||
| * {@link CheckServerRequestOptions} to check them against this type. | ||
| * Then a new field here fails to compile in each runtime, until the | ||
| * runtime supports it or lists it as unsupported. | ||
| */ | ||
| export interface ServerRequestOptions<TRequest, TResponse> { | ||
| /** | ||
| * Whether to create spans for incoming requests. | ||
| * Defaults to the client's tracing configuration. | ||
| */ | ||
| spans?: boolean; | ||
|
|
||
| /** | ||
| * Whether to create [Sessions](https://docs.sentry.io/product/releases/health/#sessions) for incoming | ||
| * requests, to track the health and crash-free rate of releases. | ||
| * | ||
| * @default `true` | ||
| */ | ||
| sessions?: boolean; | ||
|
|
||
| /** | ||
| * Number of milliseconds until sessions are flushed as a session aggregate. | ||
| * | ||
| * @default `60000` (60s) | ||
| */ | ||
| sessionFlushingDelayMS?: number; | ||
|
|
||
| /** | ||
| * Controls the maximum size of incoming request bodies attached to events. | ||
| * | ||
| * @default 'medium' | ||
| */ | ||
| maxRequestBodySize?: MaxRequestBodySize; | ||
|
|
||
| /** | ||
| * Do not capture the request body for incoming requests where the given callback returns `true`. | ||
| * | ||
| * `url` is the full URL of the request, including the query string. | ||
| */ | ||
| ignoreRequestBody?: (url: string, request: TRequest) => boolean; | ||
|
|
||
| /** | ||
| * Do not create spans for incoming requests where the given callback returns `true`. | ||
| * | ||
| * `urlPath` is the path of the request, including the query string. | ||
| */ | ||
| ignoreIncomingRequests?: (urlPath: string, request: TRequest) => boolean; | ||
|
|
||
| /** | ||
| * Whether to ignore common static asset requests (favicon.ico, robots.txt, etc.) | ||
| * when creating spans. | ||
| * | ||
| * @default `true` | ||
| */ | ||
| ignoreStaticAssets?: boolean; | ||
|
|
||
| /** | ||
| * A hook to change the span for an incoming request, after the span is created. | ||
| */ | ||
| onSpanCreated?: (span: Span, request: TRequest) => void; | ||
|
|
||
| /** | ||
| * A hook to change the span for an incoming request one last time, before it ends. | ||
| */ | ||
| onSpanEnd?: (span: Span, request: TRequest, response: TResponse) => void; | ||
| } | ||
|
|
||
| /** | ||
| * `true` when `TOptions` matches {@link ServerRequestOptions}, else a | ||
| * string that names the problem. Use it with a type that accepts only | ||
| * `true`, so a mismatch fails to compile: | ||
| * | ||
| * ```ts | ||
| * type _Check = AssertTrue<CheckServerRequestOptions<MyOptions, Request, Response, 'sessions'>>; | ||
| * ``` | ||
| * | ||
| * `TUnsupported` lists the fields that the runtime does not support. | ||
| * | ||
| * The check fails when: | ||
| * - `TOptions` does not declare a field, and `TUnsupported` does not | ||
| * list it. | ||
| * - `TUnsupported` lists a field that `TOptions` declares. | ||
| * - A callback written for the shared type does not fit the field in | ||
| * `TOptions`. | ||
| */ | ||
| export type CheckServerRequestOptions< | ||
| TOptions, | ||
| TRequest, | ||
| TResponse, | ||
| TUnsupported extends keyof ServerRequestOptions<TRequest, TResponse> = never, | ||
| > = [MissingFields<TOptions, TRequest, TResponse, TUnsupported>] extends [never] | ||
| ? [Extract<TUnsupported, keyof TOptions>] extends [never] | ||
| ? SupportedFields< | ||
| ServerRequestOptions<TRequest, TResponse>, | ||
| TRequest, | ||
| TResponse, | ||
| TUnsupported | ||
| > extends SupportedFields<TOptions, TRequest, TResponse, TUnsupported> | ||
| ? true | ||
| : 'A field type does not match ServerRequestOptions' | ||
| : `Listed as unsupported, but declared: ${Extract<TUnsupported, keyof TOptions> & string}` | ||
| : `Missing field: ${MissingFields<TOptions, TRequest, TResponse, TUnsupported> & string}`; | ||
|
|
||
| type MissingFields<TOptions, TRequest, TResponse, TUnsupported> = Exclude< | ||
| keyof ServerRequestOptions<TRequest, TResponse>, | ||
| TUnsupported | keyof TOptions | ||
| >; | ||
|
|
||
| type SupportedFields<T, TRequest, TResponse, TUnsupported> = Pick< | ||
| T, | ||
| Extract<keyof T, Exclude<keyof ServerRequestOptions<TRequest, TResponse>, TUnsupported>> | ||
| >; | ||
|
|
||
| /** Accepts only `true`. Use it with {@link CheckServerRequestOptions}. */ | ||
| export type AssertTrue<T extends true> = T; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.