UNPKG

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