miaoda-react-devkit 0.1.1-beta.2 → 0.1.1-beta.21

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.
@@ -7,12 +7,7 @@ import * as RealSentry from "@sentry/react";
7
7
 
8
8
  // src/capture/console.ts
9
9
  import { addConsoleInstrumentationHandler } from "@sentry/core";
10
- var DEFAULT_CONSOLE_FILTER_KEYWORDS = [
11
- "Sentry initialized successfully",
12
- "[vite] ",
13
- "Download the React DevTools for a better development experience"
14
- ];
15
- function serializeArg(arg) {
10
+ function formatConsoleArg(arg) {
16
11
  if (typeof arg === "string") return arg;
17
12
  if (arg instanceof Error) return arg.message;
18
13
  try {
@@ -21,9 +16,17 @@ function serializeArg(arg) {
21
16
  return String(arg);
22
17
  }
23
18
  }
19
+ function formatConsoleArgs(args) {
20
+ return args.map(formatConsoleArg).join(" ");
21
+ }
22
+ var DEFAULT_CONSOLE_FILTER_KEYWORDS = [
23
+ "Sentry initialized successfully",
24
+ "[vite] ",
25
+ "Download the React DevTools for a better development experience"
26
+ ];
24
27
  function shouldFilterConsole(args, keywords) {
25
28
  if (keywords.length === 0) return false;
26
- const text = args.map(serializeArg).join(" ");
29
+ const text = formatConsoleArgs(args);
27
30
  return keywords.some((kw) => text.includes(kw));
28
31
  }
29
32
  function shouldFilterConsoleMessage(message, keywords) {
@@ -39,9 +42,20 @@ function createConsoleObserver(keywords, subscribers) {
39
42
  for (const sub of subscribers) sub.onConsole(info);
40
43
  });
41
44
  },
42
- beforeBreadcrumb(breadcrumb, _hint) {
45
+ beforeBreadcrumb(breadcrumb, hint) {
43
46
  if (breadcrumb.category === "console" && breadcrumb.message != null) {
44
47
  if (shouldFilterConsoleMessage(breadcrumb.message, keywords)) return null;
48
+ const h = hint;
49
+ const consoleType = h?.level ?? "log";
50
+ const stacks = (h?.input ?? []).filter((arg) => arg instanceof Error && arg.stack != null).map((err) => err.stack);
51
+ const originalMessage = breadcrumb.message;
52
+ breadcrumb.message = `[${consoleType}]${originalMessage}`;
53
+ breadcrumb.data = {
54
+ ...breadcrumb.data ?? {},
55
+ consoleType,
56
+ message: originalMessage,
57
+ ...stacks.length > 0 ? { stack: stacks.join("\n\n") } : {}
58
+ };
45
59
  }
46
60
  return breadcrumb;
47
61
  }
@@ -49,7 +63,7 @@ function createConsoleObserver(keywords, subscribers) {
49
63
  }
50
64
 
51
65
  // src/capture/network.ts
52
- import { getClient } from "@sentry/core";
66
+ import { getClient, getIsolationScope } from "@sentry/core";
53
67
 
54
68
  // ../../node_modules/.pnpm/@sentry-internal+browser-utils@9.47.1/node_modules/@sentry-internal/browser-utils/build/esm/debug-build.js
55
69
  var DEBUG_BUILD = typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__;
@@ -87,9 +101,42 @@ function getFetchRequestArgBody(fetchArgs = []) {
87
101
  return fetchArgs[1].body;
88
102
  }
89
103
 
104
+ // src/utils.ts
105
+ function stripUrlOrigin(url) {
106
+ try {
107
+ const u = new URL(url);
108
+ return u.pathname + u.search + u.hash;
109
+ } catch {
110
+ return url;
111
+ }
112
+ }
113
+
90
114
  // src/capture/pgrest.ts
91
115
  var DEFAULT_PGREST_URL_PATTERNS = [/\/rest\/v1\//];
92
- var DEFAULT_PGREST_WHITELIST_CODES = [];
116
+ var DEFAULT_PGREST_WHITELIST_CODES = [
117
+ "22P02",
118
+ // 无效的文本表示(如类型转换失败)
119
+ "42703",
120
+ // 未定义的列
121
+ "42P01",
122
+ // 未定义的表
123
+ "42501",
124
+ // 权限不足
125
+ "23503",
126
+ // 外键约束失败
127
+ "42P17",
128
+ // 对象已存在
129
+ "22008",
130
+ // 日期时间字段值超出范围
131
+ "23505",
132
+ // 唯一键冲突
133
+ "PGRST116",
134
+ // 期望单行但返回多行
135
+ "PGRST200",
136
+ // 外键关系查找失败
137
+ "PGRST204"
138
+ // 响应中找不到列
139
+ ];
93
140
  function isPgRestRequest(url, patterns) {
94
141
  return patterns.some((p) => (typeof p === "string" ? new RegExp(p) : p).test(url));
95
142
  }
@@ -114,8 +161,64 @@ function parsePgRestErrorBody(body) {
114
161
  };
115
162
  }
116
163
 
164
+ // src/capture/auth.ts
165
+ var DEFAULT_AUTH_URL_PATTERNS = [/\/auth\/v1\//];
166
+ var DEFAULT_AUTH_WHITELIST_CODES = ["unexpected_failure"];
167
+ function isAuthRequest(url, patterns) {
168
+ return patterns.some((p) => (typeof p === "string" ? new RegExp(p) : p).test(url));
169
+ }
170
+ function parseAuthErrorBody(body) {
171
+ if (!body) return null;
172
+ let parsed;
173
+ try {
174
+ parsed = JSON.parse(body);
175
+ } catch {
176
+ return null;
177
+ }
178
+ if (typeof parsed !== "object") return null;
179
+ if (parsed === null) return null;
180
+ const p = parsed;
181
+ if (typeof p["code"] !== "string") return null;
182
+ if (typeof p["message"] !== "string") return null;
183
+ return {
184
+ code: p["code"],
185
+ message: p["message"],
186
+ requestId: typeof p["requestId"] === "string" ? p["requestId"] : null
187
+ };
188
+ }
189
+
190
+ // src/capture/storage.ts
191
+ var DEFAULT_STORAGE_URL_PATTERNS = [/\/storage\/v1\//];
192
+ var DEFAULT_STORAGE_WHITELIST_ERRORS = ["new row violates row-level security policy"];
193
+ function isStorageRequest(url, patterns) {
194
+ return patterns.some((p) => (typeof p === "string" ? new RegExp(p) : p).test(url));
195
+ }
196
+ function parseStorageErrorBody(body) {
197
+ if (!body) return null;
198
+ let parsed;
199
+ try {
200
+ parsed = JSON.parse(body);
201
+ } catch {
202
+ return null;
203
+ }
204
+ if (typeof parsed !== "object" || parsed === null) return null;
205
+ const p = parsed;
206
+ if (typeof p["statusCode"] !== "string") return null;
207
+ if (typeof p["error"] !== "string") return null;
208
+ if (typeof p["message"] !== "string") return null;
209
+ return {
210
+ statusCode: p["statusCode"],
211
+ error: p["error"],
212
+ message: p["message"]
213
+ };
214
+ }
215
+
117
216
  // src/capture/network.ts
118
217
  var BODY_TRUNCATE_LIMIT = 2e3;
218
+ function calcDuration(hint) {
219
+ if (hint?.startTimestamp == null || hint?.endTimestamp == null) return void 0;
220
+ return Math.round(hint.endTimestamp - hint.startTimestamp);
221
+ }
119
222
  var DEFAULT_IGNORE_URLS = [
120
223
  /\.(js|css|png|jpg|jpeg|gif|svg|ico|woff|woff2|ttf|eot|map)(\?.*)?$/,
121
224
  /\.chunk\./,
@@ -165,7 +268,15 @@ function handleXhrBreadcrumb(breadcrumb, hint, handler) {
165
268
  breadcrumb.data["requestBody"] = requestBody;
166
269
  breadcrumb.data["responseBody"] = responseBody;
167
270
  }
168
- void handler({ type: "xhr", method, url, statusCode, requestBody, responseBody, isError });
271
+ const duration = calcDuration(hint);
272
+ const relativeUrl = stripUrlOrigin(url);
273
+ const statusStr = statusCode != null ? String(statusCode) : "failed";
274
+ const durationStr = duration != null ? ` (${duration}ms)` : "";
275
+ breadcrumb.message = `XHR ${method} ${relativeUrl} -> ${statusStr}${durationStr}`;
276
+ if (breadcrumb.data) {
277
+ breadcrumb.data["duration"] = duration;
278
+ }
279
+ void handler({ type: "xhr", method, url, statusCode, requestBody, responseBody, isError, duration });
169
280
  }
170
281
  async function handleFetchBreadcrumb(breadcrumb, hint, handler) {
171
282
  const data = breadcrumb.data;
@@ -175,19 +286,24 @@ async function handleFetchBreadcrumb(breadcrumb, hint, handler) {
175
286
  const isError = hint?.data != null;
176
287
  const response = hint?.response;
177
288
  const cause = hint?.data instanceof Error ? hint.data : void 0;
178
- const fetchArgs = hint?.input;
179
- const reqBody = getFetchRequestArgBody(fetchArgs ?? []);
289
+ const reqBody = getFetchRequestArgBody(hint?.input ?? []);
180
290
  const [rawRequestBody] = getBodyString(reqBody);
181
291
  const requestBody = rawRequestBody != null ? truncateBody(rawRequestBody) : void 0;
292
+ const duration = calcDuration(hint);
293
+ const relativeUrl = stripUrlOrigin(url);
294
+ const statusStr = statusCode != null ? String(statusCode) : "failed";
295
+ const durationStr = duration != null ? ` (${duration}ms)` : "";
296
+ breadcrumb.message = `Fetch ${method} ${relativeUrl} -> ${statusStr}${durationStr}`;
182
297
  if (breadcrumb.data) {
183
298
  breadcrumb.data["requestBody"] = requestBody;
299
+ breadcrumb.data["duration"] = duration;
184
300
  }
185
301
  const contentType = response?.headers?.get("content-type") ?? "";
186
302
  if (isStreamByContentType(contentType)) {
187
303
  if (breadcrumb.data) {
188
304
  breadcrumb.data["responseBody"] = "[streaming response - not captured]";
189
305
  }
190
- await handler({ type: "fetch", method, url, statusCode, requestBody, responseBody: "[streaming response - not captured]", isError, cause });
306
+ await handler({ type: "fetch", method, url, statusCode, requestBody, responseBody: "[streaming response - not captured]", isError, cause, duration });
191
307
  return;
192
308
  }
193
309
  let responseBody;
@@ -207,33 +323,77 @@ async function handleFetchBreadcrumb(breadcrumb, hint, handler) {
207
323
  if (breadcrumb.data) {
208
324
  breadcrumb.data["responseBody"] = responseBody;
209
325
  }
210
- await handler({ type: "fetch", method, url, statusCode, requestBody, responseBody, isError, cause });
326
+ await handler({ type: "fetch", method, url, statusCode, requestBody, responseBody, isError, cause, duration });
211
327
  }
212
328
  function createNetworkObserver(opts, subscribers) {
213
- const shouldIgnore = createUrlMatcher(opts.ignoreUrls);
329
+ const isIgnored = createUrlMatcher(opts.ignoreUrls);
214
330
  const pgRestPatterns = opts.pgRestUrlPatterns ?? DEFAULT_PGREST_URL_PATTERNS;
215
331
  const pgRestWhitelistCodes = opts.pgRestWhitelistCodes ?? DEFAULT_PGREST_WHITELIST_CODES;
216
- function tryDispatchPgRestWhitelistError(requestType, method, url, statusCode, requestBody, responseBody) {
332
+ const precedingBreadcrumbsLimit = opts.precedingBreadcrumbsLimit;
333
+ const authPatterns = opts.authUrlPatterns ?? DEFAULT_AUTH_URL_PATTERNS;
334
+ const authWhitelistCodes = opts.authWhitelistCodes ?? DEFAULT_AUTH_WHITELIST_CODES;
335
+ const storagePatterns = opts.storageUrlPatterns ?? DEFAULT_STORAGE_URL_PATTERNS;
336
+ const storageWhitelistErrors = opts.storageWhitelistErrors ?? DEFAULT_STORAGE_WHITELIST_ERRORS;
337
+ const shouldIgnore = (url) => {
338
+ return isIgnored(url) && !isPgRestRequest(url, pgRestPatterns) && !isAuthRequest(url, authPatterns) && !isStorageRequest(url, storagePatterns);
339
+ };
340
+ function tryDispatchError(requestType, method, url, statusCode, requestBody, responseBody) {
217
341
  if (statusCode == null) return;
218
- if (!isPgRestRequest(url, pgRestPatterns)) return;
219
- const pgRestError = parsePgRestErrorBody(responseBody);
220
- if (!pgRestError) return;
221
- if (pgRestWhitelistCodes.length > 0 && !pgRestWhitelistCodes.includes(pgRestError.code)) return;
222
- const info = {
223
- type: requestType,
224
- method,
225
- url,
226
- statusCode,
227
- pgRestError,
228
- requestBody,
229
- responseBody
230
- };
231
- for (const sub of subscribers) sub.onPgRestWhitelistError(info);
342
+ const errorRequestType = isPgRestRequest(url, pgRestPatterns) ? "pgrest" : isAuthRequest(url, authPatterns) ? "auth" : isStorageRequest(url, storagePatterns) ? "storage" : null;
343
+ if (!errorRequestType) return;
344
+ const allBreadcrumbs = getIsolationScope().getScopeData().breadcrumbs;
345
+ const precedingBreadcrumbs = precedingBreadcrumbsLimit != null ? allBreadcrumbs.slice(-precedingBreadcrumbsLimit) : allBreadcrumbs.slice();
346
+ if (errorRequestType === "pgrest") {
347
+ const pgRestError = parsePgRestErrorBody(responseBody);
348
+ if (!pgRestError) return;
349
+ if (pgRestWhitelistCodes.length > 0 && !pgRestWhitelistCodes.includes(pgRestError.code)) return;
350
+ const info = {
351
+ type: requestType,
352
+ method,
353
+ url,
354
+ statusCode,
355
+ pgRestError,
356
+ requestBody,
357
+ responseBody,
358
+ precedingBreadcrumbs
359
+ };
360
+ for (const sub of subscribers) sub.onPgRestWhitelistError(info);
361
+ } else if (errorRequestType === "auth") {
362
+ const authError = parseAuthErrorBody(responseBody);
363
+ if (!authError) return;
364
+ if (authWhitelistCodes.length > 0 && !authWhitelistCodes.includes(authError.code)) return;
365
+ const info = {
366
+ type: requestType,
367
+ method,
368
+ url,
369
+ statusCode,
370
+ authError,
371
+ requestBody,
372
+ responseBody,
373
+ precedingBreadcrumbs
374
+ };
375
+ for (const sub of subscribers) sub.onAuthWhitelistError(info);
376
+ } else if (errorRequestType === "storage") {
377
+ const storageError = parseStorageErrorBody(responseBody);
378
+ if (!storageError) return;
379
+ if (storageWhitelistErrors.length > 0 && !storageWhitelistErrors.includes(storageError.message)) return;
380
+ const info = {
381
+ type: requestType,
382
+ method,
383
+ url,
384
+ statusCode,
385
+ storageError,
386
+ requestBody,
387
+ responseBody,
388
+ precedingBreadcrumbs
389
+ };
390
+ for (const sub of subscribers) sub.onStorageWhitelistError(info);
391
+ }
232
392
  }
233
393
  function makeHandler(requestType) {
234
394
  return (info) => {
235
395
  for (const sub of subscribers) void sub.onNetworkRequest(info);
236
- tryDispatchPgRestWhitelistError(
396
+ tryDispatchError(
237
397
  requestType,
238
398
  info.method,
239
399
  info.url,
@@ -253,10 +413,11 @@ function createNetworkObserver(opts, subscribers) {
253
413
  const fetchHandler = makeHandler("fetch");
254
414
  client.on("beforeAddBreadcrumb", (breadcrumb, hint) => {
255
415
  const url = breadcrumb.data?.url ?? "";
256
- if (shouldIgnore(url)) return;
257
416
  if (breadcrumb.category === "xhr") {
417
+ if (shouldIgnore(url)) return;
258
418
  handleXhrBreadcrumb(breadcrumb, hint, xhrHandler);
259
419
  } else if (breadcrumb.category === "fetch") {
420
+ if (shouldIgnore(url)) return;
260
421
  void handleFetchBreadcrumb(breadcrumb, hint, fetchHandler);
261
422
  }
262
423
  });
@@ -349,56 +510,10 @@ var PostMessageSubscriber = class {
349
510
  };
350
511
  this.send(msg, "*");
351
512
  }
352
- onNetworkRequest({ method, url, statusCode, requestBody, responseBody, isError, cause }) {
353
- const isClientError = statusCode != null && statusCode >= 400 && statusCode < 500;
354
- if (!isError && !isClientError) return;
355
- const urlPath = extractUrlPath(url);
356
- if (isError) {
357
- const causeDesc = cause != null ? String(cause) : "NetworkError";
358
- const errorMessage = `${method} ${urlPath} failed: ${causeDesc}`;
359
- const msg = {
360
- type: "GLOBAL_ERROR",
361
- message: errorMessage,
362
- error: cause != null ? { name: cause.name, message: cause.message, stack: cause.stack } : null,
363
- errorData: {
364
- name: cause?.name ?? "NetworkError",
365
- message: cause?.message ?? causeDesc,
366
- stack: cause?.stack ?? null,
367
- fileName: url,
368
- lineNumber: 0,
369
- columnNumber: 0,
370
- httpPath: urlPath,
371
- httpStatus: 0,
372
- httpMethod: method,
373
- requestBody: requestBody ?? "",
374
- responseBody: ""
375
- }
376
- };
377
- this.send(msg, "*");
378
- } else {
379
- const errorMessage = `${method} ${urlPath} -> ${statusCode}`;
380
- const msg = {
381
- type: "GLOBAL_ERROR",
382
- message: errorMessage,
383
- error: null,
384
- errorData: {
385
- name: "HTTPClientError",
386
- message: errorMessage,
387
- stack: null,
388
- fileName: url,
389
- lineNumber: 0,
390
- columnNumber: 0,
391
- httpPath: urlPath,
392
- httpStatus: statusCode,
393
- httpMethod: method,
394
- requestBody: requestBody ?? "",
395
- responseBody: responseBody ?? ""
396
- }
397
- };
398
- this.send(msg, "*");
399
- }
513
+ // postMessage 场景不需要上报 network 日志
514
+ onNetworkRequest(_info) {
400
515
  }
401
- onPgRestWhitelistError({ type, method, url, statusCode, pgRestError, requestBody, responseBody }) {
516
+ onPgRestWhitelistError({ type, method, url, statusCode, pgRestError, requestBody, responseBody, precedingBreadcrumbs }) {
402
517
  const urlPath = extractUrlPath(url);
403
518
  const code = pgRestError.code;
404
519
  const errorMessage = `${method} ${urlPath} -> ${statusCode} [PgRest:${code}]`;
@@ -421,7 +536,63 @@ var PostMessageSubscriber = class {
421
536
  pgRestCode: code,
422
537
  pgRestDetails: pgRestError.details ?? void 0,
423
538
  pgRestHint: pgRestError.hint ?? void 0,
424
- requestType: type
539
+ requestType: type,
540
+ precedingBreadcrumbs
541
+ }
542
+ };
543
+ this.send(msg, "*");
544
+ }
545
+ onAuthWhitelistError({ type, method, url, statusCode, authError, requestBody, responseBody, precedingBreadcrumbs }) {
546
+ const urlPath = extractUrlPath(url);
547
+ const code = authError.code;
548
+ const errorMessage = `${method} ${urlPath} -> ${statusCode} [Auth:${code}]`;
549
+ const msg = {
550
+ type: "GLOBAL_ERROR",
551
+ message: errorMessage,
552
+ error: null,
553
+ errorData: {
554
+ name: "AuthWhitelistError",
555
+ message: authError.message,
556
+ stack: null,
557
+ fileName: url,
558
+ lineNumber: 0,
559
+ columnNumber: 0,
560
+ httpPath: urlPath,
561
+ httpStatus: statusCode,
562
+ httpMethod: method,
563
+ requestBody: requestBody ?? "",
564
+ responseBody,
565
+ authCode: code,
566
+ authRequestId: authError.requestId ?? void 0,
567
+ requestType: type,
568
+ precedingBreadcrumbs
569
+ }
570
+ };
571
+ this.send(msg, "*");
572
+ }
573
+ onStorageWhitelistError({ type, method, url, statusCode, storageError, requestBody, responseBody, precedingBreadcrumbs }) {
574
+ const urlPath = extractUrlPath(url);
575
+ const errorMessage = `${method} ${urlPath} -> ${statusCode} [Storage:${storageError.error}]`;
576
+ const msg = {
577
+ type: "GLOBAL_ERROR",
578
+ message: errorMessage,
579
+ error: null,
580
+ errorData: {
581
+ name: "StorageWhitelistError",
582
+ message: storageError.message,
583
+ stack: null,
584
+ fileName: url,
585
+ lineNumber: 0,
586
+ columnNumber: 0,
587
+ httpPath: urlPath,
588
+ httpStatus: statusCode,
589
+ httpMethod: method,
590
+ requestBody: requestBody ?? "",
591
+ responseBody,
592
+ storageError: storageError.error,
593
+ storageStatusCode: storageError.statusCode,
594
+ requestType: type,
595
+ precedingBreadcrumbs
425
596
  }
426
597
  };
427
598
  this.send(msg, "*");
@@ -431,11 +602,83 @@ function createPostMessageSubscriber(send) {
431
602
  return new PostMessageSubscriber(send);
432
603
  }
433
604
 
605
+ // src/subscribers/sentryEventSubscriber.ts
606
+ import { captureEvent } from "@sentry/core";
607
+ function toSentryLevel(consoleLevel) {
608
+ switch (consoleLevel) {
609
+ case "error":
610
+ return "error";
611
+ case "warn":
612
+ return "warning";
613
+ case "debug":
614
+ return "debug";
615
+ case "info":
616
+ return "info";
617
+ default:
618
+ return "log";
619
+ }
620
+ }
621
+ var SentryEventSubscriber = class {
622
+ constructor(opts = {}) {
623
+ __publicField(this, "captureAllNetworkRequests");
624
+ this.captureAllNetworkRequests = opts.captureAllNetworkRequests ?? true;
625
+ }
626
+ onConsole(info) {
627
+ const { level, args } = info;
628
+ const formattedMessage = formatConsoleArgs(args);
629
+ const sentryLevel = toSentryLevel(level);
630
+ captureEvent({
631
+ message: `[${level}]${formattedMessage}`,
632
+ level: sentryLevel,
633
+ // 按 level + 消息内容前 100 字符分组,同一类日志聚合为同一个 Issue
634
+ fingerprint: ["console", level, formattedMessage.slice(0, 100)],
635
+ tags: {
636
+ type: "console"
637
+ },
638
+ extra: { consoleType: level, args }
639
+ });
640
+ }
641
+ // Sentry 已自动捕获 JS 错误,不重复上报
642
+ onError(_info) {
643
+ }
644
+ onNetworkRequest(info) {
645
+ const { type, method, url, statusCode, requestBody, responseBody, isError, duration } = info;
646
+ const shouldCapture = this.captureAllNetworkRequests || isError || statusCode != null && statusCode >= 400;
647
+ if (!shouldCapture) return;
648
+ const urlPath = stripUrlOrigin(url);
649
+ const requestTypeLabel = type === "xhr" ? "XHR" : "Fetch";
650
+ const statusStr = statusCode != null ? String(statusCode) : "failed";
651
+ const durationStr = duration != null ? ` (${duration}ms)` : "";
652
+ const message = `${requestTypeLabel} ${method} ${urlPath} -> ${statusStr}${durationStr}`;
653
+ const level = isError ? "error" : statusCode != null && statusCode >= 400 ? "warning" : "info";
654
+ captureEvent({
655
+ message,
656
+ level,
657
+ // 按 method + url 路径固定分组,同一接口的多次报错聚合为同一个 Issue
658
+ fingerprint: ["network", method, urlPath],
659
+ tags: {
660
+ type: "network"
661
+ },
662
+ extra: { url, method, statusCode, duration, requestBody, responseBody }
663
+ });
664
+ }
665
+ onPgRestWhitelistError(_info) {
666
+ }
667
+ onAuthWhitelistError(_info) {
668
+ }
669
+ onStorageWhitelistError(_info) {
670
+ }
671
+ };
672
+ function createSentryEventSubscriber(opts) {
673
+ return new SentryEventSubscriber(opts);
674
+ }
675
+
434
676
  // src/stubs/sentry-react-stub.ts
435
677
  export * from "@sentry/react";
436
678
  var STUB_DSN = "https://stubPublicKey@o0.ingest.sentry.io/0";
437
- var OVERRIDE_DSN = typeof process !== "undefined" && process.env["SENTRY_OVERRIDE_DSN"] ? process.env["SENTRY_OVERRIDE_DSN"] : STUB_DSN;
438
- var _subscribers = [createPostMessageSubscriber()];
679
+ var OVERRIDE_DSN = import.meta.env.VITE_SENTRY_DSN || STUB_DSN;
680
+ var OVERRIDE_ENVIRONMENT = import.meta.env.VITE_SENTRY_ENV;
681
+ var _subscribers = [createPostMessageSubscriber(), createSentryEventSubscriber()];
439
682
  function configureStubSubscribers(subscribers) {
440
683
  _subscribers = subscribers;
441
684
  }
@@ -452,6 +695,7 @@ var init2 = (options) => {
452
695
  const result = RealSentry.init({
453
696
  ...options,
454
697
  dsn: OVERRIDE_DSN,
698
+ environment: OVERRIDE_ENVIRONMENT,
455
699
  beforeSend(event, hint) {
456
700
  const processed = capture.beforeSend(event, hint);
457
701
  return upstreamBeforeSend ? upstreamBeforeSend(processed, hint) : processed;
@@ -462,6 +706,15 @@ var init2 = (options) => {
462
706
  return upstreamBeforeBreadcrumb ? upstreamBeforeBreadcrumb(processed, hint) : processed;
463
707
  }
464
708
  });
709
+ const stubTags = {
710
+ app_id: import.meta.env.VITE_APP_ID,
711
+ environment: OVERRIDE_ENVIRONMENT
712
+ };
713
+ for (const [key, value] of Object.entries(stubTags)) {
714
+ if (value) {
715
+ RealSentry.setTag(key, value);
716
+ }
717
+ }
465
718
  capture.installNetworkObserver();
466
719
  capture.installConsoleObserver();
467
720
  return result;