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