UNPKG

4.49 kBJavaScriptView Raw
1import * as tslib_1 from "tslib";
2import { BaseBackend, getCurrentHub } from '@sentry/core';
3import { Severity } from '@sentry/types';
4import { addExceptionMechanism, addExceptionTypeValue, Dsn, extractExceptionKeysForMessage, isError, isPlainObject, normalizeToSize, SyncPromise, } from '@sentry/utils';
5import { extractStackFromError, parseError, parseStack, prepareFramesForEvent } from './parsers';
6import { HTTPSTransport, HTTPTransport } from './transports';
7/**
8 * The Sentry Node SDK Backend.
9 * @hidden
10 */
11var NodeBackend = /** @class */ (function (_super) {
12 tslib_1.__extends(NodeBackend, _super);
13 function NodeBackend() {
14 return _super !== null && _super.apply(this, arguments) || this;
15 }
16 /**
17 * @inheritDoc
18 */
19 NodeBackend.prototype._setupTransport = function () {
20 if (!this._options.dsn) {
21 // We return the noop transport here in case there is no Dsn.
22 return _super.prototype._setupTransport.call(this);
23 }
24 var dsn = new Dsn(this._options.dsn);
25 var transportOptions = tslib_1.__assign({}, this._options.transportOptions, (this._options.httpProxy && { httpProxy: this._options.httpProxy }), (this._options.httpsProxy && { httpsProxy: this._options.httpsProxy }), (this._options.caCerts && { caCerts: this._options.caCerts }), { dsn: this._options.dsn });
26 if (this._options.transport) {
27 return new this._options.transport(transportOptions);
28 }
29 if (dsn.protocol === 'http') {
30 return new HTTPTransport(transportOptions);
31 }
32 return new HTTPSTransport(transportOptions);
33 };
34 /**
35 * @inheritDoc
36 */
37 NodeBackend.prototype.eventFromException = function (exception, hint) {
38 var _this = this;
39 var ex = exception;
40 var mechanism = {
41 handled: true,
42 type: 'generic',
43 };
44 if (!isError(exception)) {
45 if (isPlainObject(exception)) {
46 // This will allow us to group events based on top-level keys
47 // which is much better than creating new group when any key/value change
48 var message = "Non-Error exception captured with keys: " + extractExceptionKeysForMessage(exception);
49 getCurrentHub().configureScope(function (scope) {
50 scope.setExtra('__serialized__', normalizeToSize(exception));
51 });
52 ex = (hint && hint.syntheticException) || new Error(message);
53 ex.message = message;
54 }
55 else {
56 // This handles when someone does: `throw "something awesome";`
57 // We use synthesized Error here so we can extract a (rough) stack trace.
58 ex = (hint && hint.syntheticException) || new Error(exception);
59 }
60 mechanism.synthetic = true;
61 }
62 return new SyncPromise(function (resolve, reject) {
63 return parseError(ex, _this._options)
64 .then(function (event) {
65 addExceptionTypeValue(event, undefined, undefined);
66 addExceptionMechanism(event, mechanism);
67 resolve(tslib_1.__assign({}, event, { event_id: hint && hint.event_id }));
68 })
69 .then(null, reject);
70 });
71 };
72 /**
73 * @inheritDoc
74 */
75 NodeBackend.prototype.eventFromMessage = function (message, level, hint) {
76 var _this = this;
77 if (level === void 0) { level = Severity.Info; }
78 var event = {
79 event_id: hint && hint.event_id,
80 level: level,
81 message: message,
82 };
83 return new SyncPromise(function (resolve) {
84 if (_this._options.attachStacktrace && hint && hint.syntheticException) {
85 var stack = hint.syntheticException ? extractStackFromError(hint.syntheticException) : [];
86 parseStack(stack, _this._options)
87 .then(function (frames) {
88 event.stacktrace = {
89 frames: prepareFramesForEvent(frames),
90 };
91 resolve(event);
92 })
93 .then(null, function () {
94 resolve(event);
95 });
96 }
97 else {
98 resolve(event);
99 }
100 });
101 };
102 return NodeBackend;
103}(BaseBackend));
104export { NodeBackend };
105//# sourceMappingURL=backend.js.map
\No newline at end of file