miaoda-react-devkit 0.1.1-beta.1 → 0.1.1-beta.10
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/cloud/vite.config.js +118 -0
- package/dist/index.cjs +253 -69
- package/dist/index.d.cts +111 -2
- package/dist/index.d.ts +111 -2
- package/dist/index.js +250 -69
- package/dist/stubs/sentry-react-noop-stub.js +78 -0
- package/dist/stubs/sentry-react-stub.js +187 -69
- package/dist/vite/index.cjs +20 -1
- package/dist/vite/index.d.cts +3 -1
- package/dist/vite/index.d.ts +3 -1
- package/dist/vite/index.js +19 -1
- package/package.json +3 -1
- package/README.md +0 -181
- package/cloud/vite.config.ts +0 -156
package/dist/index.js
CHANGED
|
@@ -4,12 +4,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
4
4
|
|
|
5
5
|
// src/capture/console.ts
|
|
6
6
|
import { addConsoleInstrumentationHandler } from "@sentry/core";
|
|
7
|
-
|
|
8
|
-
"Sentry initialized successfully",
|
|
9
|
-
"[vite] ",
|
|
10
|
-
"Download the React DevTools for a better development experience"
|
|
11
|
-
];
|
|
12
|
-
function serializeArg(arg) {
|
|
7
|
+
function formatConsoleArg(arg) {
|
|
13
8
|
if (typeof arg === "string") return arg;
|
|
14
9
|
if (arg instanceof Error) return arg.message;
|
|
15
10
|
try {
|
|
@@ -18,9 +13,17 @@ function serializeArg(arg) {
|
|
|
18
13
|
return String(arg);
|
|
19
14
|
}
|
|
20
15
|
}
|
|
16
|
+
function formatConsoleArgs(args) {
|
|
17
|
+
return args.map(formatConsoleArg).join(" ");
|
|
18
|
+
}
|
|
19
|
+
var DEFAULT_CONSOLE_FILTER_KEYWORDS = [
|
|
20
|
+
"Sentry initialized successfully",
|
|
21
|
+
"[vite] ",
|
|
22
|
+
"Download the React DevTools for a better development experience"
|
|
23
|
+
];
|
|
21
24
|
function shouldFilterConsole(args, keywords) {
|
|
22
25
|
if (keywords.length === 0) return false;
|
|
23
|
-
const text = args
|
|
26
|
+
const text = formatConsoleArgs(args);
|
|
24
27
|
return keywords.some((kw) => text.includes(kw));
|
|
25
28
|
}
|
|
26
29
|
function shouldFilterConsoleMessage(message, keywords) {
|
|
@@ -36,9 +39,20 @@ function createConsoleObserver(keywords, subscribers) {
|
|
|
36
39
|
for (const sub of subscribers) sub.onConsole(info);
|
|
37
40
|
});
|
|
38
41
|
},
|
|
39
|
-
beforeBreadcrumb(breadcrumb,
|
|
42
|
+
beforeBreadcrumb(breadcrumb, hint) {
|
|
40
43
|
if (breadcrumb.category === "console" && breadcrumb.message != null) {
|
|
41
44
|
if (shouldFilterConsoleMessage(breadcrumb.message, keywords)) return null;
|
|
45
|
+
const h = hint;
|
|
46
|
+
const consoleType = h?.level ?? "log";
|
|
47
|
+
const stacks = (h?.input ?? []).filter((arg) => arg instanceof Error && arg.stack != null).map((err) => err.stack);
|
|
48
|
+
const originalMessage = breadcrumb.message;
|
|
49
|
+
breadcrumb.message = `[${consoleType}]${originalMessage}`;
|
|
50
|
+
breadcrumb.data = {
|
|
51
|
+
...breadcrumb.data ?? {},
|
|
52
|
+
consoleType,
|
|
53
|
+
message: originalMessage,
|
|
54
|
+
...stacks.length > 0 ? { stack: stacks.join("\n\n") } : {}
|
|
55
|
+
};
|
|
42
56
|
}
|
|
43
57
|
return breadcrumb;
|
|
44
58
|
}
|
|
@@ -46,7 +60,7 @@ function createConsoleObserver(keywords, subscribers) {
|
|
|
46
60
|
}
|
|
47
61
|
|
|
48
62
|
// src/capture/network.ts
|
|
49
|
-
import { getClient } from "@sentry/core";
|
|
63
|
+
import { getClient, getIsolationScope } from "@sentry/core";
|
|
50
64
|
|
|
51
65
|
// ../../node_modules/.pnpm/@sentry-internal+browser-utils@9.47.1/node_modules/@sentry-internal/browser-utils/build/esm/debug-build.js
|
|
52
66
|
var DEBUG_BUILD = typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__;
|
|
@@ -84,9 +98,42 @@ function getFetchRequestArgBody(fetchArgs = []) {
|
|
|
84
98
|
return fetchArgs[1].body;
|
|
85
99
|
}
|
|
86
100
|
|
|
101
|
+
// src/utils.ts
|
|
102
|
+
function stripUrlOrigin(url) {
|
|
103
|
+
try {
|
|
104
|
+
const u = new URL(url);
|
|
105
|
+
return u.pathname + u.search + u.hash;
|
|
106
|
+
} catch {
|
|
107
|
+
return url;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
87
111
|
// src/capture/pgrest.ts
|
|
88
112
|
var DEFAULT_PGREST_URL_PATTERNS = [/\/rest\/v1\//];
|
|
89
|
-
var DEFAULT_PGREST_WHITELIST_CODES = [
|
|
113
|
+
var DEFAULT_PGREST_WHITELIST_CODES = [
|
|
114
|
+
"22P02",
|
|
115
|
+
// 无效的文本表示(如类型转换失败)
|
|
116
|
+
"42703",
|
|
117
|
+
// 未定义的列
|
|
118
|
+
"42P01",
|
|
119
|
+
// 未定义的表
|
|
120
|
+
"42501",
|
|
121
|
+
// 权限不足
|
|
122
|
+
"23503",
|
|
123
|
+
// 外键约束失败
|
|
124
|
+
"42P17",
|
|
125
|
+
// 对象已存在
|
|
126
|
+
"22008",
|
|
127
|
+
// 日期时间字段值超出范围
|
|
128
|
+
"23505",
|
|
129
|
+
// 唯一键冲突
|
|
130
|
+
"PGRST116",
|
|
131
|
+
// 期望单行但返回多行
|
|
132
|
+
"PGRST200",
|
|
133
|
+
// 外键关系查找失败
|
|
134
|
+
"PGRST204"
|
|
135
|
+
// 响应中找不到列
|
|
136
|
+
];
|
|
90
137
|
function isPgRestRequest(url, patterns) {
|
|
91
138
|
return patterns.some((p) => (typeof p === "string" ? new RegExp(p) : p).test(url));
|
|
92
139
|
}
|
|
@@ -111,8 +158,38 @@ function parsePgRestErrorBody(body) {
|
|
|
111
158
|
};
|
|
112
159
|
}
|
|
113
160
|
|
|
161
|
+
// src/capture/auth.ts
|
|
162
|
+
var DEFAULT_AUTH_URL_PATTERNS = [/\/auth\/v1\//];
|
|
163
|
+
var DEFAULT_AUTH_WHITELIST_CODES = ["unexpected_failure"];
|
|
164
|
+
function isAuthRequest(url, patterns) {
|
|
165
|
+
return patterns.some((p) => (typeof p === "string" ? new RegExp(p) : p).test(url));
|
|
166
|
+
}
|
|
167
|
+
function parseAuthErrorBody(body) {
|
|
168
|
+
if (!body) return null;
|
|
169
|
+
let parsed;
|
|
170
|
+
try {
|
|
171
|
+
parsed = JSON.parse(body);
|
|
172
|
+
} catch {
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
if (typeof parsed !== "object") return null;
|
|
176
|
+
if (parsed === null) return null;
|
|
177
|
+
const p = parsed;
|
|
178
|
+
if (typeof p["code"] !== "string") return null;
|
|
179
|
+
if (typeof p["message"] !== "string") return null;
|
|
180
|
+
return {
|
|
181
|
+
code: p["code"],
|
|
182
|
+
message: p["message"],
|
|
183
|
+
requestId: typeof p["requestId"] === "string" ? p["requestId"] : null
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
114
187
|
// src/capture/network.ts
|
|
115
188
|
var BODY_TRUNCATE_LIMIT = 2e3;
|
|
189
|
+
function calcDuration(hint) {
|
|
190
|
+
if (hint?.startTimestamp == null || hint?.endTimestamp == null) return void 0;
|
|
191
|
+
return Math.round((hint.endTimestamp - hint.startTimestamp) * 1e3);
|
|
192
|
+
}
|
|
116
193
|
var DEFAULT_IGNORE_URLS = [
|
|
117
194
|
/\.(js|css|png|jpg|jpeg|gif|svg|ico|woff|woff2|ttf|eot|map)(\?.*)?$/,
|
|
118
195
|
/\.chunk\./,
|
|
@@ -162,7 +239,15 @@ function handleXhrBreadcrumb(breadcrumb, hint, handler) {
|
|
|
162
239
|
breadcrumb.data["requestBody"] = requestBody;
|
|
163
240
|
breadcrumb.data["responseBody"] = responseBody;
|
|
164
241
|
}
|
|
165
|
-
|
|
242
|
+
const duration = calcDuration(hint);
|
|
243
|
+
const relativeUrl = stripUrlOrigin(url);
|
|
244
|
+
const statusStr = statusCode != null ? String(statusCode) : "failed";
|
|
245
|
+
const durationStr = duration != null ? ` (${duration}ms)` : "";
|
|
246
|
+
breadcrumb.message = `XHR ${method} ${relativeUrl} -> ${statusStr}${durationStr}`;
|
|
247
|
+
if (breadcrumb.data) {
|
|
248
|
+
breadcrumb.data["duration"] = duration;
|
|
249
|
+
}
|
|
250
|
+
void handler({ type: "xhr", method, url, statusCode, requestBody, responseBody, isError, duration });
|
|
166
251
|
}
|
|
167
252
|
async function handleFetchBreadcrumb(breadcrumb, hint, handler) {
|
|
168
253
|
const data = breadcrumb.data;
|
|
@@ -172,19 +257,24 @@ async function handleFetchBreadcrumb(breadcrumb, hint, handler) {
|
|
|
172
257
|
const isError = hint?.data != null;
|
|
173
258
|
const response = hint?.response;
|
|
174
259
|
const cause = hint?.data instanceof Error ? hint.data : void 0;
|
|
175
|
-
const
|
|
176
|
-
const reqBody = getFetchRequestArgBody(fetchArgs ?? []);
|
|
260
|
+
const reqBody = getFetchRequestArgBody(hint?.input ?? []);
|
|
177
261
|
const [rawRequestBody] = getBodyString(reqBody);
|
|
178
262
|
const requestBody = rawRequestBody != null ? truncateBody(rawRequestBody) : void 0;
|
|
263
|
+
const duration = calcDuration(hint);
|
|
264
|
+
const relativeUrl = stripUrlOrigin(url);
|
|
265
|
+
const statusStr = statusCode != null ? String(statusCode) : "failed";
|
|
266
|
+
const durationStr = duration != null ? ` (${duration}ms)` : "";
|
|
267
|
+
breadcrumb.message = `Fetch ${method} ${relativeUrl} -> ${statusStr}${durationStr}`;
|
|
179
268
|
if (breadcrumb.data) {
|
|
180
269
|
breadcrumb.data["requestBody"] = requestBody;
|
|
270
|
+
breadcrumb.data["duration"] = duration;
|
|
181
271
|
}
|
|
182
272
|
const contentType = response?.headers?.get("content-type") ?? "";
|
|
183
273
|
if (isStreamByContentType(contentType)) {
|
|
184
274
|
if (breadcrumb.data) {
|
|
185
275
|
breadcrumb.data["responseBody"] = "[streaming response - not captured]";
|
|
186
276
|
}
|
|
187
|
-
await handler({ type: "fetch", method, url, statusCode, requestBody, responseBody: "[streaming response - not captured]", isError, cause });
|
|
277
|
+
await handler({ type: "fetch", method, url, statusCode, requestBody, responseBody: "[streaming response - not captured]", isError, cause, duration });
|
|
188
278
|
return;
|
|
189
279
|
}
|
|
190
280
|
let responseBody;
|
|
@@ -204,18 +294,23 @@ async function handleFetchBreadcrumb(breadcrumb, hint, handler) {
|
|
|
204
294
|
if (breadcrumb.data) {
|
|
205
295
|
breadcrumb.data["responseBody"] = responseBody;
|
|
206
296
|
}
|
|
207
|
-
await handler({ type: "fetch", method, url, statusCode, requestBody, responseBody, isError, cause });
|
|
297
|
+
await handler({ type: "fetch", method, url, statusCode, requestBody, responseBody, isError, cause, duration });
|
|
208
298
|
}
|
|
209
299
|
function createNetworkObserver(opts, subscribers) {
|
|
210
300
|
const shouldIgnore = createUrlMatcher(opts.ignoreUrls);
|
|
211
301
|
const pgRestPatterns = opts.pgRestUrlPatterns ?? DEFAULT_PGREST_URL_PATTERNS;
|
|
212
302
|
const pgRestWhitelistCodes = opts.pgRestWhitelistCodes ?? DEFAULT_PGREST_WHITELIST_CODES;
|
|
303
|
+
const precedingBreadcrumbsLimit = opts.precedingBreadcrumbsLimit;
|
|
304
|
+
const authPatterns = opts.authUrlPatterns ?? DEFAULT_AUTH_URL_PATTERNS;
|
|
305
|
+
const authWhitelistCodes = opts.authWhitelistCodes ?? DEFAULT_AUTH_WHITELIST_CODES;
|
|
213
306
|
function tryDispatchPgRestWhitelistError(requestType, method, url, statusCode, requestBody, responseBody) {
|
|
214
307
|
if (statusCode == null) return;
|
|
215
308
|
if (!isPgRestRequest(url, pgRestPatterns)) return;
|
|
216
309
|
const pgRestError = parsePgRestErrorBody(responseBody);
|
|
217
310
|
if (!pgRestError) return;
|
|
218
311
|
if (pgRestWhitelistCodes.length > 0 && !pgRestWhitelistCodes.includes(pgRestError.code)) return;
|
|
312
|
+
const allBreadcrumbs = getIsolationScope().getScopeData().breadcrumbs;
|
|
313
|
+
const precedingBreadcrumbs = precedingBreadcrumbsLimit != null ? allBreadcrumbs.slice(-precedingBreadcrumbsLimit) : allBreadcrumbs.slice();
|
|
219
314
|
const info = {
|
|
220
315
|
type: requestType,
|
|
221
316
|
method,
|
|
@@ -223,10 +318,31 @@ function createNetworkObserver(opts, subscribers) {
|
|
|
223
318
|
statusCode,
|
|
224
319
|
pgRestError,
|
|
225
320
|
requestBody,
|
|
226
|
-
responseBody
|
|
321
|
+
responseBody,
|
|
322
|
+
precedingBreadcrumbs
|
|
227
323
|
};
|
|
228
324
|
for (const sub of subscribers) sub.onPgRestWhitelistError(info);
|
|
229
325
|
}
|
|
326
|
+
function tryDispatchAuthWhitelistError(requestType, method, url, statusCode, requestBody, responseBody) {
|
|
327
|
+
if (statusCode == null) return;
|
|
328
|
+
if (!isAuthRequest(url, authPatterns)) return;
|
|
329
|
+
const authError = parseAuthErrorBody(responseBody);
|
|
330
|
+
if (!authError) return;
|
|
331
|
+
if (authWhitelistCodes.length > 0 && !authWhitelistCodes.includes(authError.code)) return;
|
|
332
|
+
const allBreadcrumbs = getIsolationScope().getScopeData().breadcrumbs;
|
|
333
|
+
const precedingBreadcrumbs = precedingBreadcrumbsLimit != null ? allBreadcrumbs.slice(-precedingBreadcrumbsLimit) : allBreadcrumbs.slice();
|
|
334
|
+
const info = {
|
|
335
|
+
type: requestType,
|
|
336
|
+
method,
|
|
337
|
+
url,
|
|
338
|
+
statusCode,
|
|
339
|
+
authError,
|
|
340
|
+
requestBody,
|
|
341
|
+
responseBody,
|
|
342
|
+
precedingBreadcrumbs
|
|
343
|
+
};
|
|
344
|
+
for (const sub of subscribers) sub.onAuthWhitelistError(info);
|
|
345
|
+
}
|
|
230
346
|
function makeHandler(requestType) {
|
|
231
347
|
return (info) => {
|
|
232
348
|
for (const sub of subscribers) void sub.onNetworkRequest(info);
|
|
@@ -238,6 +354,14 @@ function createNetworkObserver(opts, subscribers) {
|
|
|
238
354
|
info.requestBody,
|
|
239
355
|
info.responseBody
|
|
240
356
|
);
|
|
357
|
+
tryDispatchAuthWhitelistError(
|
|
358
|
+
requestType,
|
|
359
|
+
info.method,
|
|
360
|
+
info.url,
|
|
361
|
+
info.statusCode,
|
|
362
|
+
info.requestBody,
|
|
363
|
+
info.responseBody
|
|
364
|
+
);
|
|
241
365
|
};
|
|
242
366
|
}
|
|
243
367
|
return {
|
|
@@ -250,10 +374,11 @@ function createNetworkObserver(opts, subscribers) {
|
|
|
250
374
|
const fetchHandler = makeHandler("fetch");
|
|
251
375
|
client.on("beforeAddBreadcrumb", (breadcrumb, hint) => {
|
|
252
376
|
const url = breadcrumb.data?.url ?? "";
|
|
253
|
-
if (shouldIgnore(url)) return;
|
|
254
377
|
if (breadcrumb.category === "xhr") {
|
|
378
|
+
if (shouldIgnore(url)) return;
|
|
255
379
|
handleXhrBreadcrumb(breadcrumb, hint, xhrHandler);
|
|
256
380
|
} else if (breadcrumb.category === "fetch") {
|
|
381
|
+
if (shouldIgnore(url)) return;
|
|
257
382
|
void handleFetchBreadcrumb(breadcrumb, hint, fetchHandler);
|
|
258
383
|
}
|
|
259
384
|
});
|
|
@@ -346,56 +471,10 @@ var PostMessageSubscriber = class {
|
|
|
346
471
|
};
|
|
347
472
|
this.send(msg, "*");
|
|
348
473
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
if (!isError && !isClientError) return;
|
|
352
|
-
const urlPath = extractUrlPath(url);
|
|
353
|
-
if (isError) {
|
|
354
|
-
const causeDesc = cause != null ? String(cause) : "NetworkError";
|
|
355
|
-
const errorMessage = `${method} ${urlPath} failed: ${causeDesc}`;
|
|
356
|
-
const msg = {
|
|
357
|
-
type: "GLOBAL_ERROR",
|
|
358
|
-
message: errorMessage,
|
|
359
|
-
error: cause != null ? { name: cause.name, message: cause.message, stack: cause.stack } : null,
|
|
360
|
-
errorData: {
|
|
361
|
-
name: cause?.name ?? "NetworkError",
|
|
362
|
-
message: cause?.message ?? causeDesc,
|
|
363
|
-
stack: cause?.stack ?? null,
|
|
364
|
-
fileName: url,
|
|
365
|
-
lineNumber: 0,
|
|
366
|
-
columnNumber: 0,
|
|
367
|
-
httpPath: urlPath,
|
|
368
|
-
httpStatus: 0,
|
|
369
|
-
httpMethod: method,
|
|
370
|
-
requestBody: requestBody ?? "",
|
|
371
|
-
responseBody: ""
|
|
372
|
-
}
|
|
373
|
-
};
|
|
374
|
-
this.send(msg, "*");
|
|
375
|
-
} else {
|
|
376
|
-
const errorMessage = `${method} ${urlPath} -> ${statusCode}`;
|
|
377
|
-
const msg = {
|
|
378
|
-
type: "GLOBAL_ERROR",
|
|
379
|
-
message: errorMessage,
|
|
380
|
-
error: null,
|
|
381
|
-
errorData: {
|
|
382
|
-
name: "HTTPClientError",
|
|
383
|
-
message: errorMessage,
|
|
384
|
-
stack: null,
|
|
385
|
-
fileName: url,
|
|
386
|
-
lineNumber: 0,
|
|
387
|
-
columnNumber: 0,
|
|
388
|
-
httpPath: urlPath,
|
|
389
|
-
httpStatus: statusCode,
|
|
390
|
-
httpMethod: method,
|
|
391
|
-
requestBody: requestBody ?? "",
|
|
392
|
-
responseBody: responseBody ?? ""
|
|
393
|
-
}
|
|
394
|
-
};
|
|
395
|
-
this.send(msg, "*");
|
|
396
|
-
}
|
|
474
|
+
// postMessage 场景不需要上报 network 日志
|
|
475
|
+
onNetworkRequest(_info) {
|
|
397
476
|
}
|
|
398
|
-
onPgRestWhitelistError({ type, method, url, statusCode, pgRestError, requestBody, responseBody }) {
|
|
477
|
+
onPgRestWhitelistError({ type, method, url, statusCode, pgRestError, requestBody, responseBody, precedingBreadcrumbs }) {
|
|
399
478
|
const urlPath = extractUrlPath(url);
|
|
400
479
|
const code = pgRestError.code;
|
|
401
480
|
const errorMessage = `${method} ${urlPath} -> ${statusCode} [PgRest:${code}]`;
|
|
@@ -418,7 +497,36 @@ var PostMessageSubscriber = class {
|
|
|
418
497
|
pgRestCode: code,
|
|
419
498
|
pgRestDetails: pgRestError.details ?? void 0,
|
|
420
499
|
pgRestHint: pgRestError.hint ?? void 0,
|
|
421
|
-
requestType: type
|
|
500
|
+
requestType: type,
|
|
501
|
+
precedingBreadcrumbs
|
|
502
|
+
}
|
|
503
|
+
};
|
|
504
|
+
this.send(msg, "*");
|
|
505
|
+
}
|
|
506
|
+
onAuthWhitelistError({ type, method, url, statusCode, authError, requestBody, responseBody, precedingBreadcrumbs }) {
|
|
507
|
+
const urlPath = extractUrlPath(url);
|
|
508
|
+
const code = authError.code;
|
|
509
|
+
const errorMessage = `${method} ${urlPath} -> ${statusCode} [Auth:${code}]`;
|
|
510
|
+
const msg = {
|
|
511
|
+
type: "GLOBAL_ERROR",
|
|
512
|
+
message: errorMessage,
|
|
513
|
+
error: null,
|
|
514
|
+
errorData: {
|
|
515
|
+
name: "AuthWhitelistError",
|
|
516
|
+
message: authError.message,
|
|
517
|
+
stack: null,
|
|
518
|
+
fileName: url,
|
|
519
|
+
lineNumber: 0,
|
|
520
|
+
columnNumber: 0,
|
|
521
|
+
httpPath: urlPath,
|
|
522
|
+
httpStatus: statusCode,
|
|
523
|
+
httpMethod: method,
|
|
524
|
+
requestBody: requestBody ?? "",
|
|
525
|
+
responseBody,
|
|
526
|
+
authCode: code,
|
|
527
|
+
authRequestId: authError.requestId ?? void 0,
|
|
528
|
+
requestType: type,
|
|
529
|
+
precedingBreadcrumbs
|
|
422
530
|
}
|
|
423
531
|
};
|
|
424
532
|
this.send(msg, "*");
|
|
@@ -438,16 +546,89 @@ function createNoopSubscriber() {
|
|
|
438
546
|
onNetworkRequest() {
|
|
439
547
|
},
|
|
440
548
|
onPgRestWhitelistError() {
|
|
549
|
+
},
|
|
550
|
+
onAuthWhitelistError() {
|
|
441
551
|
}
|
|
442
552
|
};
|
|
443
553
|
}
|
|
554
|
+
|
|
555
|
+
// src/subscribers/sentryEventSubscriber.ts
|
|
556
|
+
import { captureEvent } from "@sentry/core";
|
|
557
|
+
function toSentryLevel(consoleLevel) {
|
|
558
|
+
switch (consoleLevel) {
|
|
559
|
+
case "error":
|
|
560
|
+
return "error";
|
|
561
|
+
case "warn":
|
|
562
|
+
return "warning";
|
|
563
|
+
case "debug":
|
|
564
|
+
return "debug";
|
|
565
|
+
case "info":
|
|
566
|
+
return "info";
|
|
567
|
+
default:
|
|
568
|
+
return "log";
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
var SentryEventSubscriber = class {
|
|
572
|
+
constructor(opts = {}) {
|
|
573
|
+
__publicField(this, "captureAllNetworkRequests");
|
|
574
|
+
this.captureAllNetworkRequests = opts.captureAllNetworkRequests ?? true;
|
|
575
|
+
}
|
|
576
|
+
onConsole(info) {
|
|
577
|
+
const { level, args } = info;
|
|
578
|
+
const formattedMessage = formatConsoleArgs(args);
|
|
579
|
+
const sentryLevel = toSentryLevel(level);
|
|
580
|
+
captureEvent({
|
|
581
|
+
message: `[${level}]${formattedMessage}`,
|
|
582
|
+
level: sentryLevel,
|
|
583
|
+
// 按 level + 消息内容前 100 字符分组,同一类日志聚合为同一个 Issue
|
|
584
|
+
fingerprint: ["console", level, formattedMessage.slice(0, 100)],
|
|
585
|
+
tags: {
|
|
586
|
+
type: "console"
|
|
587
|
+
},
|
|
588
|
+
extra: { consoleType: level, args }
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
// Sentry 已自动捕获 JS 错误,不重复上报
|
|
592
|
+
onError(_info) {
|
|
593
|
+
}
|
|
594
|
+
onNetworkRequest(info) {
|
|
595
|
+
const { type, method, url, statusCode, requestBody, responseBody, isError, duration } = info;
|
|
596
|
+
const shouldCapture = this.captureAllNetworkRequests || isError || statusCode != null && statusCode >= 400;
|
|
597
|
+
if (!shouldCapture) return;
|
|
598
|
+
const urlPath = stripUrlOrigin(url);
|
|
599
|
+
const requestTypeLabel = type === "xhr" ? "XHR" : "Fetch";
|
|
600
|
+
const statusStr = statusCode != null ? String(statusCode) : "failed";
|
|
601
|
+
const durationStr = duration != null ? ` (${duration}ms)` : "";
|
|
602
|
+
const message = `${requestTypeLabel} ${method} ${urlPath} -> ${statusStr}${durationStr}`;
|
|
603
|
+
const level = isError ? "error" : statusCode != null && statusCode >= 400 ? "warning" : "info";
|
|
604
|
+
captureEvent({
|
|
605
|
+
message,
|
|
606
|
+
level,
|
|
607
|
+
// 按 method + url 路径固定分组,同一接口的多次报错聚合为同一个 Issue
|
|
608
|
+
fingerprint: ["network", method, urlPath],
|
|
609
|
+
tags: {
|
|
610
|
+
type: "network"
|
|
611
|
+
},
|
|
612
|
+
extra: { url, method, statusCode, duration, requestBody, responseBody }
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
onPgRestWhitelistError(_info) {
|
|
616
|
+
}
|
|
617
|
+
onAuthWhitelistError(_info) {
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
function createSentryEventSubscriber(opts) {
|
|
621
|
+
return new SentryEventSubscriber(opts);
|
|
622
|
+
}
|
|
444
623
|
export {
|
|
624
|
+
DEFAULT_AUTH_URL_PATTERNS,
|
|
625
|
+
DEFAULT_AUTH_WHITELIST_CODES,
|
|
445
626
|
DEFAULT_CONSOLE_FILTER_KEYWORDS,
|
|
446
627
|
DEFAULT_IGNORE_URLS,
|
|
447
628
|
DEFAULT_PGREST_URL_PATTERNS,
|
|
448
629
|
DEFAULT_PGREST_WHITELIST_CODES,
|
|
449
630
|
SentryCapture,
|
|
450
631
|
createNoopSubscriber,
|
|
451
|
-
createPostMessageSubscriber
|
|
632
|
+
createPostMessageSubscriber,
|
|
633
|
+
createSentryEventSubscriber
|
|
452
634
|
};
|
|
453
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// src/stubs/sentry-react-noop-stub.ts
|
|
2
|
+
var init = (_options) => {
|
|
3
|
+
};
|
|
4
|
+
var browserTracingIntegration = () => ({});
|
|
5
|
+
var captureException = (_err) => "";
|
|
6
|
+
var captureMessage = (_msg) => "";
|
|
7
|
+
var captureEvent = (_event) => "";
|
|
8
|
+
var addBreadcrumb = (_breadcrumb) => {
|
|
9
|
+
};
|
|
10
|
+
var setUser = (_user) => {
|
|
11
|
+
};
|
|
12
|
+
var setTag = (_key, _value) => {
|
|
13
|
+
};
|
|
14
|
+
var setTags = (_tags) => {
|
|
15
|
+
};
|
|
16
|
+
var setContext = (_key, _ctx) => {
|
|
17
|
+
};
|
|
18
|
+
var setExtra = (_key, _value) => {
|
|
19
|
+
};
|
|
20
|
+
var setExtras = (_extras) => {
|
|
21
|
+
};
|
|
22
|
+
var withScope = (cb) => {
|
|
23
|
+
cb({});
|
|
24
|
+
};
|
|
25
|
+
var withIsolationScope = (cb) => {
|
|
26
|
+
cb({});
|
|
27
|
+
};
|
|
28
|
+
var startSpan = (_opts, cb) => cb();
|
|
29
|
+
var getClient = () => void 0;
|
|
30
|
+
var flush = () => Promise.resolve(true);
|
|
31
|
+
var close = () => Promise.resolve(true);
|
|
32
|
+
var lastEventId = () => void 0;
|
|
33
|
+
var SDK_VERSION = "0.0.0-stub";
|
|
34
|
+
var ErrorBoundary = ({ children }) => children ?? null;
|
|
35
|
+
var withErrorBoundary = (Component) => Component;
|
|
36
|
+
var withProfiler = (Component) => Component;
|
|
37
|
+
var useProfiler = (_name) => {
|
|
38
|
+
};
|
|
39
|
+
var Profiler = ({ children }) => children ?? null;
|
|
40
|
+
var withSentryRouting = (Component) => Component;
|
|
41
|
+
var withSentryReactRouterV6Routing = (Component) => Component;
|
|
42
|
+
var wrapCreateBrowserRouterV6 = (fn) => fn;
|
|
43
|
+
var wrapCreateBrowserRouterV7 = (fn) => fn;
|
|
44
|
+
var reactRouterV6BrowserTracingIntegration = () => ({});
|
|
45
|
+
var reactRouterV7BrowserTracingIntegration = () => ({});
|
|
46
|
+
export {
|
|
47
|
+
ErrorBoundary,
|
|
48
|
+
Profiler,
|
|
49
|
+
SDK_VERSION,
|
|
50
|
+
addBreadcrumb,
|
|
51
|
+
browserTracingIntegration,
|
|
52
|
+
captureEvent,
|
|
53
|
+
captureException,
|
|
54
|
+
captureMessage,
|
|
55
|
+
close,
|
|
56
|
+
flush,
|
|
57
|
+
getClient,
|
|
58
|
+
init,
|
|
59
|
+
lastEventId,
|
|
60
|
+
reactRouterV6BrowserTracingIntegration,
|
|
61
|
+
reactRouterV7BrowserTracingIntegration,
|
|
62
|
+
setContext,
|
|
63
|
+
setExtra,
|
|
64
|
+
setExtras,
|
|
65
|
+
setTag,
|
|
66
|
+
setTags,
|
|
67
|
+
setUser,
|
|
68
|
+
startSpan,
|
|
69
|
+
useProfiler,
|
|
70
|
+
withErrorBoundary,
|
|
71
|
+
withIsolationScope,
|
|
72
|
+
withProfiler,
|
|
73
|
+
withScope,
|
|
74
|
+
withSentryReactRouterV6Routing,
|
|
75
|
+
withSentryRouting,
|
|
76
|
+
wrapCreateBrowserRouterV6,
|
|
77
|
+
wrapCreateBrowserRouterV7
|
|
78
|
+
};
|