UNPKG

4.49 kBJavaScriptView Raw
1Object.defineProperty(exports, "__esModule", { value: true });
2var tslib_1 = require("tslib");
3var core_1 = require("@sentry/core");
4var hub_1 = require("@sentry/hub");
5var utils_1 = require("@sentry/utils");
6var domain = require("domain");
7var client_1 = require("./client");
8var integrations_1 = require("./integrations");
9exports.defaultIntegrations = [
10 // Common
11 new core_1.Integrations.InboundFilters(),
12 new core_1.Integrations.FunctionToString(),
13 // Native Wrappers
14 new integrations_1.Console(),
15 new integrations_1.Http(),
16 // Global Handlers
17 new integrations_1.OnUncaughtException(),
18 new integrations_1.OnUnhandledRejection(),
19 // Misc
20 new integrations_1.LinkedErrors(),
21];
22/**
23 * The Sentry Node SDK Client.
24 *
25 * To use this SDK, call the {@link init} function as early as possible in the
26 * main entry module. To set context information or send manual events, use the
27 * provided methods.
28 *
29 * @example
30 * ```
31 *
32 * const { init } = require('@sentry/node');
33 *
34 * init({
35 * dsn: '__DSN__',
36 * // ...
37 * });
38 * ```
39 *
40 * @example
41 * ```
42 *
43 * const { configureScope } = require('@sentry/node');
44 * configureScope((scope: Scope) => {
45 * scope.setExtra({ battery: 0.7 });
46 * scope.setTag({ user_mode: 'admin' });
47 * scope.setUser({ id: '4711' });
48 * });
49 * ```
50 *
51 * @example
52 * ```
53 *
54 * const { addBreadcrumb } = require('@sentry/node');
55 * addBreadcrumb({
56 * message: 'My Breadcrumb',
57 * // ...
58 * });
59 * ```
60 *
61 * @example
62 * ```
63 *
64 * const Sentry = require('@sentry/node');
65 * Sentry.captureMessage('Hello, world!');
66 * Sentry.captureException(new Error('Good bye'));
67 * Sentry.captureEvent({
68 * message: 'Manual',
69 * stacktrace: [
70 * // ...
71 * ],
72 * });
73 * ```
74 *
75 * @see {@link NodeOptions} for documentation on configuration options.
76 */
77function init(options) {
78 if (options === void 0) { options = {}; }
79 if (options.defaultIntegrations === undefined) {
80 options.defaultIntegrations = exports.defaultIntegrations;
81 }
82 if (options.dsn === undefined && process.env.SENTRY_DSN) {
83 options.dsn = process.env.SENTRY_DSN;
84 }
85 if (options.release === undefined) {
86 var global_1 = utils_1.getGlobalObject();
87 // Prefer env var over global
88 if (process.env.SENTRY_RELEASE) {
89 options.release = process.env.SENTRY_RELEASE;
90 }
91 // This supports the variable that sentry-webpack-plugin injects
92 else if (global_1.SENTRY_RELEASE && global_1.SENTRY_RELEASE.id) {
93 options.release = global_1.SENTRY_RELEASE.id;
94 }
95 }
96 if (options.environment === undefined && process.env.SENTRY_ENVIRONMENT) {
97 options.environment = process.env.SENTRY_ENVIRONMENT;
98 }
99 if (domain.active) {
100 hub_1.setHubOnCarrier(hub_1.getMainCarrier(), core_1.getCurrentHub());
101 }
102 core_1.initAndBind(client_1.NodeClient, options);
103}
104exports.init = init;
105/**
106 * This is the getter for lastEventId.
107 *
108 * @returns The last event id of a captured event.
109 */
110function lastEventId() {
111 return core_1.getCurrentHub().lastEventId();
112}
113exports.lastEventId = lastEventId;
114/**
115 * A promise that resolves when all current events have been sent.
116 * If you provide a timeout and the queue takes longer to drain the promise returns false.
117 *
118 * @param timeout Maximum time in ms the client should wait.
119 */
120function flush(timeout) {
121 return tslib_1.__awaiter(this, void 0, void 0, function () {
122 var client;
123 return tslib_1.__generator(this, function (_a) {
124 client = core_1.getCurrentHub().getClient();
125 if (client) {
126 return [2 /*return*/, client.flush(timeout)];
127 }
128 return [2 /*return*/, Promise.reject(false)];
129 });
130 });
131}
132exports.flush = flush;
133/**
134 * A promise that resolves when all current events have been sent.
135 * If you provide a timeout and the queue takes longer to drain the promise returns false.
136 *
137 * @param timeout Maximum time in ms the client should wait.
138 */
139function close(timeout) {
140 return tslib_1.__awaiter(this, void 0, void 0, function () {
141 var client;
142 return tslib_1.__generator(this, function (_a) {
143 client = core_1.getCurrentHub().getClient();
144 if (client) {
145 return [2 /*return*/, client.close(timeout)];
146 }
147 return [2 /*return*/, Promise.reject(false)];
148 });
149 });
150}
151exports.close = close;
152//# sourceMappingURL=sdk.js.map
\No newline at end of file