@honeybadger-io/js 4.3.0 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/honeybadger.js +51 -50
- package/dist/browser/honeybadger.js.map +1 -1
- package/dist/browser/honeybadger.min.js +1 -1
- package/dist/browser/honeybadger.min.js.map +1 -1
- package/dist/server/async_store.d.ts +24 -4
- package/dist/server/honeybadger.d.ts +2 -0
- package/dist/server/honeybadger.js +186 -82
- package/dist/server/stacked_store.d.ts +23 -0
- package/package.json +3 -3
|
@@ -1,6 +1,26 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { Types } from '@honeybadger-io/core';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
4
|
+
export declare class AsyncStore implements Types.HoneybadgerStore {
|
|
5
|
+
private als;
|
|
6
|
+
private readonly contents;
|
|
7
|
+
private readonly breadcrumbsLimit;
|
|
8
|
+
constructor(asyncLocalStorage: AsyncLocalStorage<Types.StoreContents>, contents: Types.StoreContents, breadcrumbsLimit: number);
|
|
9
|
+
/**
|
|
10
|
+
* Attempt to create a new AsyncStore instance
|
|
11
|
+
*/
|
|
12
|
+
static create(contents: Types.StoreContents, breadcrumbsLimit: number): AsyncStore | null;
|
|
13
|
+
/**
|
|
14
|
+
* This returns the live store object, so we can mutate it.
|
|
15
|
+
* If we're in an async context (a `run()` callback), the stored contents at this point will be returned.
|
|
16
|
+
* Otherwise, the initial stored contents will be returned.
|
|
17
|
+
*/
|
|
18
|
+
__currentContents(): Types.StoreContents;
|
|
19
|
+
getContents(key?: keyof Types.StoreContents): any;
|
|
20
|
+
available(): boolean;
|
|
21
|
+
setContext(context: Record<string, unknown>): void;
|
|
22
|
+
addBreadcrumb(breadcrumb: any): void;
|
|
23
|
+
clear(): void;
|
|
24
|
+
run<R>(callback: () => R, request?: Record<symbol, unknown>): R;
|
|
25
|
+
}
|
|
6
26
|
//# sourceMappingURL=async_store.d.ts.map
|
|
@@ -9,8 +9,10 @@ declare class Honeybadger extends Client {
|
|
|
9
9
|
constructor(opts?: Partial<Types.Config | Types.ServerlessConfig>);
|
|
10
10
|
factory(opts?: Partial<Types.Config | Types.ServerlessConfig>): this;
|
|
11
11
|
configure(opts?: Partial<Types.Config | Types.ServerlessConfig>): this;
|
|
12
|
+
protected __initStore(): void;
|
|
12
13
|
checkIn(id: string): Promise<void>;
|
|
13
14
|
withRequest<R>(request: Record<symbol, unknown>, handler: (...args: never[]) => R, onError?: (...args: unknown[]) => unknown): R | void;
|
|
15
|
+
run<R>(callback: (...args: never[]) => R): R;
|
|
14
16
|
}
|
|
15
17
|
export { Types } from '@honeybadger-io/core';
|
|
16
18
|
declare const _default: Honeybadger;
|
|
@@ -703,20 +703,37 @@ var store = {};
|
|
|
703
703
|
|
|
704
704
|
Object.defineProperty(store, "__esModule", { value: true });
|
|
705
705
|
store.GlobalStore = void 0;
|
|
706
|
+
var util_1$4 = util$1;
|
|
706
707
|
var GlobalStore = /** @class */ (function () {
|
|
707
|
-
function GlobalStore(
|
|
708
|
-
this.
|
|
708
|
+
function GlobalStore(contents, breadcrumbsLimit) {
|
|
709
|
+
this.contents = contents;
|
|
710
|
+
this.breadcrumbsLimit = breadcrumbsLimit;
|
|
709
711
|
}
|
|
710
|
-
GlobalStore.
|
|
711
|
-
return
|
|
712
|
+
GlobalStore.create = function (contents, breadcrumbsLimit) {
|
|
713
|
+
return new GlobalStore(contents, breadcrumbsLimit);
|
|
712
714
|
};
|
|
713
|
-
GlobalStore.prototype.
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
715
|
+
GlobalStore.prototype.available = function () {
|
|
716
|
+
return true;
|
|
717
|
+
};
|
|
718
|
+
GlobalStore.prototype.getContents = function (key) {
|
|
719
|
+
var value = key ? this.contents[key] : this.contents;
|
|
720
|
+
return JSON.parse(JSON.stringify(value));
|
|
721
|
+
};
|
|
722
|
+
GlobalStore.prototype.setContext = function (context) {
|
|
723
|
+
this.contents.context = (0, util_1$4.merge)(this.contents.context, context || {});
|
|
724
|
+
};
|
|
725
|
+
GlobalStore.prototype.addBreadcrumb = function (breadcrumb) {
|
|
726
|
+
if (this.contents.breadcrumbs.length == this.breadcrumbsLimit) {
|
|
727
|
+
this.contents.breadcrumbs.shift();
|
|
717
728
|
}
|
|
718
|
-
this.
|
|
719
|
-
|
|
729
|
+
this.contents.breadcrumbs.push(breadcrumb);
|
|
730
|
+
};
|
|
731
|
+
GlobalStore.prototype.clear = function () {
|
|
732
|
+
this.contents.context = {};
|
|
733
|
+
this.contents.breadcrumbs = [];
|
|
734
|
+
};
|
|
735
|
+
GlobalStore.prototype.run = function (callback) {
|
|
736
|
+
return callback();
|
|
720
737
|
};
|
|
721
738
|
return GlobalStore;
|
|
722
739
|
}());
|
|
@@ -740,7 +757,7 @@ var store_1 = store;
|
|
|
740
757
|
var notifier = {
|
|
741
758
|
name: 'honeybadger-js',
|
|
742
759
|
url: 'https://github.com/honeybadger-io/honeybadger-js',
|
|
743
|
-
version: '4.
|
|
760
|
+
version: '4.6.0'
|
|
744
761
|
};
|
|
745
762
|
// Split at commas and spaces
|
|
746
763
|
var TAG_SEPARATOR = /,|\s+/;
|
|
@@ -754,9 +771,7 @@ var Client = /** @class */ (function () {
|
|
|
754
771
|
this.__beforeNotifyHandlers = [];
|
|
755
772
|
this.__afterNotifyHandlers = [];
|
|
756
773
|
this.config = __assign({ apiKey: null, endpoint: 'https://api.honeybadger.io', environment: null, hostname: null, projectRoot: null, component: null, action: null, revision: null, reportData: null, breadcrumbsEnabled: true, maxBreadcrumbs: 40, maxObjectDepth: 8, logger: console, developmentEnvironments: ['dev', 'development', 'test'], debug: false, tags: null, enableUncaught: true, enableUnhandledRejection: true, afterUncaught: function () { return true; }, filters: ['creditcard', 'password'], __plugins: [] }, opts);
|
|
757
|
-
|
|
758
|
-
// Webserver middleware can then switch to the AsyncStore for async context tracking.
|
|
759
|
-
this.__store = new store_1.GlobalStore({ context: {}, breadcrumbs: [] });
|
|
774
|
+
this.__initStore();
|
|
760
775
|
this.__transport = transport;
|
|
761
776
|
this.logger = (0, util_1$3.logger)(this);
|
|
762
777
|
}
|
|
@@ -775,8 +790,8 @@ var Client = /** @class */ (function () {
|
|
|
775
790
|
}
|
|
776
791
|
return this;
|
|
777
792
|
};
|
|
778
|
-
Client.prototype.
|
|
779
|
-
this.__store =
|
|
793
|
+
Client.prototype.__initStore = function () {
|
|
794
|
+
this.__store = new store_1.GlobalStore({ context: {}, breadcrumbs: [] }, this.config.maxBreadcrumbs);
|
|
780
795
|
};
|
|
781
796
|
Client.prototype.beforeNotify = function (handler) {
|
|
782
797
|
this.__beforeNotifyHandlers.push(handler);
|
|
@@ -787,27 +802,21 @@ var Client = /** @class */ (function () {
|
|
|
787
802
|
return this;
|
|
788
803
|
};
|
|
789
804
|
Client.prototype.setContext = function (context) {
|
|
790
|
-
if (typeof context === 'object') {
|
|
791
|
-
|
|
792
|
-
store.context = (0, util_1$3.merge)(store.context, context);
|
|
805
|
+
if (typeof context === 'object' && context != null) {
|
|
806
|
+
this.__store.setContext(context);
|
|
793
807
|
}
|
|
794
808
|
return this;
|
|
795
809
|
};
|
|
796
810
|
Client.prototype.resetContext = function (context) {
|
|
797
811
|
this.logger.warn('Deprecation warning: `Honeybadger.resetContext()` has been deprecated; please use `Honeybadger.clear()` instead.');
|
|
798
|
-
|
|
812
|
+
this.__store.clear();
|
|
799
813
|
if (typeof context === 'object' && context !== null) {
|
|
800
|
-
|
|
801
|
-
}
|
|
802
|
-
else {
|
|
803
|
-
store.context = {};
|
|
814
|
+
this.__store.setContext(context);
|
|
804
815
|
}
|
|
805
816
|
return this;
|
|
806
817
|
};
|
|
807
818
|
Client.prototype.clear = function () {
|
|
808
|
-
|
|
809
|
-
store.context = {};
|
|
810
|
-
store.breadcrumbs = [];
|
|
819
|
+
this.__store.clear();
|
|
811
820
|
return this;
|
|
812
821
|
};
|
|
813
822
|
Client.prototype.notify = function (noticeable, name, extra) {
|
|
@@ -852,8 +861,8 @@ var Client = /** @class */ (function () {
|
|
|
852
861
|
stack: notice.stack
|
|
853
862
|
}
|
|
854
863
|
});
|
|
855
|
-
var breadcrumbs = this.
|
|
856
|
-
notice.__breadcrumbs = this.config.breadcrumbsEnabled ? breadcrumbs
|
|
864
|
+
var breadcrumbs = this.__store.getContents('breadcrumbs');
|
|
865
|
+
notice.__breadcrumbs = this.config.breadcrumbsEnabled ? breadcrumbs : [];
|
|
857
866
|
(0, util_1$3.getSourceForBacktrace)(sourceCodeData, this.__getSourceFileHandler)
|
|
858
867
|
.then(function (sourcePerTrace) {
|
|
859
868
|
sourcePerTrace.forEach(function (source, index) {
|
|
@@ -954,7 +963,7 @@ var Client = /** @class */ (function () {
|
|
|
954
963
|
if ((0, util_1$3.objectIsEmpty)(notice)) {
|
|
955
964
|
return null;
|
|
956
965
|
}
|
|
957
|
-
var context = this.
|
|
966
|
+
var context = this.__store.getContents('context');
|
|
958
967
|
var noticeTags = this.__constructTags(notice.tags);
|
|
959
968
|
var contextTags = this.__constructTags(context['tags']);
|
|
960
969
|
var configTags = this.__constructTags(this.config.tags);
|
|
@@ -987,21 +996,20 @@ var Client = /** @class */ (function () {
|
|
|
987
996
|
var metadata = (0, util_1$3.shallowClone)(opts.metadata);
|
|
988
997
|
var category = opts.category || 'custom';
|
|
989
998
|
var timestamp = new Date().toISOString();
|
|
990
|
-
|
|
991
|
-
var breadcrumbs = store.breadcrumbs;
|
|
992
|
-
breadcrumbs.push({
|
|
999
|
+
this.__store.addBreadcrumb({
|
|
993
1000
|
category: category,
|
|
994
1001
|
message: message,
|
|
995
1002
|
metadata: metadata,
|
|
996
1003
|
timestamp: timestamp
|
|
997
1004
|
});
|
|
998
|
-
var limit = this.config.maxBreadcrumbs;
|
|
999
|
-
if (breadcrumbs.length > limit) {
|
|
1000
|
-
breadcrumbs = breadcrumbs.slice(breadcrumbs.length - limit);
|
|
1001
|
-
}
|
|
1002
|
-
store.breadcrumbs = breadcrumbs;
|
|
1003
1005
|
return this;
|
|
1004
1006
|
};
|
|
1007
|
+
Client.prototype.__getBreadcrumbs = function () {
|
|
1008
|
+
return this.__store.getContents('breadcrumbs').slice();
|
|
1009
|
+
};
|
|
1010
|
+
Client.prototype.__getContext = function () {
|
|
1011
|
+
return this.__store.getContents('context');
|
|
1012
|
+
};
|
|
1005
1013
|
Client.prototype.__developmentMode = function () {
|
|
1006
1014
|
if (this.config.reportData === true) {
|
|
1007
1015
|
return false;
|
|
@@ -1050,16 +1058,6 @@ var Client = /** @class */ (function () {
|
|
|
1050
1058
|
}
|
|
1051
1059
|
return tags.toString().split(TAG_SEPARATOR).filter(function (tag) { return NOT_BLANK.test(tag); });
|
|
1052
1060
|
};
|
|
1053
|
-
/**
|
|
1054
|
-
* For ALS, the store may be uninitialized (if .run()` has not been called).
|
|
1055
|
-
* This provides an easy way to read the existing store object or fall back to a default.
|
|
1056
|
-
* Returns *a copy* of the s tore contents.
|
|
1057
|
-
*/
|
|
1058
|
-
Client.prototype.__getStoreContentsOrDefault = function () {
|
|
1059
|
-
var existingStoreContents = this.__store.getStore();
|
|
1060
|
-
var storeContents = existingStoreContents || {};
|
|
1061
|
-
return __assign({ context: {}, breadcrumbs: [] }, storeContents);
|
|
1062
|
-
};
|
|
1063
1061
|
return Client;
|
|
1064
1062
|
}());
|
|
1065
1063
|
client.Client = Client;
|
|
@@ -1085,6 +1083,9 @@ Object.defineProperty(types, "__esModule", { value: true });
|
|
|
1085
1083
|
}) : function(o, v) {
|
|
1086
1084
|
o["default"] = v;
|
|
1087
1085
|
});
|
|
1086
|
+
var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) {
|
|
1087
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
1088
|
+
};
|
|
1088
1089
|
var __importStar = (commonjsGlobal && commonjsGlobal.__importStar) || function (mod) {
|
|
1089
1090
|
if (mod && mod.__esModule) return mod;
|
|
1090
1091
|
var result = {};
|
|
@@ -1093,10 +1094,10 @@ Object.defineProperty(types, "__esModule", { value: true });
|
|
|
1093
1094
|
return result;
|
|
1094
1095
|
};
|
|
1095
1096
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1096
|
-
exports.Util = exports.Types = exports.
|
|
1097
|
+
exports.Util = exports.Types = exports.Client = void 0;
|
|
1097
1098
|
var client_1 = client;
|
|
1098
1099
|
Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_1.Client; } });
|
|
1099
|
-
|
|
1100
|
+
__exportStar(store, exports);
|
|
1100
1101
|
exports.Types = __importStar(types);
|
|
1101
1102
|
exports.Util = __importStar(util$1);
|
|
1102
1103
|
} (src));
|
|
@@ -1237,25 +1238,8 @@ var uncaught_exception = {};
|
|
|
1237
1238
|
|
|
1238
1239
|
var aws_lambda = {};
|
|
1239
1240
|
|
|
1240
|
-
var async_store = {};
|
|
1241
|
-
|
|
1242
|
-
Object.defineProperty(async_store, "__esModule", { value: true });
|
|
1243
|
-
async_store.AsyncStore = void 0;
|
|
1244
|
-
var core_1$1 = src;
|
|
1245
|
-
var Store;
|
|
1246
|
-
try {
|
|
1247
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
1248
|
-
var AsyncLocalStorage = require('async_hooks').AsyncLocalStorage;
|
|
1249
|
-
Store = new AsyncLocalStorage();
|
|
1250
|
-
}
|
|
1251
|
-
catch (e) {
|
|
1252
|
-
Store = new core_1$1.Store.GlobalStore({ context: {}, breadcrumbs: [] });
|
|
1253
|
-
}
|
|
1254
|
-
async_store.AsyncStore = Store;
|
|
1255
|
-
|
|
1256
1241
|
Object.defineProperty(aws_lambda, "__esModule", { value: true });
|
|
1257
1242
|
aws_lambda.removeAwsDefaultUncaughtExceptionListener = aws_lambda.lambdaHandler = void 0;
|
|
1258
|
-
var async_store_1 = async_store;
|
|
1259
1243
|
function isHandlerSync(handler) {
|
|
1260
1244
|
return handler.length > 2;
|
|
1261
1245
|
}
|
|
@@ -1269,9 +1253,8 @@ function reportToHoneybadger(hb, err, callback) {
|
|
|
1269
1253
|
}
|
|
1270
1254
|
function asyncHandler(handler, hb) {
|
|
1271
1255
|
return function wrappedLambdaHandler(event, context) {
|
|
1272
|
-
hb.__setStore(async_store_1.AsyncStore);
|
|
1273
1256
|
return new Promise(function (resolve, reject) {
|
|
1274
|
-
|
|
1257
|
+
hb.run(function () {
|
|
1275
1258
|
var timeoutHandler = setupTimeoutWarning(hb, context);
|
|
1276
1259
|
try {
|
|
1277
1260
|
var result = handler(event, context);
|
|
@@ -1297,8 +1280,7 @@ function asyncHandler(handler, hb) {
|
|
|
1297
1280
|
}
|
|
1298
1281
|
function syncHandler(handler, hb) {
|
|
1299
1282
|
return function wrappedLambdaHandler(event, context, cb) {
|
|
1300
|
-
hb.
|
|
1301
|
-
async_store_1.AsyncStore.run({ context: {}, breadcrumbs: [] }, function () {
|
|
1283
|
+
hb.run(function () {
|
|
1302
1284
|
var timeoutHandler = setupTimeoutWarning(hb, context);
|
|
1303
1285
|
try {
|
|
1304
1286
|
handler(event, context, function (error, result) {
|
|
@@ -1467,12 +1449,12 @@ var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || func
|
|
|
1467
1449
|
};
|
|
1468
1450
|
Object.defineProperty(transport, "__esModule", { value: true });
|
|
1469
1451
|
transport.ServerTransport = void 0;
|
|
1470
|
-
var core_1 = src;
|
|
1452
|
+
var core_1$1 = src;
|
|
1471
1453
|
var url_1 = require$$0__default$1["default"];
|
|
1472
1454
|
var http_1 = __importDefault(require$$2__default$1["default"]);
|
|
1473
1455
|
var https_1 = __importDefault(require$$3__default["default"]);
|
|
1474
1456
|
var util_1 = util;
|
|
1475
|
-
var sanitize = core_1.Util.sanitize;
|
|
1457
|
+
var sanitize = core_1$1.Util.sanitize;
|
|
1476
1458
|
var ServerTransport = /** @class */ (function () {
|
|
1477
1459
|
function ServerTransport() {
|
|
1478
1460
|
}
|
|
@@ -1536,6 +1518,126 @@ var ServerTransport = /** @class */ (function () {
|
|
|
1536
1518
|
}());
|
|
1537
1519
|
transport.ServerTransport = ServerTransport;
|
|
1538
1520
|
|
|
1521
|
+
var stacked_store = {};
|
|
1522
|
+
|
|
1523
|
+
var async_store = {};
|
|
1524
|
+
|
|
1525
|
+
Object.defineProperty(async_store, "__esModule", { value: true });
|
|
1526
|
+
async_store.AsyncStore = void 0;
|
|
1527
|
+
var kHoneybadgerStore = Symbol.for('kHoneybadgerStore');
|
|
1528
|
+
var AsyncStore = /** @class */ (function () {
|
|
1529
|
+
function AsyncStore(asyncLocalStorage, contents, breadcrumbsLimit) {
|
|
1530
|
+
this.als = asyncLocalStorage;
|
|
1531
|
+
this.contents = contents;
|
|
1532
|
+
this.breadcrumbsLimit = breadcrumbsLimit;
|
|
1533
|
+
}
|
|
1534
|
+
/**
|
|
1535
|
+
* Attempt to create a new AsyncStore instance
|
|
1536
|
+
*/
|
|
1537
|
+
AsyncStore.create = function (contents, breadcrumbsLimit) {
|
|
1538
|
+
try {
|
|
1539
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
1540
|
+
var AsyncLocalStorage_1 = require('async_hooks').AsyncLocalStorage;
|
|
1541
|
+
return new AsyncStore(new AsyncLocalStorage_1, contents, breadcrumbsLimit);
|
|
1542
|
+
}
|
|
1543
|
+
catch (e) {
|
|
1544
|
+
return null;
|
|
1545
|
+
}
|
|
1546
|
+
};
|
|
1547
|
+
/**
|
|
1548
|
+
* This returns the live store object, so we can mutate it.
|
|
1549
|
+
* If we're in an async context (a `run()` callback), the stored contents at this point will be returned.
|
|
1550
|
+
* Otherwise, the initial stored contents will be returned.
|
|
1551
|
+
*/
|
|
1552
|
+
AsyncStore.prototype.__currentContents = function () {
|
|
1553
|
+
return this.als.getStore() || this.contents;
|
|
1554
|
+
};
|
|
1555
|
+
AsyncStore.prototype.getContents = function (key) {
|
|
1556
|
+
var value = key ? this.__currentContents()[key] : this.__currentContents();
|
|
1557
|
+
return JSON.parse(JSON.stringify(value));
|
|
1558
|
+
};
|
|
1559
|
+
AsyncStore.prototype.available = function () {
|
|
1560
|
+
return !!this.als.getStore();
|
|
1561
|
+
};
|
|
1562
|
+
AsyncStore.prototype.setContext = function (context) {
|
|
1563
|
+
Object.assign(this.__currentContents().context, context || {});
|
|
1564
|
+
};
|
|
1565
|
+
AsyncStore.prototype.addBreadcrumb = function (breadcrumb) {
|
|
1566
|
+
if (this.__currentContents().breadcrumbs.length == this.breadcrumbsLimit) {
|
|
1567
|
+
this.__currentContents().breadcrumbs.shift();
|
|
1568
|
+
}
|
|
1569
|
+
this.__currentContents().breadcrumbs.push(breadcrumb);
|
|
1570
|
+
};
|
|
1571
|
+
AsyncStore.prototype.clear = function () {
|
|
1572
|
+
this.__currentContents().context = {};
|
|
1573
|
+
this.__currentContents().breadcrumbs = [];
|
|
1574
|
+
};
|
|
1575
|
+
AsyncStore.prototype.run = function (callback, request) {
|
|
1576
|
+
// When entering an async context, we pass in *a copy* of the initial contents.
|
|
1577
|
+
// This allows every request to start from the same state
|
|
1578
|
+
// and add data specific to them, without overlapping.
|
|
1579
|
+
if (!request) {
|
|
1580
|
+
return this.als.run(this.getContents(), callback);
|
|
1581
|
+
}
|
|
1582
|
+
var contents;
|
|
1583
|
+
if (request[kHoneybadgerStore]) {
|
|
1584
|
+
contents = request[kHoneybadgerStore];
|
|
1585
|
+
}
|
|
1586
|
+
else {
|
|
1587
|
+
contents = this.getContents();
|
|
1588
|
+
request[kHoneybadgerStore] = contents;
|
|
1589
|
+
}
|
|
1590
|
+
return this.als.run(contents, callback);
|
|
1591
|
+
};
|
|
1592
|
+
return AsyncStore;
|
|
1593
|
+
}());
|
|
1594
|
+
async_store.AsyncStore = AsyncStore;
|
|
1595
|
+
|
|
1596
|
+
Object.defineProperty(stacked_store, "__esModule", { value: true });
|
|
1597
|
+
stacked_store.StackedStore = void 0;
|
|
1598
|
+
var core_1 = src;
|
|
1599
|
+
var async_store_1 = async_store;
|
|
1600
|
+
/**
|
|
1601
|
+
* A store that's really a "stack" of stores (async and global)
|
|
1602
|
+
* Will proxy calls to the async store if it's active (ie when we enter an async context via `ALS.run()`),
|
|
1603
|
+
* otherwise it will fall back to the global store.
|
|
1604
|
+
* Both stores in the stack start out with the same contents object.
|
|
1605
|
+
* Note that the asyncStore may be null if ALS is not supported.
|
|
1606
|
+
*/
|
|
1607
|
+
var StackedStore = /** @class */ (function () {
|
|
1608
|
+
function StackedStore(breadcrumbsLimit) {
|
|
1609
|
+
this.contents = { context: {}, breadcrumbs: [] };
|
|
1610
|
+
this.asyncStore = async_store_1.AsyncStore.create(this.contents, breadcrumbsLimit);
|
|
1611
|
+
this.globalStore = core_1.GlobalStore.create(this.contents, breadcrumbsLimit);
|
|
1612
|
+
}
|
|
1613
|
+
StackedStore.prototype.__activeStore = function () {
|
|
1614
|
+
var _a;
|
|
1615
|
+
return ((_a = this.asyncStore) === null || _a === void 0 ? void 0 : _a.available()) ? this.asyncStore : this.globalStore;
|
|
1616
|
+
};
|
|
1617
|
+
StackedStore.prototype.available = function () {
|
|
1618
|
+
return true;
|
|
1619
|
+
};
|
|
1620
|
+
// @ts-ignore
|
|
1621
|
+
StackedStore.prototype.getContents = function (key) {
|
|
1622
|
+
return this.__activeStore().getContents(key);
|
|
1623
|
+
};
|
|
1624
|
+
StackedStore.prototype.setContext = function (context) {
|
|
1625
|
+
this.__activeStore().setContext(context);
|
|
1626
|
+
};
|
|
1627
|
+
StackedStore.prototype.addBreadcrumb = function (breadcrumb) {
|
|
1628
|
+
this.__activeStore().addBreadcrumb(breadcrumb);
|
|
1629
|
+
};
|
|
1630
|
+
StackedStore.prototype.clear = function () {
|
|
1631
|
+
this.__activeStore().clear();
|
|
1632
|
+
};
|
|
1633
|
+
StackedStore.prototype.run = function (callback, request) {
|
|
1634
|
+
// We explicitly favour the async store here, if ALS is supported. It's the whole point of the `run()` method
|
|
1635
|
+
return this.asyncStore ? this.asyncStore.run(callback, request) : this.globalStore.run(callback);
|
|
1636
|
+
};
|
|
1637
|
+
return StackedStore;
|
|
1638
|
+
}());
|
|
1639
|
+
stacked_store.StackedStore = StackedStore;
|
|
1640
|
+
|
|
1539
1641
|
(function (exports) {
|
|
1540
1642
|
var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
|
|
1541
1643
|
var extendStatics = function (d, b) {
|
|
@@ -1576,10 +1678,9 @@ transport.ServerTransport = ServerTransport;
|
|
|
1576
1678
|
var unhandled_rejection_1 = __importDefault(unhandled_rejection);
|
|
1577
1679
|
var middleware_1 = middleware;
|
|
1578
1680
|
var aws_lambda_1 = aws_lambda;
|
|
1579
|
-
var async_store_1 = async_store;
|
|
1580
1681
|
var transport_1 = transport;
|
|
1682
|
+
var stacked_store_1 = stacked_store;
|
|
1581
1683
|
var endpoint = core_1.Util.endpoint;
|
|
1582
|
-
var kHoneybadgerStore = Symbol.for('kHoneybadgerStore');
|
|
1583
1684
|
var Honeybadger = /** @class */ (function (_super) {
|
|
1584
1685
|
__extends(Honeybadger, _super);
|
|
1585
1686
|
function Honeybadger(opts) {
|
|
@@ -1619,6 +1720,10 @@ transport.ServerTransport = ServerTransport;
|
|
|
1619
1720
|
if (opts === void 0) { opts = {}; }
|
|
1620
1721
|
return _super.prototype.configure.call(this, opts);
|
|
1621
1722
|
};
|
|
1723
|
+
Honeybadger.prototype.__initStore = function () {
|
|
1724
|
+
// @ts-ignore
|
|
1725
|
+
this.__store = new stacked_store_1.StackedStore(this.config.maxBreadcrumbs);
|
|
1726
|
+
};
|
|
1622
1727
|
Honeybadger.prototype.checkIn = function (id) {
|
|
1623
1728
|
var _this = this;
|
|
1624
1729
|
return this.__transport
|
|
@@ -1641,14 +1746,10 @@ transport.ServerTransport = ServerTransport;
|
|
|
1641
1746
|
// 1. Using AsyncLocalStorage so the context is tracked across async operations.
|
|
1642
1747
|
// 2. Attaching the store contents to the request object,
|
|
1643
1748
|
// so, even if the store is destroyed, we can still recover the context for a given request
|
|
1749
|
+
// (for example, in an error-handling middleware)
|
|
1644
1750
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1645
1751
|
Honeybadger.prototype.withRequest = function (request, handler, onError) {
|
|
1646
1752
|
var _this = this;
|
|
1647
|
-
var storeObject = (request[kHoneybadgerStore] || this.__getStoreContentsOrDefault());
|
|
1648
|
-
this.__setStore(async_store_1.AsyncStore);
|
|
1649
|
-
if (!request[kHoneybadgerStore]) {
|
|
1650
|
-
request[kHoneybadgerStore] = storeObject;
|
|
1651
|
-
}
|
|
1652
1753
|
if (onError) {
|
|
1653
1754
|
// ALS is fine for context-tracking, but `domain` allows us to catch errors
|
|
1654
1755
|
// thrown asynchronously (timers, event emitters)
|
|
@@ -1657,11 +1758,14 @@ transport.ServerTransport = ServerTransport;
|
|
|
1657
1758
|
// Note that this doesn't still handle all cases. `domain` has its own problems:
|
|
1658
1759
|
// See https://github.com/honeybadger-io/honeybadger-js/pull/711
|
|
1659
1760
|
var dom = domain_1.default.create();
|
|
1660
|
-
var onErrorWithContext = function (err) { return _this.__store.run(
|
|
1761
|
+
var onErrorWithContext = function (err) { return _this.__store.run(function () { return onError(err); }, request); };
|
|
1661
1762
|
dom.on('error', onErrorWithContext);
|
|
1662
1763
|
handler = dom.bind(handler);
|
|
1663
1764
|
}
|
|
1664
|
-
return this.__store.run(
|
|
1765
|
+
return this.__store.run(handler, request);
|
|
1766
|
+
};
|
|
1767
|
+
Honeybadger.prototype.run = function (callback) {
|
|
1768
|
+
return this.__store.run(callback);
|
|
1665
1769
|
};
|
|
1666
1770
|
return Honeybadger;
|
|
1667
1771
|
}(core_1.Client));
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { GlobalStore, Types } from '@honeybadger-io/core';
|
|
2
|
+
import { AsyncStore } from './types/async_store';
|
|
3
|
+
/**
|
|
4
|
+
* A store that's really a "stack" of stores (async and global)
|
|
5
|
+
* Will proxy calls to the async store if it's active (ie when we enter an async context via `ALS.run()`),
|
|
6
|
+
* otherwise it will fall back to the global store.
|
|
7
|
+
* Both stores in the stack start out with the same contents object.
|
|
8
|
+
* Note that the asyncStore may be null if ALS is not supported.
|
|
9
|
+
*/
|
|
10
|
+
export declare class StackedStore implements Types.HoneybadgerStore {
|
|
11
|
+
private readonly contents;
|
|
12
|
+
private readonly asyncStore;
|
|
13
|
+
private readonly globalStore;
|
|
14
|
+
constructor(breadcrumbsLimit: number);
|
|
15
|
+
__activeStore(): AsyncStore | GlobalStore;
|
|
16
|
+
available(): boolean;
|
|
17
|
+
getContents(key?: keyof Types.StoreContents): any;
|
|
18
|
+
setContext(context: any): void;
|
|
19
|
+
addBreadcrumb(breadcrumb: any): void;
|
|
20
|
+
clear(): void;
|
|
21
|
+
run<R>(callback: () => R, request?: Record<symbol, unknown>): R;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=stacked_store.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@honeybadger-io/js",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"homepage": "https://github.com/honeybadger-io/honeybadger-js/tree/master/packages/js",
|
|
6
6
|
"author": {
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"postpublish": "./scripts/release-cdn.sh"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@honeybadger-io/core": "^4.
|
|
53
|
+
"@honeybadger-io/core": "^4.6.0",
|
|
54
54
|
"@types/aws-lambda": "^8.10.89"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"publishConfig": {
|
|
75
75
|
"access": "public"
|
|
76
76
|
},
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "91209fc67df96975d1cacf057d4bbf16e29943d5"
|
|
78
78
|
}
|