1 | import { __extends } from "tslib";
|
2 | import { BaseClient, SDK_VERSION } from '@sentry/core';
|
3 | import { SessionFlusher } from '@sentry/hub';
|
4 | import { RequestSessionStatus } from '@sentry/types';
|
5 | import { logger } from '@sentry/utils';
|
6 | import { NodeBackend } from './backend';
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | var NodeClient = (function (_super) {
|
14 | __extends(NodeClient, _super);
|
15 | |
16 |
|
17 |
|
18 |
|
19 | function NodeClient(options) {
|
20 | var _this = this;
|
21 | options._metadata = options._metadata || {};
|
22 | options._metadata.sdk = options._metadata.sdk || {
|
23 | name: 'sentry.javascript.node',
|
24 | packages: [
|
25 | {
|
26 | name: 'npm:@sentry/node',
|
27 | version: SDK_VERSION,
|
28 | },
|
29 | ],
|
30 | version: SDK_VERSION,
|
31 | };
|
32 | _this = _super.call(this, NodeBackend, options) || this;
|
33 | return _this;
|
34 | }
|
35 | |
36 |
|
37 |
|
38 |
|
39 | NodeClient.prototype.captureException = function (exception, hint, scope) {
|
40 |
|
41 |
|
42 |
|
43 | if (this._options.autoSessionTracking && this._sessionFlusher && scope) {
|
44 | var requestSession = scope.getRequestSession();
|
45 |
|
46 |
|
47 | if (requestSession && requestSession.status === RequestSessionStatus.Ok) {
|
48 | requestSession.status = RequestSessionStatus.Errored;
|
49 | }
|
50 | }
|
51 | return _super.prototype.captureException.call(this, exception, hint, scope);
|
52 | };
|
53 | |
54 |
|
55 |
|
56 | NodeClient.prototype.captureEvent = function (event, hint, scope) {
|
57 |
|
58 |
|
59 |
|
60 | if (this._options.autoSessionTracking && this._sessionFlusher && scope) {
|
61 | var eventType = event.type || 'exception';
|
62 | var isException = eventType === 'exception' && event.exception && event.exception.values && event.exception.values.length > 0;
|
63 |
|
64 | if (isException) {
|
65 | var requestSession = scope.getRequestSession();
|
66 |
|
67 |
|
68 | if (requestSession && requestSession.status === RequestSessionStatus.Ok) {
|
69 | requestSession.status = RequestSessionStatus.Errored;
|
70 | }
|
71 | }
|
72 | }
|
73 | return _super.prototype.captureEvent.call(this, event, hint, scope);
|
74 | };
|
75 | |
76 |
|
77 |
|
78 |
|
79 | NodeClient.prototype.close = function (timeout) {
|
80 | var _a;
|
81 | (_a = this._sessionFlusher) === null || _a === void 0 ? void 0 : _a.close();
|
82 | return _super.prototype.close.call(this, timeout);
|
83 | };
|
84 |
|
85 | NodeClient.prototype.initSessionFlusher = function () {
|
86 | var _a = this._options, release = _a.release, environment = _a.environment;
|
87 | if (!release) {
|
88 | logger.warn('Cannot initialise an instance of SessionFlusher if no release is provided!');
|
89 | }
|
90 | else {
|
91 | this._sessionFlusher = new SessionFlusher(this.getTransport(), {
|
92 | release: release,
|
93 | environment: environment,
|
94 | });
|
95 | }
|
96 | };
|
97 | |
98 |
|
99 |
|
100 | NodeClient.prototype._prepareEvent = function (event, scope, hint) {
|
101 | event.platform = event.platform || 'node';
|
102 | if (this.getOptions().serverName) {
|
103 | event.server_name = this.getOptions().serverName;
|
104 | }
|
105 | return _super.prototype._prepareEvent.call(this, event, scope, hint);
|
106 | };
|
107 | |
108 |
|
109 |
|
110 |
|
111 | NodeClient.prototype._captureRequestSession = function () {
|
112 | if (!this._sessionFlusher) {
|
113 | logger.warn('Discarded request mode session because autoSessionTracking option was disabled');
|
114 | }
|
115 | else {
|
116 | this._sessionFlusher.incrementSessionStatusCount();
|
117 | }
|
118 | };
|
119 | return NodeClient;
|
120 | }(BaseClient));
|
121 | export { NodeClient };
|
122 |
|
\ | No newline at end of file |