UNPKG

8.61 kBTypeScriptView Raw
1import type { Breadcrumb, BreadcrumbHint, Client, ClientOptions, DataCategory, DsnComponents, Envelope, Event, EventDropReason, EventHint, Integration, IntegrationClass, Outcome, SdkMetadata, Session, SessionAggregates, Severity, SeverityLevel, Transaction, Transport, TransportMakeRequestResponse } from '@sentry/types';
2import type { IntegrationIndex } from './integration';
3import type { 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 private _hooks;
50 /**
51 * Initializes this client instance.
52 *
53 * @param options Options for the client.
54 */
55 protected constructor(options: O);
56 /**
57 * @inheritDoc
58 */
59 captureException(exception: any, hint?: EventHint, scope?: Scope): string | undefined;
60 /**
61 * @inheritDoc
62 */
63 captureMessage(message: string, level?: Severity | SeverityLevel, hint?: EventHint, scope?: Scope): string | undefined;
64 /**
65 * @inheritDoc
66 */
67 captureEvent(event: Event, hint?: EventHint, scope?: Scope): string | undefined;
68 /**
69 * @inheritDoc
70 */
71 captureSession(session: Session): void;
72 /**
73 * @inheritDoc
74 */
75 getDsn(): DsnComponents | undefined;
76 /**
77 * @inheritDoc
78 */
79 getOptions(): O;
80 /**
81 * @see SdkMetadata in @sentry/types
82 *
83 * @return The metadata of the SDK
84 */
85 getSdkMetadata(): SdkMetadata | undefined;
86 /**
87 * @inheritDoc
88 */
89 getTransport(): Transport | undefined;
90 /**
91 * @inheritDoc
92 */
93 flush(timeout?: number): PromiseLike<boolean>;
94 /**
95 * @inheritDoc
96 */
97 close(timeout?: number): PromiseLike<boolean>;
98 /**
99 * Sets up the integrations
100 */
101 setupIntegrations(): void;
102 /**
103 * Gets an installed integration by its `id`.
104 *
105 * @returns The installed integration or `undefined` if no integration with that `id` was installed.
106 */
107 getIntegrationById(integrationId: string): Integration | undefined;
108 /**
109 * @inheritDoc
110 */
111 getIntegration<T extends Integration>(integration: IntegrationClass<T>): T | null;
112 /**
113 * @inheritDoc
114 */
115 addIntegration(integration: Integration): void;
116 /**
117 * @inheritDoc
118 */
119 sendEvent(event: Event, hint?: EventHint): void;
120 /**
121 * @inheritDoc
122 */
123 sendSession(session: Session | SessionAggregates): void;
124 /**
125 * @inheritDoc
126 */
127 recordDroppedEvent(reason: EventDropReason, category: DataCategory, _event?: Event): void;
128 /** @inheritdoc */
129 on(hook: 'startTransaction' | 'finishTransaction', callback: (transaction: Transaction) => void): void;
130 /** @inheritdoc */
131 on(hook: 'beforeEnvelope', callback: (envelope: Envelope) => void): void;
132 /** @inheritdoc */
133 on(hook: 'afterSendEvent', callback: (event: Event, sendResponse: TransportMakeRequestResponse | void) => void): void;
134 /** @inheritdoc */
135 on(hook: 'beforeAddBreadcrumb', callback: (breadcrumb: Breadcrumb, hint?: BreadcrumbHint) => void): void;
136 /** @inheritdoc */
137 emit(hook: 'startTransaction' | 'finishTransaction', transaction: Transaction): void;
138 /** @inheritdoc */
139 emit(hook: 'beforeEnvelope', envelope: Envelope): void;
140 /** @inheritdoc */
141 emit(hook: 'afterSendEvent', event: Event, sendResponse: TransportMakeRequestResponse | void): void;
142 /** @inheritdoc */
143 emit(hook: 'beforeAddBreadcrumb', breadcrumb: Breadcrumb, hint?: BreadcrumbHint): void;
144 /** Updates existing session based on the provided event */
145 protected _updateSessionFromEvent(session: Session, event: Event): void;
146 /**
147 * Determine if the client is finished processing. Returns a promise because it will wait `timeout` ms before saying
148 * "no" (resolving to `false`) in order to give the client a chance to potentially finish first.
149 *
150 * @param timeout The time, in ms, after which to resolve to `false` if the client is still busy. Passing `0` (or not
151 * passing anything) will make the promise wait as long as it takes for processing to finish before resolving to
152 * `true`.
153 * @returns A promise which will resolve to `true` if processing is already done or finishes before the timeout, and
154 * `false` otherwise
155 */
156 protected _isClientDoneProcessing(timeout?: number): PromiseLike<boolean>;
157 /** Determines whether this SDK is enabled and a valid Dsn is present. */
158 protected _isEnabled(): boolean;
159 /**
160 * Adds common information to events.
161 *
162 * The information includes release and environment from `options`,
163 * breadcrumbs and context (extra, tags and user) from the scope.
164 *
165 * Information that is already present in the event is never overwritten. For
166 * nested objects, such as the context, keys are merged.
167 *
168 * @param event The original event.
169 * @param hint May contain additional information about the original exception.
170 * @param scope A scope containing event metadata.
171 * @returns A new event with more information.
172 */
173 protected _prepareEvent(event: Event, hint: EventHint, scope?: Scope): PromiseLike<Event | null>;
174 /**
175 * Processes the event and logs an error in case of rejection
176 * @param event
177 * @param hint
178 * @param scope
179 */
180 protected _captureEvent(event: Event, hint?: EventHint, scope?: Scope): PromiseLike<string | undefined>;
181 /**
182 * Processes an event (either error or message) and sends it to Sentry.
183 *
184 * This also adds breadcrumbs and context information to the event. However,
185 * platform specific meta data (such as the User's IP address) must be added
186 * by the SDK implementor.
187 *
188 *
189 * @param event The event to send to Sentry.
190 * @param hint May contain additional information about the original exception.
191 * @param scope A scope containing event metadata.
192 * @returns A SyncPromise that resolves with the event or rejects in case event was/will not be send.
193 */
194 protected _processEvent(event: Event, hint: EventHint, scope?: Scope): PromiseLike<Event>;
195 /**
196 * Occupies the client with processing and event
197 */
198 protected _process<T>(promise: PromiseLike<T>): void;
199 /**
200 * @inheritdoc
201 */
202 protected _sendEnvelope(envelope: Envelope): PromiseLike<void | TransportMakeRequestResponse> | void;
203 /**
204 * Clears outcomes on this client and returns them.
205 */
206 protected _clearOutcomes(): Outcome[];
207 /**
208 * @inheritDoc
209 */
210 abstract eventFromException(_exception: any, _hint?: EventHint): PromiseLike<Event>;
211 /**
212 * @inheritDoc
213 */
214 abstract eventFromMessage(_message: string, _level?: Severity | SeverityLevel, _hint?: EventHint): PromiseLike<Event>;
215}
216//# sourceMappingURL=baseclient.d.ts.map
\No newline at end of file