UNPKG

6.99 kBTypeScriptView Raw
1import { Scope, Session } from '@sentry/hub';
2import { Client, Event, EventHint, Integration, IntegrationClass, Options, Severity } 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 call being processed */
52 protected _processing: 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 flush(timeout?: number): PromiseLike<boolean>;
88 /**
89 * @inheritDoc
90 */
91 close(timeout?: number): PromiseLike<boolean>;
92 /**
93 * Sets up the integrations
94 */
95 setupIntegrations(): void;
96 /**
97 * @inheritDoc
98 */
99 getIntegration<T extends Integration>(integration: IntegrationClass<T>): T | null;
100 /** Updates existing session based on the provided event */
101 protected _updateSessionFromEvent(session: Session, event: Event): void;
102 /** Deliver captured session to Sentry */
103 protected _sendSession(session: Session): void;
104 /** Waits for the client to be done with processing. */
105 protected _isClientProcessing(timeout?: number): PromiseLike<boolean>;
106 /** Returns the current backend. */
107 protected _getBackend(): B;
108 /** Determines whether this SDK is enabled and a valid Dsn is present. */
109 protected _isEnabled(): boolean;
110 /**
111 * Adds common information to events.
112 *
113 * The information includes release and environment from `options`,
114 * breadcrumbs and context (extra, tags and user) from the scope.
115 *
116 * Information that is already present in the event is never overwritten. For
117 * nested objects, such as the context, keys are merged.
118 *
119 * @param event The original event.
120 * @param hint May contain additional information about the original exception.
121 * @param scope A scope containing event metadata.
122 * @returns A new event with more information.
123 */
124 protected _prepareEvent(event: Event, scope?: Scope, hint?: EventHint): PromiseLike<Event | null>;
125 /**
126 * Applies `normalize` function on necessary `Event` attributes to make them safe for serialization.
127 * Normalized keys:
128 * - `breadcrumbs.data`
129 * - `user`
130 * - `contexts`
131 * - `extra`
132 * @param event Event
133 * @returns Normalized event
134 */
135 protected _normalizeEvent(event: Event | null, depth: number): Event | null;
136 /**
137 * Enhances event using the client configuration.
138 * It takes care of all "static" values like environment, release and `dist`,
139 * as well as truncating overly long values.
140 * @param event event instance to be enhanced
141 */
142 protected _applyClientOptions(event: Event): void;
143 /**
144 * This function adds all used integrations to the SDK info in the event.
145 * @param event The event that will be filled with all integrations.
146 */
147 protected _applyIntegrationsMetadata(event: Event): void;
148 /**
149 * Tells the backend to send this event
150 * @param event The Sentry event to send
151 */
152 protected _sendEvent(event: Event): void;
153 /**
154 * Processes the event and logs an error in case of rejection
155 * @param event
156 * @param hint
157 * @param scope
158 */
159 protected _captureEvent(event: Event, hint?: EventHint, scope?: Scope): PromiseLike<string | undefined>;
160 /**
161 * Processes an event (either error or message) and sends it to Sentry.
162 *
163 * This also adds breadcrumbs and context information to the event. However,
164 * platform specific meta data (such as the User's IP address) must be added
165 * by the SDK implementor.
166 *
167 *
168 * @param event The event to send to Sentry.
169 * @param hint May contain additional information about the original exception.
170 * @param scope A scope containing event metadata.
171 * @returns A SyncPromise that resolves with the event or rejects in case event was/will not be send.
172 */
173 protected _processEvent(event: Event, hint?: EventHint, scope?: Scope): PromiseLike<Event>;
174 /**
175 * Occupies the client with processing and event
176 */
177 protected _process<T>(promise: PromiseLike<T>): void;
178}
179//# sourceMappingURL=baseclient.d.ts.map
\No newline at end of file