@devmoods/sentry 0.5.1 → 0.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/coverage/base.css +262 -124
- package/coverage/block-navigation.js +64 -69
- package/coverage/clover.xml +3 -3
- package/coverage/coverage-final.json +1 -1
- package/coverage/index.html +1 -1
- package/coverage/index.ts.html +15 -33
- package/coverage/prettify.css +101 -1
- package/coverage/prettify.js +936 -1
- package/coverage/sorter.js +187 -192
- package/dist/index.d.ts +0 -2
- package/dist/index.js +10 -13
- package/package.json +6 -6
- package/src/__tests__/index.spec.ts +25 -12
- package/src/index.ts +13 -19
package/coverage/sorter.js
CHANGED
|
@@ -1,210 +1,205 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
|
-
var addSorting = (function() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
var addSorting = (function () {
|
|
3
|
+
"use strict";
|
|
4
|
+
var cols,
|
|
5
|
+
currentSort = {
|
|
6
|
+
index: 0,
|
|
7
|
+
desc: false,
|
|
8
|
+
};
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
10
|
+
// returns the summary table element
|
|
11
|
+
function getTable() {
|
|
12
|
+
return document.querySelector(".coverage-summary");
|
|
13
|
+
}
|
|
14
|
+
// returns the thead element of the summary table
|
|
15
|
+
function getTableHeader() {
|
|
16
|
+
return getTable().querySelector("thead tr");
|
|
17
|
+
}
|
|
18
|
+
// returns the tbody element of the summary table
|
|
19
|
+
function getTableBody() {
|
|
20
|
+
return getTable().querySelector("tbody");
|
|
21
|
+
}
|
|
22
|
+
// returns the th element for nth column
|
|
23
|
+
function getNthColumn(n) {
|
|
24
|
+
return getTableHeader().querySelectorAll("th")[n];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function onFilterInput() {
|
|
28
|
+
const searchValue = document.getElementById("fileSearch").value;
|
|
29
|
+
const rows = document.getElementsByTagName("tbody")[0].children;
|
|
30
|
+
|
|
31
|
+
// Try to create a RegExp from the searchValue. If it fails (invalid regex),
|
|
32
|
+
// it will be treated as a plain text search
|
|
33
|
+
let searchRegex;
|
|
34
|
+
try {
|
|
35
|
+
searchRegex = new RegExp(searchValue, "i"); // 'i' for case-insensitive
|
|
36
|
+
} catch (error) {
|
|
37
|
+
searchRegex = null;
|
|
25
38
|
}
|
|
26
39
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// Try to create a RegExp from the searchValue. If it fails (invalid regex),
|
|
32
|
-
// it will be treated as a plain text search
|
|
33
|
-
let searchRegex;
|
|
34
|
-
try {
|
|
35
|
-
searchRegex = new RegExp(searchValue, 'i'); // 'i' for case-insensitive
|
|
36
|
-
} catch (error) {
|
|
37
|
-
searchRegex = null;
|
|
38
|
-
}
|
|
40
|
+
for (let i = 0; i < rows.length; i++) {
|
|
41
|
+
const row = rows[i];
|
|
42
|
+
let isMatch = false;
|
|
39
43
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
} else {
|
|
48
|
-
// Otherwise, fall back to the original plain text search
|
|
49
|
-
isMatch = row.textContent
|
|
50
|
-
.toLowerCase()
|
|
51
|
-
.includes(searchValue.toLowerCase());
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
row.style.display = isMatch ? '' : 'none';
|
|
55
|
-
}
|
|
56
|
-
}
|
|
44
|
+
if (searchRegex) {
|
|
45
|
+
// If a valid regex was created, use it for matching
|
|
46
|
+
isMatch = searchRegex.test(row.textContent);
|
|
47
|
+
} else {
|
|
48
|
+
// Otherwise, fall back to the original plain text search
|
|
49
|
+
isMatch = row.textContent.toLowerCase().includes(searchValue.toLowerCase());
|
|
50
|
+
}
|
|
57
51
|
|
|
58
|
-
|
|
59
|
-
function addSearchBox() {
|
|
60
|
-
var template = document.getElementById('filterTemplate');
|
|
61
|
-
var templateClone = template.content.cloneNode(true);
|
|
62
|
-
templateClone.getElementById('fileSearch').oninput = onFilterInput;
|
|
63
|
-
template.parentElement.appendChild(templateClone);
|
|
52
|
+
row.style.display = isMatch ? "" : "none";
|
|
64
53
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// loads the search box
|
|
57
|
+
function addSearchBox() {
|
|
58
|
+
var template = document.getElementById("filterTemplate");
|
|
59
|
+
var templateClone = template.content.cloneNode(true);
|
|
60
|
+
templateClone.getElementById("fileSearch").oninput = onFilterInput;
|
|
61
|
+
template.parentElement.appendChild(templateClone);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// loads all columns
|
|
65
|
+
function loadColumns() {
|
|
66
|
+
var colNodes = getTableHeader().querySelectorAll("th"),
|
|
67
|
+
colNode,
|
|
68
|
+
cols = [],
|
|
69
|
+
col,
|
|
70
|
+
i;
|
|
71
|
+
|
|
72
|
+
for (i = 0; i < colNodes.length; i += 1) {
|
|
73
|
+
colNode = colNodes[i];
|
|
74
|
+
col = {
|
|
75
|
+
key: colNode.getAttribute("data-col"),
|
|
76
|
+
sortable: !colNode.getAttribute("data-nosort"),
|
|
77
|
+
type: colNode.getAttribute("data-type") || "string",
|
|
78
|
+
};
|
|
79
|
+
cols.push(col);
|
|
80
|
+
if (col.sortable) {
|
|
81
|
+
col.defaultDescSort = col.type === "number";
|
|
82
|
+
colNode.innerHTML = colNode.innerHTML + '<span class="sorter"></span>';
|
|
83
|
+
}
|
|
89
84
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
85
|
+
return cols;
|
|
86
|
+
}
|
|
87
|
+
// attaches a data attribute to every tr element with an object
|
|
88
|
+
// of data values keyed by column name
|
|
89
|
+
function loadRowData(tableRow) {
|
|
90
|
+
var tableCols = tableRow.querySelectorAll("td"),
|
|
91
|
+
colNode,
|
|
92
|
+
col,
|
|
93
|
+
data = {},
|
|
94
|
+
i,
|
|
95
|
+
val;
|
|
96
|
+
for (i = 0; i < tableCols.length; i += 1) {
|
|
97
|
+
colNode = tableCols[i];
|
|
98
|
+
col = cols[i];
|
|
99
|
+
val = colNode.getAttribute("data-value");
|
|
100
|
+
if (col.type === "number") {
|
|
101
|
+
val = Number(val);
|
|
102
|
+
}
|
|
103
|
+
data[col.key] = val;
|
|
109
104
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
105
|
+
return data;
|
|
106
|
+
}
|
|
107
|
+
// loads all row data
|
|
108
|
+
function loadData() {
|
|
109
|
+
var rows = getTableBody().querySelectorAll("tr"),
|
|
110
|
+
i;
|
|
111
|
+
|
|
112
|
+
for (i = 0; i < rows.length; i += 1) {
|
|
113
|
+
rows[i].data = loadRowData(rows[i]);
|
|
118
114
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
for (i = 0; i < rowNodes.length; i += 1) {
|
|
140
|
-
rows.push(rowNodes[i]);
|
|
141
|
-
tableBody.removeChild(rowNodes[i]);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
rows.sort(finalSorter);
|
|
145
|
-
|
|
146
|
-
for (i = 0; i < rows.length; i += 1) {
|
|
147
|
-
tableBody.appendChild(rows[i]);
|
|
148
|
-
}
|
|
115
|
+
}
|
|
116
|
+
// sorts the table using the data for the ith column
|
|
117
|
+
function sortByIndex(index, desc) {
|
|
118
|
+
var key = cols[index].key,
|
|
119
|
+
sorter = function (a, b) {
|
|
120
|
+
a = a.data[key];
|
|
121
|
+
b = b.data[key];
|
|
122
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
123
|
+
},
|
|
124
|
+
finalSorter = sorter,
|
|
125
|
+
tableBody = document.querySelector(".coverage-summary tbody"),
|
|
126
|
+
rowNodes = tableBody.querySelectorAll("tr"),
|
|
127
|
+
rows = [],
|
|
128
|
+
i;
|
|
129
|
+
|
|
130
|
+
if (desc) {
|
|
131
|
+
finalSorter = function (a, b) {
|
|
132
|
+
return -1 * sorter(a, b);
|
|
133
|
+
};
|
|
149
134
|
}
|
|
150
|
-
// removes sort indicators for current column being sorted
|
|
151
|
-
function removeSortIndicators() {
|
|
152
|
-
var col = getNthColumn(currentSort.index),
|
|
153
|
-
cls = col.className;
|
|
154
135
|
|
|
155
|
-
|
|
156
|
-
|
|
136
|
+
for (i = 0; i < rowNodes.length; i += 1) {
|
|
137
|
+
rows.push(rowNodes[i]);
|
|
138
|
+
tableBody.removeChild(rowNodes[i]);
|
|
157
139
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
140
|
+
|
|
141
|
+
rows.sort(finalSorter);
|
|
142
|
+
|
|
143
|
+
for (i = 0; i < rows.length; i += 1) {
|
|
144
|
+
tableBody.appendChild(rows[i]);
|
|
163
145
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
146
|
+
}
|
|
147
|
+
// removes sort indicators for current column being sorted
|
|
148
|
+
function removeSortIndicators() {
|
|
149
|
+
var col = getNthColumn(currentSort.index),
|
|
150
|
+
cls = col.className;
|
|
151
|
+
|
|
152
|
+
cls = cls.replace(/ sorted$/, "").replace(/ sorted-desc$/, "");
|
|
153
|
+
col.className = cls;
|
|
154
|
+
}
|
|
155
|
+
// adds sort indicators for current column being sorted
|
|
156
|
+
function addSortIndicators() {
|
|
157
|
+
getNthColumn(currentSort.index).className += currentSort.desc ? " sorted-desc" : " sorted";
|
|
158
|
+
}
|
|
159
|
+
// adds event listeners for all sorter widgets
|
|
160
|
+
function enableUI() {
|
|
161
|
+
var i,
|
|
162
|
+
el,
|
|
163
|
+
ithSorter = function ithSorter(i) {
|
|
164
|
+
var col = cols[i];
|
|
165
|
+
|
|
166
|
+
return function () {
|
|
167
|
+
var desc = col.defaultDescSort;
|
|
168
|
+
|
|
169
|
+
if (currentSort.index === i) {
|
|
170
|
+
desc = !currentSort.desc;
|
|
171
|
+
}
|
|
172
|
+
sortByIndex(i, desc);
|
|
173
|
+
removeSortIndicators();
|
|
174
|
+
currentSort.index = i;
|
|
175
|
+
currentSort.desc = desc;
|
|
176
|
+
addSortIndicators();
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
for (i = 0; i < cols.length; i += 1) {
|
|
180
|
+
if (cols[i].sortable) {
|
|
181
|
+
// add the click event handler on the th so users
|
|
182
|
+
// dont have to click on those tiny arrows
|
|
183
|
+
el = getNthColumn(i).querySelector(".sorter").parentElement;
|
|
184
|
+
if (el.addEventListener) {
|
|
185
|
+
el.addEventListener("click", ithSorter(i));
|
|
186
|
+
} else {
|
|
187
|
+
el.attachEvent("onclick", ithSorter(i));
|
|
195
188
|
}
|
|
189
|
+
}
|
|
196
190
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
191
|
+
}
|
|
192
|
+
// adds sorting functionality to the UI
|
|
193
|
+
return function () {
|
|
194
|
+
if (!getTable()) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
cols = loadColumns();
|
|
198
|
+
loadData();
|
|
199
|
+
addSearchBox();
|
|
200
|
+
addSortIndicators();
|
|
201
|
+
enableUI();
|
|
202
|
+
};
|
|
208
203
|
})();
|
|
209
204
|
|
|
210
|
-
window.addEventListener(
|
|
205
|
+
window.addEventListener("load", addSorting);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type LoggerAdapter, type MetricAttributes, type MetricsAdapter } from '@devmoods/observability';
|
|
2
2
|
import * as Sentry from '@sentry/node';
|
|
3
|
-
import { type ErrorRequestHandler } from 'express';
|
|
4
3
|
declare module '@devmoods/config' {
|
|
5
4
|
interface Config extends ConfigFromDefs<typeof sentryConfig> {
|
|
6
5
|
}
|
|
@@ -17,7 +16,6 @@ export interface SentryOptions extends Sentry.NodeOptions {
|
|
|
17
16
|
export declare function initSentry(options?: SentryOptions): Promise<void>;
|
|
18
17
|
export declare function closeSentry(): Promise<void>;
|
|
19
18
|
export declare function sentryOptions(options?: SentryOptions): Promise<SentryOptions>;
|
|
20
|
-
export declare function sentryErrorHandler(options?: Sentry.NodeOptions): ErrorRequestHandler;
|
|
21
19
|
/**
|
|
22
20
|
* MetricsAdapter backed by `Sentry.metrics` (available in @sentry/node >=10.25.0).
|
|
23
21
|
* Requires `Sentry.init()` to have been called; calls are silently dropped when
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { config, define, t } from '@devmoods/config';
|
|
2
2
|
import {} from '@devmoods/observability';
|
|
3
3
|
import * as Sentry from '@sentry/node';
|
|
4
|
-
import {} from 'express';
|
|
5
4
|
export const sentryConfig = define({
|
|
6
5
|
SENTRY_DSN: t.string(),
|
|
7
6
|
SENTRY_TRACES_SAMPLE_RATE: t.number(0.3),
|
|
@@ -48,8 +47,16 @@ export async function sentryOptions(options = {}) {
|
|
|
48
47
|
dsn: config.SENTRY_DSN,
|
|
49
48
|
tracesSampleRate: config.SENTRY_TRACES_SAMPLE_RATE,
|
|
50
49
|
profileSessionSampleRate: config.SENTRY_PROFILES_SAMPLE_RATE,
|
|
51
|
-
integrations:
|
|
52
|
-
|
|
50
|
+
integrations: [
|
|
51
|
+
...nativeIntegrations,
|
|
52
|
+
Sentry.expressIntegration({
|
|
53
|
+
shouldHandleError(error) {
|
|
54
|
+
const status = getHttpStatusCode(error);
|
|
55
|
+
return (process.env.NODE_ENV === 'production' &&
|
|
56
|
+
(status == null || status < 400 || status >= 500));
|
|
57
|
+
},
|
|
58
|
+
}),
|
|
59
|
+
],
|
|
53
60
|
...options,
|
|
54
61
|
};
|
|
55
62
|
}
|
|
@@ -64,16 +71,6 @@ function getHttpStatusCode(error) {
|
|
|
64
71
|
? parsed
|
|
65
72
|
: undefined;
|
|
66
73
|
}
|
|
67
|
-
export function sentryErrorHandler(options = {}) {
|
|
68
|
-
return Sentry.expressErrorHandler({
|
|
69
|
-
shouldHandleError(error) {
|
|
70
|
-
const status = getHttpStatusCode(error);
|
|
71
|
-
return (process.env.NODE_ENV === 'production' &&
|
|
72
|
-
(status == null || status < 400 || status >= 500));
|
|
73
|
-
},
|
|
74
|
-
...options,
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
74
|
/**
|
|
78
75
|
* MetricsAdapter backed by `Sentry.metrics` (available in @sentry/node >=10.25.0).
|
|
79
76
|
* Requires `Sentry.init()` to have been called; calls are silently dropped when
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devmoods/sentry",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -23,14 +23,14 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@devmoods/config": "0.3.0",
|
|
26
|
-
"@devmoods/observability": "0.
|
|
27
|
-
"@sentry/node": "^
|
|
28
|
-
"@sentry/node-native": "^
|
|
29
|
-
"@sentry/profiling-node": "^
|
|
26
|
+
"@devmoods/observability": "0.5.0",
|
|
27
|
+
"@sentry/node": "^11.5.0",
|
|
28
|
+
"@sentry/node-native": "^11.5.0",
|
|
29
|
+
"@sentry/profiling-node": "^11.5.0",
|
|
30
30
|
"express": "^4.21.2"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"express": ">=4.21.2 <5.0.0"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "60fe0c3459c81c7d71a4423cdc66d046d166de75"
|
|
36
36
|
}
|
|
@@ -9,7 +9,11 @@ async function loadModuleWithSentryMock(initialized = true) {
|
|
|
9
9
|
init: vi.fn(),
|
|
10
10
|
close: vi.fn(),
|
|
11
11
|
isInitialized: vi.fn(() => initialized),
|
|
12
|
-
|
|
12
|
+
expressIntegration: vi.fn<
|
|
13
|
+
(options: { shouldHandleError(error: unknown): boolean }) => {
|
|
14
|
+
name: string;
|
|
15
|
+
}
|
|
16
|
+
>(() => ({ name: 'Express' })),
|
|
13
17
|
captureException: vi.fn(),
|
|
14
18
|
logger: {
|
|
15
19
|
trace: vi.fn(),
|
|
@@ -49,7 +53,6 @@ test('sentryOptions', async () => {
|
|
|
49
53
|
expect(options).toEqual(
|
|
50
54
|
expect.objectContaining({
|
|
51
55
|
dsn: 'https://example.com/sentry',
|
|
52
|
-
enableLogs: true,
|
|
53
56
|
integrations: expect.any(Array),
|
|
54
57
|
profileSessionSampleRate: 0.3,
|
|
55
58
|
tracesSampleRate: 0.3,
|
|
@@ -59,7 +62,7 @@ test('sentryOptions', async () => {
|
|
|
59
62
|
reset();
|
|
60
63
|
});
|
|
61
64
|
|
|
62
|
-
describe('
|
|
65
|
+
describe('Express integration', () => {
|
|
63
66
|
beforeEach(() => {
|
|
64
67
|
vi.unstubAllEnvs();
|
|
65
68
|
});
|
|
@@ -67,11 +70,16 @@ describe('sentryErrorHandler', () => {
|
|
|
67
70
|
test('ignores HTTP 40x errors in production', async () => {
|
|
68
71
|
vi.stubEnv('NODE_ENV', 'production');
|
|
69
72
|
|
|
70
|
-
const { Sentry,
|
|
73
|
+
const { Sentry, sentryOptions: getSentryOptions } =
|
|
74
|
+
await loadModuleWithSentryMock();
|
|
71
75
|
|
|
72
|
-
|
|
76
|
+
const sdkOptions = await getSentryOptions();
|
|
73
77
|
|
|
74
|
-
|
|
78
|
+
expect(sdkOptions.integrations).toContain(
|
|
79
|
+
Sentry.expressIntegration.mock.results[0]!.value,
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const options = Sentry.expressIntegration.mock.calls[0]![0];
|
|
75
83
|
expect(options.shouldHandleError({ status: 400 })).toEqual(false);
|
|
76
84
|
expect(options.shouldHandleError({ statusCode: 401 })).toEqual(false);
|
|
77
85
|
expect(options.shouldHandleError({ status_code: '403' })).toEqual(false);
|
|
@@ -83,23 +91,28 @@ describe('sentryErrorHandler', () => {
|
|
|
83
91
|
test('handles server and unknown errors in production', async () => {
|
|
84
92
|
vi.stubEnv('NODE_ENV', 'production');
|
|
85
93
|
|
|
86
|
-
const { Sentry,
|
|
94
|
+
const { Sentry, sentryOptions: getSentryOptions } =
|
|
95
|
+
await loadModuleWithSentryMock();
|
|
87
96
|
|
|
88
|
-
|
|
97
|
+
await getSentryOptions();
|
|
89
98
|
|
|
90
|
-
const options = Sentry.
|
|
99
|
+
const options = Sentry.expressIntegration.mock.calls[0]![0];
|
|
91
100
|
expect(options.shouldHandleError(new Error('boom'))).toEqual(true);
|
|
92
101
|
expect(options.shouldHandleError({ status: 500 })).toEqual(true);
|
|
102
|
+
expect(options.shouldHandleError({ status: 399 })).toEqual(true);
|
|
103
|
+
expect(options.shouldHandleError({ status: 'invalid' })).toEqual(true);
|
|
104
|
+
expect(options.shouldHandleError(null)).toEqual(true);
|
|
93
105
|
});
|
|
94
106
|
|
|
95
107
|
test('does not handle errors outside production', async () => {
|
|
96
108
|
vi.stubEnv('NODE_ENV', 'test');
|
|
97
109
|
|
|
98
|
-
const { Sentry,
|
|
110
|
+
const { Sentry, sentryOptions: getSentryOptions } =
|
|
111
|
+
await loadModuleWithSentryMock();
|
|
99
112
|
|
|
100
|
-
|
|
113
|
+
await getSentryOptions();
|
|
101
114
|
|
|
102
|
-
const options = Sentry.
|
|
115
|
+
const options = Sentry.expressIntegration.mock.calls[0]![0];
|
|
103
116
|
expect(options.shouldHandleError({ status: 500 })).toEqual(false);
|
|
104
117
|
});
|
|
105
118
|
});
|
package/src/index.ts
CHANGED
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
type MetricsAdapter,
|
|
6
6
|
} from '@devmoods/observability';
|
|
7
7
|
import * as Sentry from '@sentry/node';
|
|
8
|
-
import { type ErrorRequestHandler } from 'express';
|
|
9
8
|
|
|
10
9
|
declare module '@devmoods/config' {
|
|
11
10
|
interface Config extends ConfigFromDefs<typeof sentryConfig> {}
|
|
@@ -71,8 +70,19 @@ export async function sentryOptions(
|
|
|
71
70
|
dsn: config.SENTRY_DSN,
|
|
72
71
|
tracesSampleRate: config.SENTRY_TRACES_SAMPLE_RATE,
|
|
73
72
|
profileSessionSampleRate: config.SENTRY_PROFILES_SAMPLE_RATE,
|
|
74
|
-
integrations:
|
|
75
|
-
|
|
73
|
+
integrations: [
|
|
74
|
+
...nativeIntegrations,
|
|
75
|
+
Sentry.expressIntegration({
|
|
76
|
+
shouldHandleError(error) {
|
|
77
|
+
const status = getHttpStatusCode(error);
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
process.env.NODE_ENV === 'production' &&
|
|
81
|
+
(status == null || status < 400 || status >= 500)
|
|
82
|
+
);
|
|
83
|
+
},
|
|
84
|
+
}),
|
|
85
|
+
],
|
|
76
86
|
...options,
|
|
77
87
|
};
|
|
78
88
|
}
|
|
@@ -101,22 +111,6 @@ function getHttpStatusCode(error: unknown) {
|
|
|
101
111
|
: undefined;
|
|
102
112
|
}
|
|
103
113
|
|
|
104
|
-
export function sentryErrorHandler(
|
|
105
|
-
options: Sentry.NodeOptions = {},
|
|
106
|
-
): ErrorRequestHandler {
|
|
107
|
-
return Sentry.expressErrorHandler({
|
|
108
|
-
shouldHandleError(error) {
|
|
109
|
-
const status = getHttpStatusCode(error);
|
|
110
|
-
|
|
111
|
-
return (
|
|
112
|
-
process.env.NODE_ENV === 'production' &&
|
|
113
|
-
(status == null || status < 400 || status >= 500)
|
|
114
|
-
);
|
|
115
|
-
},
|
|
116
|
-
...options,
|
|
117
|
-
}) as unknown as ErrorRequestHandler;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
114
|
/**
|
|
121
115
|
* MetricsAdapter backed by `Sentry.metrics` (available in @sentry/node >=10.25.0).
|
|
122
116
|
* Requires `Sentry.init()` to have been called; calls are silently dropped when
|