Skip to content

Commit 213eb37

Browse files
committed
feat(core): Introduce seperate client options
1 parent f3e9384 commit 213eb37

File tree

4 files changed

+120
-69
lines changed

4 files changed

+120
-69
lines changed

packages/core/src/options.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { ClientOptions, Options } from '@sentry/types';
2+
import { makeDsn, stackParserFromOptions } from '@sentry/utils';
3+
4+
import { getIntegrationsToSetup } from './integration';
5+
import { NoopTransport } from './transports/noop';
6+
7+
export const DEFAULT_MAX_BREADCRUMBS = 100;
8+
export const DEFAULT_MAX_VALUE_LENGTH = 250;
9+
export const DEFAULT_NORMALIZE_DEPTH = 3;
10+
export const DEFAULT_NORMALIZE_MAX_BREADTH = 1000;
11+
export const DEFAULT_SHUTDOWN_TIMEOUT = 2000;
12+
13+
/** JSDoc */
14+
export function optionsToClientOptions(options: Options): ClientOptions {
15+
return {
16+
...options,
17+
integrations: getIntegrationsToSetup(options),
18+
transport: options.transport || NoopTransport,
19+
dsn: options.dsn === undefined ? undefined : makeDsn(options.dsn),
20+
stackParser: stackParserFromOptions(options),
21+
maxBreadcrumbs: options.maxBreadcrumbs || DEFAULT_MAX_BREADCRUMBS,
22+
sampleRate: typeof options.sampleRate === 'number' ? options.sampleRate : 1,
23+
maxValueLength: options.maxValueLength || DEFAULT_MAX_VALUE_LENGTH,
24+
normalizeDepth: options.normalizeDepth || DEFAULT_NORMALIZE_DEPTH,
25+
normalizeMaxBreadth: options.normalizeMaxBreadth || DEFAULT_NORMALIZE_MAX_BREADTH,
26+
shutdownTimeout: options.shutdownTimeout || DEFAULT_SHUTDOWN_TIMEOUT,
27+
};
28+
}

packages/types/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export { Hub } from './hub';
2727
export { Integration, IntegrationClass } from './integration';
2828
export { Mechanism } from './mechanism';
2929
export { ExtractedNodeRequestData, Primitive, WorkerLocation } from './misc';
30-
export { Options } from './options';
30+
export { ClientOptions, Options } from './options';
3131
export { Package } from './package';
3232
export { QueryParams, Request, SentryRequest, SentryRequestType } from './request';
3333
export { Response } from './response';

packages/types/src/options.ts

+91-66
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Breadcrumb, BreadcrumbHint } from './breadcrumb';
2+
import { DsnComponents } from './dsn';
23
import { Event, EventHint } from './event';
34
import { Integration } from './integration';
45
import { CaptureContext } from './scope';
@@ -7,8 +8,7 @@ import { StackLineParser, StackParser } from './stacktrace';
78
import { SamplingContext } from './transaction';
89
import { Transport, TransportClass, TransportOptions } from './transport';
910

10-
/** Base configuration options for every SDK. */
11-
export interface Options {
11+
export interface ClientOptions {
1212
/**
1313
* Enable debug functionality in the SDK itself
1414
*/
@@ -20,76 +20,88 @@ export interface Options {
2020
*/
2121
enabled?: boolean;
2222

23+
/** Attaches stacktraces to pure capture message / log integrations */
24+
attachStacktrace?: boolean;
25+
26+
/**
27+
* A flag enabling Sessions Tracking feature.
28+
* By default, Sessions Tracking is enabled.
29+
*/
30+
autoSessionTracking?: boolean;
31+
32+
/**
33+
* Send SDK Client Reports.
34+
* By default, Client Reports are enabled.
35+
*/
36+
sendClientReports?: boolean;
37+
2338
/**
2439
* The Dsn used to connect to Sentry and identify the project. If omitted, the
2540
* SDK will not send any data to Sentry.
2641
*/
27-
dsn?: string;
42+
dsn?: DsnComponents;
2843

2944
/**
30-
* If this is set to false, default integrations will not be added, otherwise this will internally be set to the
31-
* recommended default integrations.
32-
* TODO: We should consider changing this to `boolean | Integration[]`
45+
* The release identifier used when uploading respective source maps. Specify
46+
* this value to allow Sentry to resolve the correct source maps when
47+
* processing events.
3348
*/
34-
defaultIntegrations?: false | Integration[];
49+
release?: string;
50+
51+
/** The current environment of your application (e.g. "production"). */
52+
environment?: string;
53+
54+
/** Sets the distribution for all events */
55+
dist?: string;
3556

3657
/**
3758
* List of integrations that should be installed after SDK was initialized.
38-
* Accepts either a list of integrations or a function that receives
39-
* default integrations and returns a new, updated list.
4059
*/
41-
integrations?: Integration[] | ((integrations: Integration[]) => Integration[]);
60+
integrations: Integration[];
4261

4362
/**
44-
* A pattern for error messages which should not be sent to Sentry.
45-
* By default, all errors will be sent.
63+
* Transport object that should be used to send events to Sentry
4664
*/
47-
ignoreErrors?: Array<string | RegExp>;
65+
transport: TransportClass<Transport>;
4866

4967
/**
50-
* Transport object that should be used to send events to Sentry
68+
* A stack parser implementation
69+
* By default, a stack parser is supplied for all supported platforms
5170
*/
52-
transport?: TransportClass<Transport>;
71+
stackParser: StackParser;
5372

5473
/**
5574
* Options for the default transport that the SDK uses.
5675
*/
5776
transportOptions?: TransportOptions;
5877

5978
/**
60-
* A URL to an envelope tunnel endpoint. An envelope tunnel is an HTTP endpoint
61-
* that accepts Sentry envelopes for forwarding. This can be used to force data
62-
* through a custom server independent of the type of data.
79+
* Sample rate to determine trace sampling.
80+
*
81+
* 0.0 = 0% chance of a given trace being sent (send no traces) 1.0 = 100% chance of a given trace being sent (send
82+
* all traces)
83+
*
84+
* Tracing is enabled if either this or `tracesSampler` is defined. If both are defined, `tracesSampleRate` is
85+
* ignored.
6386
*/
64-
tunnel?: string;
87+
tracesSampleRate?: number;
6588

6689
/**
67-
* The release identifier used when uploading respective source maps. Specify
68-
* this value to allow Sentry to resolve the correct source maps when
69-
* processing events.
90+
* Initial data to populate scope.
7091
*/
71-
release?: string;
72-
73-
/** The current environment of your application (e.g. "production"). */
74-
environment?: string;
75-
76-
/** Sets the distribution for all events */
77-
dist?: string;
92+
initialScope?: CaptureContext;
7893

7994
/**
8095
* The maximum number of breadcrumbs sent with events. Defaults to 100.
8196
* Values over 100 will be ignored and 100 used instead.
8297
*/
83-
maxBreadcrumbs?: number;
98+
maxBreadcrumbs: number;
8499

85100
/** A global sample rate to apply to all events (0 - 1). */
86-
sampleRate?: number;
87-
88-
/** Attaches stacktraces to pure capture message / log integrations */
89-
attachStacktrace?: boolean;
101+
sampleRate: number;
90102

91103
/** Maximum number of chars a single value can have before it will be truncated. */
92-
maxValueLength?: number;
104+
maxValueLength: number;
93105

94106
/**
95107
* Maximum number of levels that normalization algorithm will traverse in objects and arrays.
@@ -100,7 +112,7 @@ export interface Options {
100112
* - `extra`
101113
* Defaults to `3`. Set to `0` to disable.
102114
*/
103-
normalizeDepth?: number;
115+
normalizeDepth: number;
104116

105117
/**
106118
* Maximum number of properties or elements that the normalization algorithm will output in any single array or object included in the normalized event.
@@ -111,7 +123,7 @@ export interface Options {
111123
* - `extra`
112124
* Defaults to `1000`
113125
*/
114-
normalizeMaxBreadth?: number;
126+
normalizeMaxBreadth: number;
115127

116128
/**
117129
* Controls how many milliseconds to wait before shutting down. The default is
@@ -120,41 +132,20 @@ export interface Options {
120132
* high can cause the application to block for users with network connectivity
121133
* problems.
122134
*/
123-
shutdownTimeout?: number;
135+
shutdownTimeout: number;
124136

125137
/**
126-
* Sample rate to determine trace sampling.
127-
*
128-
* 0.0 = 0% chance of a given trace being sent (send no traces) 1.0 = 100% chance of a given trace being sent (send
129-
* all traces)
130-
*
131-
* Tracing is enabled if either this or `tracesSampler` is defined. If both are defined, `tracesSampleRate` is
132-
* ignored.
133-
*/
134-
tracesSampleRate?: number;
135-
136-
/**
137-
* A flag enabling Sessions Tracking feature.
138-
* By default, Sessions Tracking is enabled.
139-
*/
140-
autoSessionTracking?: boolean;
141-
142-
/**
143-
* Send SDK Client Reports.
144-
* By default, Client Reports are enabled.
145-
*/
146-
sendClientReports?: boolean;
147-
148-
/**
149-
* Initial data to populate scope.
138+
* A pattern for error messages which should not be sent to Sentry.
139+
* By default, all errors will be sent.
150140
*/
151-
initialScope?: CaptureContext;
141+
ignoreErrors?: Array<string | RegExp>;
152142

153143
/**
154-
* A stack parser implementation or an array of stack line parsers
155-
* By default, a stack parser is supplied for all supported browsers
144+
* A URL to an envelope tunnel endpoint. An envelope tunnel is an HTTP endpoint
145+
* that accepts Sentry envelopes for forwarding. This can be used to force data
146+
* through a custom server independent of the type of data.
156147
*/
157-
stackParser?: StackParser | StackLineParser[];
148+
tunnel?: string;
158149

159150
/**
160151
* Set of metadata about the SDK that can be internally used to enhance envelopes and events,
@@ -210,3 +201,37 @@ export interface Options {
210201
*/
211202
beforeBreadcrumb?: (breadcrumb: Breadcrumb, hint?: BreadcrumbHint) => Breadcrumb | null;
212203
}
204+
205+
/** Base configuration options for every SDK. */
206+
export interface Options extends Omit<Partial<ClientOptions>, 'dsn' | 'integrations' | 'transport' | 'stackParser'> {
207+
/**
208+
* The Dsn used to connect to Sentry and identify the project. If omitted, the
209+
* SDK will not send any data to Sentry.
210+
*/
211+
dsn?: string;
212+
213+
/**
214+
* If this is set to false, default integrations will not be added, otherwise this will internally be set to the
215+
* recommended default integrations.
216+
* TODO: We should consider changing this to `boolean | Integration[]`
217+
*/
218+
defaultIntegrations?: false | Integration[];
219+
220+
/**
221+
* List of integrations that should be installed after SDK was initialized.
222+
* Accepts either a list of integrations or a function that receives
223+
* default integrations and returns a new, updated list.
224+
*/
225+
integrations?: Integration[] | ((integrations: Integration[]) => Integration[]);
226+
227+
/**
228+
* Transport object that should be used to send events to Sentry
229+
*/
230+
transport?: TransportClass<Transport>;
231+
232+
/**
233+
* A stack parser implementation or an array of stack line parsers
234+
* By default, a stack parser is supplied for all supported browsers
235+
*/
236+
stackParser?: StackParser | StackLineParser[];
237+
}

packages/utils/src/dsn.ts

-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ function validateDsn(dsn: DsnComponents): boolean | void {
9898
/** The Sentry Dsn, identifying a Sentry instance and project. */
9999
export function makeDsn(from: DsnLike): DsnComponents {
100100
const components = typeof from === 'string' ? dsnFromString(from) : dsnFromComponents(from);
101-
102101
validateDsn(components);
103-
104102
return components;
105103
}

0 commit comments

Comments
 (0)