UNPKG

7.88 kBTypeScriptView Raw
1import { Scope, Session } from '@sentry/hub';
2import { Client, Event, EventHint, Integration, IntegrationClass, Options, Severity, Transport } from '@sentry/types';
3import { Dsn } from '@sentry/utils';
4import { Backend, BackendClass } from './basebackend';
5import { IntegrationIndex } from './integration';
6/**
7 * Base implementation for all JavaScript SDK clients.
8 *
9 * Call the constructor with the corresponding backend constructor and options
10 * specific to the client subclass. To access these options later, use
11 * {@link Client.getOptions}. Also, the Backend instance is available via
12 * {@link Client.getBackend}.
13 *
14 * If a Dsn is specified in the options, it will be parsed and stored. Use
15 * {@link Client.getDsn} to retrieve the Dsn at any moment. In case the Dsn is
16 * invalid, the constructor will throw a {@link SentryException}. Note that
17 * without a valid Dsn, the SDK will not send any events to Sentry.
18 *
19 * Before sending an event via the backend, it is passed through
20 * {@link BaseClient._prepareEvent} to add SDK information and scope data
21 * (breadcrumbs and context). To add more custom information, override this
22 * method and extend the resulting prepared event.
23 *
24 * To issue automatically created events (e.g. via instrumentation), use
25 * {@link Client.captureEvent}. It will prepare the event and pass it through
26 * the callback lifecycle. To issue auto-breadcrumbs, use
27 * {@link Client.addBreadcrumb}.
28 *
29 * @example
30 * class NodeClient extends BaseClient<NodeBackend, NodeOptions> {
31 * public constructor(options: NodeOptions) {
32 * super(NodeBackend, options);
33 * }
34 *
35 * // ...
36 * }
37 */
38export declare abstract class BaseClient<B extends Backend, O extends Options> implements Client<O> {
39 /**
40 * The backend used to physically interact in the environment. Usually, this
41 * will correspond to the client. When composing SDKs, however, the Backend
42 * from the root SDK will be used.
43 */
44 protected readonly _backend: B;
45 /** Options passed to the SDK. */
46 protected readonly _options: O;
47 /** The client Dsn, if specified in options. Without this Dsn, the SDK will be disabled. */
48 protected readonly _dsn?: Dsn;
49 /** Array of used integrations. */
50 protected _integrations: IntegrationIndex;
51 /** Number of calls being processed */
52 protected _numProcessing: number;
53 /**
54 * Initializes this client instance.
55 *
56 * @param backendClass A constructor function to create the backend.
57 * @param options Options for the client.
58 */
59 protected constructor(backendClass: BackendClass<B, O>, options: O);
60 /**
61 * @inheritDoc
62 */
63 captureException(exception: any, hint?: EventHint, scope?: Scope): string | undefined;
64 /**
65 * @inheritDoc
66 */
67 captureMessage(message: string, level?: Severity, hint?: EventHint, scope?: Scope): string | undefined;
68 /**
69 * @inheritDoc
70 */
71 captureEvent(event: Event, hint?: EventHint, scope?: Scope): string | undefined;
72 /**
73 * @inheritDoc
74 */
75 captureSession(session: Session): void;
76 /**
77 * @inheritDoc
78 */
79 getDsn(): Dsn | undefined;
80 /**
81 * @inheritDoc
82 */
83 getOptions(): O;
84 /**
85 * @inheritDoc
86 */
87 getTransport(): Transport;
88 /**
89 * @inheritDoc
90 */
91 flush(timeout?: number): PromiseLike<boolean>;
92 /**
93 * @inheritDoc
94 */
95 close(timeout?: number): PromiseLike<boolean>;
96 /**
97 * Sets up the integrations
98 */
99 setupIntegrations(): void;
100 /**
101 * @inheritDoc
102 */
103 getIntegration<T extends Integration>(integration: IntegrationClass<T>): T | null;
104 /** Updates existing session based on the provided event */
105 protected _updateSessionFromEvent(session: Session, event: Event): void;
106 /** Deliver captured session to Sentry */
107 protected _sendSession(session: Session): void;
108 /**
109 * Determine if the client is finished processing. Returns a promise because it will wait `timeout` ms before saying
110 * "no" (resolving to `false`) in order to give the client a chance to potentially finish first.
111 *
112 * @param timeout The time, in ms, after which to resolve to `false` if the client is still busy. Passing `0` (or not
113 * passing anything) will make the promise wait as long as it takes for processing to finish before resolving to
114 * `true`.
115 * @returns A promise which will resolve to `true` if processing is already done or finishes before the timeout, and
116 * `false` otherwise
117 */
118 protected _isClientDoneProcessing(timeout?: number): PromiseLike<boolean>;
119 /** Returns the current backend. */
120 protected _getBackend(): B;
121 /** Determines whether this SDK is enabled and a valid Dsn is present. */
122 protected _isEnabled(): boolean;
123 /**
124 * Adds common information to events.
125 *
126 * The information includes release and environment from `options`,
127 * breadcrumbs and context (extra, tags and user) from the scope.
128 *
129 * Information that is already present in the event is never overwritten. For
130 * nested objects, such as the context, keys are merged.
131 *
132 * @param event The original event.
133 * @param hint May contain additional information about the original exception.
134 * @param scope A scope containing event metadata.
135 * @returns A new event with more information.
136 */
137 protected _prepareEvent(event: Event, scope?: Scope, hint?: EventHint): PromiseLike<Event | null>;
138 /**
139 * Applies `normalize` function on necessary `Event` attributes to make them safe for serialization.
140 * Normalized keys:
141 * - `breadcrumbs.data`
142 * - `user`
143 * - `contexts`
144 * - `extra`
145 * @param event Event
146 * @returns Normalized event
147 */
148 protected _normalizeEvent(event: Event | null, depth: number): Event | null;
149 /**
150 * Enhances event using the client configuration.
151 * It takes care of all "static" values like environment, release and `dist`,
152 * as well as truncating overly long values.
153 * @param event event instance to be enhanced
154 */
155 protected _applyClientOptions(event: Event): void;
156 /**
157 * This function adds all used integrations to the SDK info in the event.
158 * @param event The event that will be filled with all integrations.
159 */
160 protected _applyIntegrationsMetadata(event: Event): void;
161 /**
162 * Tells the backend to send this event
163 * @param event The Sentry event to send
164 */
165 protected _sendEvent(event: Event): void;
166 /**
167 * Processes the event and logs an error in case of rejection
168 * @param event
169 * @param hint
170 * @param scope
171 */
172 protected _captureEvent(event: Event, hint?: EventHint, scope?: Scope): PromiseLike<string | undefined>;
173 /**
174 * Processes an event (either error or message) and sends it to Sentry.
175 *
176 * This also adds breadcrumbs and context information to the event. However,
177 * platform specific meta data (such as the User's IP address) must be added
178 * by the SDK implementor.
179 *
180 *
181 * @param event The event to send to Sentry.
182 * @param hint May contain additional information about the original exception.
183 * @param scope A scope containing event metadata.
184 * @returns A SyncPromise that resolves with the event or rejects in case event was/will not be send.
185 */
186 protected _processEvent(event: Event, hint?: EventHint, scope?: Scope): PromiseLike<Event>;
187 /**
188 * Occupies the client with processing and event
189 */
190 protected _process<T>(promise: PromiseLike<T>): void;
191 /**
192 * Verifies that return value of configured `beforeSend` is of expected type.
193 */
194 protected _ensureBeforeSendRv(rv: PromiseLike<Event | null> | Event | null): PromiseLike<Event | null> | Event | null;
195}
196//# sourceMappingURL=baseclient.d.ts.map
\No newline at end of file