UNPKG

5.12 kBTypeScriptView Raw
1import type { Client, HandlerDataXhr, Span } from '@sentry/core';
2/** Options for Request Instrumentation */
3export interface RequestInstrumentationOptions {
4 /**
5 * List of strings and/or Regular Expressions used to determine which outgoing requests will have `sentry-trace` and `baggage`
6 * headers attached.
7 *
8 * **Default:** If this option is not provided, tracing headers will be attached to all outgoing requests.
9 * If you are using a browser SDK, by default, tracing headers will only be attached to outgoing requests to the same origin.
10 *
11 * **Disclaimer:** Carelessly setting this option in browser environments may result into CORS errors!
12 * Only attach tracing headers to requests to the same origin, or to requests to services you can control CORS headers of.
13 * Cross-origin requests, meaning requests to a different domain, for example a request to `https://api.example.com/` while you're on `https://example.com/`, take special care.
14 * If you are attaching headers to cross-origin requests, make sure the backend handling the request returns a `"Access-Control-Allow-Headers: sentry-trace, baggage"` header to ensure your requests aren't blocked.
15 *
16 * If you provide a `tracePropagationTargets` array, the entries you provide will be matched against the entire URL of the outgoing request.
17 * If you are using a browser SDK, the entries will also be matched against the pathname of the outgoing requests.
18 * This is so you can have matchers for relative requests, for example, `/^\/api/` if you want to trace requests to your `/api` routes on the same domain.
19 *
20 * If any of the two match any of the provided values, tracing headers will be attached to the outgoing request.
21 * Both, the string values, and the RegExes you provide in the array will match if they partially match the URL or pathname.
22 *
23 * Examples:
24 * - `tracePropagationTargets: [/^\/api/]` and request to `https://same-origin.com/api/posts`:
25 * - Tracing headers will be attached because the request is sent to the same origin and the regex matches the pathname "/api/posts".
26 * - `tracePropagationTargets: [/^\/api/]` and request to `https://different-origin.com/api/posts`:
27 * - Tracing headers will not be attached because the pathname will only be compared when the request target lives on the same origin.
28 * - `tracePropagationTargets: [/^\/api/, 'https://external-api.com']` and request to `https://external-api.com/v1/data`:
29 * - Tracing headers will be attached because the request URL matches the string `'https://external-api.com'`.
30 */
31 tracePropagationTargets?: Array<string | RegExp>;
32 /**
33 * Flag to disable patching all together for fetch requests.
34 *
35 * Default: true
36 */
37 traceFetch: boolean;
38 /**
39 * Flag to disable patching all together for xhr requests.
40 *
41 * Default: true
42 */
43 traceXHR: boolean;
44 /**
45 * Flag to disable tracking of long-lived streams, like server-sent events (SSE) via fetch.
46 * Do not enable this in case you have live streams or very long running streams.
47 *
48 * Disabled by default since it can lead to issues with streams using the `cancel()` api
49 * (https://github.com/getsentry/sentry-javascript/issues/13950)
50 *
51 * Default: false
52 */
53 trackFetchStreamPerformance: boolean;
54 /**
55 * If true, Sentry will capture http timings and add them to the corresponding http spans.
56 *
57 * Default: true
58 */
59 enableHTTPTimings: boolean;
60 /**
61 * This function will be called before creating a span for a request with the given url.
62 * Return false if you don't want a span for the given url.
63 *
64 * Default: (url: string) => true
65 */
66 shouldCreateSpanForRequest?(this: void, url: string): boolean;
67}
68export declare const defaultRequestInstrumentationOptions: RequestInstrumentationOptions;
69/** Registers span creators for xhr and fetch requests */
70export declare function instrumentOutgoingRequests(client: Client, _options?: Partial<RequestInstrumentationOptions>): void;
71/**
72 * Converts ALPN protocol ids to name and version.
73 *
74 * (https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#alpn-protocol-ids)
75 * @param nextHopProtocol PerformanceResourceTiming.nextHopProtocol
76 */
77export declare function extractNetworkProtocol(nextHopProtocol: string): {
78 name: string;
79 version: string;
80};
81/**
82 * A function that determines whether to attach tracing headers to a request.
83 * We only export this function for testing purposes.
84 */
85export declare function shouldAttachHeaders(targetUrl: string, tracePropagationTargets: (string | RegExp)[] | undefined): boolean;
86/**
87 * Create and track xhr request spans
88 *
89 * @returns Span if a span was created, otherwise void.
90 */
91export declare function xhrCallback(handlerData: HandlerDataXhr, shouldCreateSpan: (url: string) => boolean, shouldAttachHeaders: (url: string) => boolean, spans: Record<string, Span>): Span | undefined;
92//# sourceMappingURL=request.d.ts.map
\No newline at end of file