UNPKG

15.4 kBTypeScriptView Raw
1import type { Breadcrumb, BreadcrumbHint } from './breadcrumb';
2import type { ErrorEvent, EventHint, TransactionEvent } from './event';
3import type { Integration } from './integration';
4import type { SamplingContext } from './samplingcontext';
5import type { CaptureContext } from './scope';
6import type { SdkMetadata } from './sdkmetadata';
7import type { SpanJSON } from './span';
8import type { StackLineParser, StackParser } from './stacktrace';
9import type { TracePropagationTargets } from './tracing';
10import type { BaseTransportOptions, Transport } from './transport';
11export interface ClientOptions<TO extends BaseTransportOptions = BaseTransportOptions> {
12 /**
13 * Enable debug functionality in the SDK itself
14 */
15 debug?: boolean;
16 /**
17 * Specifies whether this SDK should send events to Sentry.
18 * Defaults to true.
19 */
20 enabled?: boolean;
21 /** Attaches stacktraces to pure capture message / log integrations */
22 attachStacktrace?: boolean;
23 /**
24 * A flag enabling Sessions Tracking feature.
25 * By default, Sessions Tracking is enabled.
26 */
27 autoSessionTracking?: boolean;
28 /**
29 * Send SDK Client Reports. When calling `Sentry.init()`, this option defaults to `true`.
30 */
31 sendClientReports?: boolean;
32 /**
33 * The Dsn used to connect to Sentry and identify the project. If omitted, the
34 * SDK will not send any data to Sentry.
35 */
36 dsn?: string;
37 /**
38 * The release identifier used when uploading respective source maps. Specify
39 * this value to allow Sentry to resolve the correct source maps when
40 * processing events.
41 */
42 release?: string;
43 /** The current environment of your application (e.g. "production"). */
44 environment?: string;
45 /** Sets the distribution for all events */
46 dist?: string;
47 /**
48 * List of integrations that should be installed after SDK was initialized.
49 */
50 integrations: Integration[];
51 /**
52 * A function that takes transport options and returns the Transport object which is used to send events to Sentry.
53 * The function is invoked internally when the client is initialized.
54 */
55 transport: (transportOptions: TO) => Transport;
56 /**
57 * A stack parser implementation
58 * By default, a stack parser is supplied for all supported platforms
59 */
60 stackParser: StackParser;
61 /**
62 * Options for the default transport that the SDK uses.
63 */
64 transportOptions?: Partial<TO>;
65 /**
66 * Sample rate to determine trace sampling.
67 *
68 * 0.0 = 0% chance of a given trace being sent (send no traces) 1.0 = 100% chance of a given trace being sent (send
69 * all traces)
70 *
71 * Tracing is enabled if either this or `tracesSampler` is defined. If both are defined, `tracesSampleRate` is
72 * ignored.
73 */
74 tracesSampleRate?: number;
75 /**
76 * If this is enabled, spans and trace data will be generated and captured.
77 * This will set the `tracesSampleRate` to the recommended default of `1.0` if `tracesSampleRate` is undefined.
78 * Note that `tracesSampleRate` and `tracesSampler` take precedence over this option.
79 *
80 * @deprecated This option is deprecated and will be removed in the next major version. If you want to enable performance
81 * monitoring, please use the `tracesSampleRate` or `tracesSampler` options instead. If you wan't to disable performance
82 * monitoring, remove the `tracesSampler` and `tracesSampleRate` options.
83 */
84 enableTracing?: boolean;
85 /**
86 * If this is enabled, any spans started will always have their parent be the active root span,
87 * if there is any active span.
88 *
89 * This is necessary because in some environments (e.g. browser),
90 * we cannot guarantee an accurate active span.
91 * Because we cannot properly isolate execution environments,
92 * you may get wrong results when using e.g. nested `startSpan()` calls.
93 *
94 * To solve this, in these environments we'll by default enable this option.
95 */
96 parentSpanIsAlwaysRootSpan?: boolean;
97 /**
98 * Initial data to populate scope.
99 */
100 initialScope?: CaptureContext;
101 /**
102 * The maximum number of breadcrumbs sent with events. Defaults to 100.
103 * Sentry has a maximum payload size of 1MB and any events exceeding that payload size will be dropped.
104 */
105 maxBreadcrumbs?: number;
106 /**
107 * A global sample rate to apply to all events.
108 *
109 * 0.0 = 0% chance of a given event being sent (send no events) 1.0 = 100% chance of a given event being sent (send
110 * all events)
111 */
112 sampleRate?: number;
113 /** Maximum number of chars a single value can have before it will be truncated. */
114 maxValueLength?: number;
115 /**
116 * Maximum number of levels that normalization algorithm will traverse in objects and arrays.
117 * Used when normalizing an event before sending, on all of the listed attributes:
118 * - `breadcrumbs.data`
119 * - `user`
120 * - `contexts`
121 * - `extra`
122 * Defaults to `3`. Set to `0` to disable.
123 */
124 normalizeDepth?: number;
125 /**
126 * Maximum number of properties or elements that the normalization algorithm will output in any single array or object included in the normalized event.
127 * Used when normalizing an event before sending, on all of the listed attributes:
128 * - `breadcrumbs.data`
129 * - `user`
130 * - `contexts`
131 * - `extra`
132 * Defaults to `1000`
133 */
134 normalizeMaxBreadth?: number;
135 /**
136 * Controls how many milliseconds to wait before shutting down. The default is
137 * SDK-specific but typically around 2 seconds. Setting this too low can cause
138 * problems for sending events from command line applications. Setting it too
139 * high can cause the application to block for users with network connectivity
140 * problems.
141 */
142 shutdownTimeout?: number;
143 /**
144 * A pattern for error messages which should not be sent to Sentry.
145 * By default, all errors will be sent.
146 */
147 ignoreErrors?: Array<string | RegExp>;
148 /**
149 * A pattern for transaction names which should not be sent to Sentry.
150 * By default, all transactions will be sent.
151 */
152 ignoreTransactions?: Array<string | RegExp>;
153 /**
154 * A URL to an envelope tunnel endpoint. An envelope tunnel is an HTTP endpoint
155 * that accepts Sentry envelopes for forwarding. This can be used to force data
156 * through a custom server independent of the type of data.
157 */
158 tunnel?: string;
159 /**
160 * Controls if potentially sensitive data should be sent to Sentry by default.
161 * Note that this only applies to data that the SDK is sending by default
162 * but not data that was explicitly set (e.g. by calling `Sentry.setUser()`).
163 *
164 * Defaults to `false`.
165 *
166 * NOTE: This option currently controls only a few data points in a selected
167 * set of SDKs. The goal for this option is to eventually control all sensitive
168 * data the SDK sets by default. However, this would be a breaking change so
169 * until the next major update this option only controls data points which were
170 * added in versions above `7.9.0`.
171 */
172 sendDefaultPii?: boolean;
173 /**
174 * Set of metadata about the SDK that can be internally used to enhance envelopes and events,
175 * and provide additional data about every request.
176 */
177 _metadata?: SdkMetadata;
178 /**
179 * Options which are in beta, or otherwise not guaranteed to be stable.
180 */
181 _experiments?: {
182 [key: string]: any;
183 };
184 /**
185 * A pattern for error URLs which should exclusively be sent to Sentry.
186 * This is the opposite of {@link Options.denyUrls}.
187 * By default, all errors will be sent.
188 *
189 * Requires the use of the `InboundFilters` integration.
190 */
191 allowUrls?: Array<string | RegExp>;
192 /**
193 * A pattern for error URLs which should not be sent to Sentry.
194 * To allow certain errors instead, use {@link Options.allowUrls}.
195 * By default, all errors will be sent.
196 *
197 * Requires the use of the `InboundFilters` integration.
198 */
199 denyUrls?: Array<string | RegExp>;
200 /**
201 * List of strings and/or Regular Expressions used to determine which outgoing requests will have `sentry-trace` and `baggage`
202 * headers attached.
203 *
204 * **Default:** If this option is not provided, tracing headers will be attached to all outgoing requests.
205 * If you are using a browser SDK, by default, tracing headers will only be attached to outgoing requests to the same origin.
206 *
207 * **Disclaimer:** Carelessly setting this option in browser environments may result into CORS errors!
208 * Only attach tracing headers to requests to the same origin, or to requests to services you can control CORS headers of.
209 * 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.
210 * 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.
211 *
212 * If you provide a `tracePropagationTargets` array, the entries you provide will be matched against the entire URL of the outgoing request.
213 * If you are using a browser SDK, the entries will also be matched against the pathname of the outgoing requests.
214 * 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.
215 *
216 * If any of the two match any of the provided values, tracing headers will be attached to the outgoing request.
217 * Both, the string values, and the RegExes you provide in the array will match if they partially match the URL or pathname.
218 *
219 * Examples:
220 * - `tracePropagationTargets: [/^\/api/]` and request to `https://same-origin.com/api/posts`:
221 * - Tracing headers will be attached because the request is sent to the same origin and the regex matches the pathname "/api/posts".
222 * - `tracePropagationTargets: [/^\/api/]` and request to `https://different-origin.com/api/posts`:
223 * - Tracing headers will not be attached because the pathname will only be compared when the request target lives on the same origin.
224 * - `tracePropagationTargets: [/^\/api/, 'https://external-api.com']` and request to `https://external-api.com/v1/data`:
225 * - Tracing headers will be attached because the request URL matches the string `'https://external-api.com'`.
226 */
227 tracePropagationTargets?: TracePropagationTargets;
228 /**
229 * Function to compute tracing sample rate dynamically and filter unwanted traces.
230 *
231 * Tracing is enabled if either this or `tracesSampleRate` is defined. If both are defined, `tracesSampleRate` is
232 * ignored.
233 *
234 * Will automatically be passed a context object of default and optional custom data. See
235 * {@link Transaction.samplingContext} and {@link Hub.startTransaction}.
236 *
237 * @returns A sample rate between 0 and 1 (0 drops the trace, 1 guarantees it will be sent). Returning `true` is
238 * equivalent to returning 1 and returning `false` is equivalent to returning 0.
239 */
240 tracesSampler?: (samplingContext: SamplingContext) => number | boolean;
241 /**
242 * An event-processing callback for error and message events, guaranteed to be invoked after all other event
243 * processors, which allows an event to be modified or dropped.
244 *
245 * Note that you must return a valid event from this callback. If you do not wish to modify the event, simply return
246 * it at the end. Returning `null` will cause the event to be dropped.
247 *
248 * @param event The error or message event generated by the SDK.
249 * @param hint Event metadata useful for processing.
250 * @returns A new event that will be sent | null.
251 */
252 beforeSend?: (event: ErrorEvent, hint: EventHint) => PromiseLike<ErrorEvent | null> | ErrorEvent | null;
253 /**
254 * This function can be defined to modify or entirely drop a child span before it's sent.
255 * Returning `null` will cause this span to be dropped.
256 *
257 * Note that this function is only called for child spans and not for the root span (formerly known as transaction).
258 * If you want to modify or drop the root span, use {@link Options.beforeSendTransaction} instead.
259 *
260 * @param span The span generated by the SDK.
261 *
262 * @returns A new span that will be sent or null if the span should not be sent.
263 */
264 beforeSendSpan?: (span: SpanJSON) => SpanJSON | null;
265 /**
266 * An event-processing callback for transaction events, guaranteed to be invoked after all other event
267 * processors. This allows an event to be modified or dropped before it's sent.
268 *
269 * Note that you must return a valid event from this callback. If you do not wish to modify the event, simply return
270 * it at the end. Returning `null` will cause the event to be dropped.
271 *
272 * @param event The error or message event generated by the SDK.
273 * @param hint Event metadata useful for processing.
274 * @returns A new event that will be sent | null.
275 */
276 beforeSendTransaction?: (event: TransactionEvent, hint: EventHint) => PromiseLike<TransactionEvent | null> | TransactionEvent | null;
277 /**
278 * A callback invoked when adding a breadcrumb, allowing to optionally modify
279 * it before adding it to future events.
280 *
281 * Note that you must return a valid breadcrumb from this callback. If you do
282 * not wish to modify the breadcrumb, simply return it at the end.
283 * Returning null will cause the breadcrumb to be dropped.
284 *
285 * @param breadcrumb The breadcrumb as created by the SDK.
286 * @returns The breadcrumb that will be added | null.
287 */
288 beforeBreadcrumb?: (breadcrumb: Breadcrumb, hint?: BreadcrumbHint) => Breadcrumb | null;
289}
290/** Base configuration options for every SDK. */
291export interface Options<TO extends BaseTransportOptions = BaseTransportOptions> extends Omit<Partial<ClientOptions<TO>>, 'integrations' | 'transport' | 'stackParser'> {
292 /**
293 * If this is set to false, default integrations will not be added, otherwise this will internally be set to the
294 * recommended default integrations.
295 */
296 defaultIntegrations?: false | Integration[];
297 /**
298 * List of integrations that should be installed after SDK was initialized.
299 * Accepts either a list of integrations or a function that receives
300 * default integrations and returns a new, updated list.
301 */
302 integrations?: Integration[] | ((integrations: Integration[]) => Integration[]);
303 /**
304 * A function that takes transport options and returns the Transport object which is used to send events to Sentry.
305 * The function is invoked internally during SDK initialization.
306 * By default, the SDK initializes its default transports.
307 */
308 transport?: (transportOptions: TO) => Transport;
309 /**
310 * A stack parser implementation or an array of stack line parsers
311 * By default, a stack parser is supplied for all supported browsers
312 */
313 stackParser?: StackParser | StackLineParser[];
314}
315//# sourceMappingURL=options.d.ts.map
\No newline at end of file