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