1 | /**
|
2 | * The functions here, which enrich an event with request data, are mostly for use in Node, but are safe for use in a
|
3 | * browser context. They live here in `@sentry/utils` rather than in `@sentry/node` so that they can be used in
|
4 | * frameworks (like nextjs), which, because of SSR, run the same code in both Node and browser contexts.
|
5 | *
|
6 | * TODO (v8 / #5257): Remove the note below
|
7 | * Note that for now, the tests for this code have to live in `@sentry/node`, since they test both these functions and
|
8 | * the backwards-compatibility-preserving wrappers which still live in `handlers.ts` there.
|
9 | */
|
10 | import { Event, ExtractedNodeRequestData, PolymorphicRequest, Transaction, TransactionSource } from '@sentry/types';
|
11 | declare type InjectedNodeDeps = {
|
12 | cookie: {
|
13 | parse: (cookieStr: string) => Record<string, string>;
|
14 | };
|
15 | url: {
|
16 | parse: (urlStr: string) => {
|
17 | query: string | null;
|
18 | };
|
19 | };
|
20 | };
|
21 | /**
|
22 | * Sets parameterized route as transaction name e.g.: `GET /users/:id`
|
23 | * Also adds more context data on the transaction from the request
|
24 | */
|
25 | export declare function addRequestDataToTransaction(transaction: Transaction | undefined, req: PolymorphicRequest, deps?: InjectedNodeDeps): void;
|
26 | /**
|
27 | * Extracts a complete and parameterized path from the request object and uses it to construct transaction name.
|
28 | * If the parameterized transaction name cannot be extracted, we fall back to the raw URL.
|
29 | *
|
30 | * Additionally, this function determines and returns the transaction name source
|
31 | *
|
32 | * eg. GET /mountpoint/user/:id
|
33 | *
|
34 | * @param req A request object
|
35 | * @param options What to include in the transaction name (method, path, or a custom route name to be
|
36 | * used instead of the request's route)
|
37 | *
|
38 | * @returns A tuple of the fully constructed transaction name [0] and its source [1] (can be either 'route' or 'url')
|
39 | */
|
40 | export declare function extractPathForTransaction(req: PolymorphicRequest, options?: {
|
41 | path?: boolean;
|
42 | method?: boolean;
|
43 | customRoute?: string;
|
44 | }): [string, TransactionSource];
|
45 | declare type TransactionNamingScheme = 'path' | 'methodPath' | 'handler';
|
46 | /**
|
47 | * Normalize data from the request object, accounting for framework differences.
|
48 | *
|
49 | * @param req The request object from which to extract data
|
50 | * @param options.include An optional array of keys to include in the normalized data. Defaults to
|
51 | * DEFAULT_REQUEST_INCLUDES if not provided.
|
52 | * @param options.deps Injected, platform-specific dependencies
|
53 | * @returns An object containing normalized request data
|
54 | */
|
55 | export declare function extractRequestData(req: PolymorphicRequest, options?: {
|
56 | include?: string[];
|
57 | deps?: InjectedNodeDeps;
|
58 | }): ExtractedNodeRequestData;
|
59 | /**
|
60 | * Options deciding what parts of the request to use when enhancing an event
|
61 | */
|
62 | export interface AddRequestDataToEventOptions {
|
63 | /** Flags controlling whether each type of data should be added to the event */
|
64 | include?: {
|
65 | ip?: boolean;
|
66 | request?: boolean | string[];
|
67 | transaction?: boolean | TransactionNamingScheme;
|
68 | user?: boolean | string[];
|
69 | };
|
70 | /** Injected platform-specific dependencies */
|
71 | deps?: {
|
72 | cookie: {
|
73 | parse: (cookieStr: string) => Record<string, string>;
|
74 | };
|
75 | url: {
|
76 | parse: (urlStr: string) => {
|
77 | query: string | null;
|
78 | };
|
79 | };
|
80 | };
|
81 | }
|
82 | /**
|
83 | * Add data from the given request to the given event
|
84 | *
|
85 | * @param event The event to which the request data will be added
|
86 | * @param req Request object
|
87 | * @param options.include Flags to control what data is included
|
88 | * @param options.deps Injected platform-specific dependencies
|
89 | * @hidden
|
90 | */
|
91 | export declare function addRequestDataToEvent(event: Event, req: PolymorphicRequest, options?: AddRequestDataToEventOptions): Event;
|
92 | export {};
|
93 | //# sourceMappingURL=requestdata.d.ts.map |
\ | No newline at end of file |