@swifty.js/sentry 0.0.4 → 0.0.6
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/LICENSE +21 -0
- package/README.md +124 -144
- package/dist/constants/index.cjs +1 -1
- package/dist/constants/index.js +1 -1
- package/dist/core/api.cjs +1 -1
- package/dist/core/api.d.ts +28 -9
- package/dist/core/api.js +1 -1
- package/dist/core/breadcrumb.cjs +1 -1
- package/dist/core/breadcrumb.js +1 -1
- package/dist/core/decorate-http.cjs +1 -1
- package/dist/core/decorate-http.js +1 -1
- package/dist/core/decorate-route.cjs +1 -1
- package/dist/core/decorate-route.js +1 -1
- package/dist/core/decorates.cjs +1 -1
- package/dist/core/decorates.js +1 -1
- package/dist/core/error-dedup.cjs +1 -0
- package/dist/core/error-dedup.js +1 -0
- package/dist/core/framework-error.cjs +1 -1
- package/dist/core/framework-error.js +1 -1
- package/dist/core/handle-code-error.cjs +1 -1
- package/dist/core/handle-code-error.js +1 -1
- package/dist/core/handle-error.cjs +1 -1
- package/dist/core/handle-error.js +1 -1
- package/dist/core/handle-events.cjs +1 -1
- package/dist/core/handle-events.js +1 -1
- package/dist/core/handle-route.cjs +1 -1
- package/dist/core/handle-route.js +1 -1
- package/dist/core/identity.cjs +1 -1
- package/dist/core/identity.js +1 -1
- package/dist/core/options-schema.cjs +1 -1
- package/dist/core/options-schema.d.ts +42 -45
- package/dist/core/options-schema.js +1 -1
- package/dist/core/pv-lifecycle.cjs +1 -1
- package/dist/core/pv-lifecycle.js +1 -1
- package/dist/core/sdk-lifecycle.cjs +1 -1
- package/dist/core/sdk-lifecycle.d.ts +1 -1
- package/dist/core/sdk-lifecycle.js +1 -1
- package/dist/core/setup.cjs +1 -1
- package/dist/core/setup.js +1 -1
- package/dist/core/white-screen.cjs +1 -1
- package/dist/core/white-screen.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +4 -5
- package/dist/index.js +1 -1
- package/dist/node/dev-endpoint.cjs +1 -0
- package/dist/node/dev-endpoint.js +1 -0
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.js +1 -1
- package/dist/plugins/exposure/index.cjs +1 -1
- package/dist/plugins/exposure/index.d.ts +0 -1
- package/dist/plugins/exposure/index.js +1 -1
- package/dist/plugins/performance/first-screen-paint.cjs +1 -1
- package/dist/plugins/performance/first-screen-paint.js +1 -1
- package/dist/plugins/performance/index.cjs +1 -1
- package/dist/plugins/performance/index.d.ts +0 -1
- package/dist/plugins/performance/index.js +1 -1
- package/dist/plugins/performance/navigation-timing.cjs +1 -1
- package/dist/plugins/performance/navigation-timing.js +1 -1
- package/dist/plugins/performance/perf.cjs +1 -1
- package/dist/plugins/performance/perf.js +1 -1
- package/dist/plugins/performance/resource-element-fallback.cjs +1 -1
- package/dist/plugins/performance/resource-element-fallback.js +1 -1
- package/dist/plugins/performance/resource-timing.cjs +1 -1
- package/dist/plugins/performance/resource-timing.js +1 -1
- package/dist/plugins/screen-record/index.cjs +1 -1
- package/dist/plugins/screen-record/index.js +1 -1
- package/dist/plugins/screen-record/recorder.cjs +1 -1
- package/dist/plugins/screen-record/recorder.d.ts +1 -1
- package/dist/plugins/screen-record/recorder.js +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.d.ts +7 -80
- package/dist/react.js +1 -1
- package/dist/reporter/index.cjs +1 -1
- package/dist/reporter/index.js +1 -1
- package/dist/reporter/network-listener.cjs +1 -1
- package/dist/reporter/network-listener.js +1 -1
- package/dist/reporter/offline-cache.cjs +1 -1
- package/dist/reporter/offline-cache.js +1 -1
- package/dist/reporter/report-data-schema.cjs +1 -1
- package/dist/reporter/report-data-schema.js +1 -1
- package/dist/reporter/report-data.cjs +1 -1
- package/dist/reporter/report-data.js +1 -1
- package/dist/reporter/server-recovery.cjs +1 -1
- package/dist/reporter/server-recovery.js +1 -1
- package/dist/reporter/transports.cjs +1 -1
- package/dist/reporter/transports.js +1 -1
- package/dist/source-map/source-map.cjs +1 -0
- package/dist/source-map/source-map.js +1 -0
- package/dist/source-map/vite.cjs +1 -0
- package/dist/source-map/vite.js +1 -0
- package/dist/source-map/webpack.cjs +1 -0
- package/dist/source-map/webpack.js +1 -0
- package/dist/types/common.d.ts +10 -11
- package/dist/types/enums.cjs +1 -1
- package/dist/types/enums.d.ts +1 -45
- package/dist/types/enums.js +1 -1
- package/dist/types/options.d.ts +9 -13
- package/dist/types/plugin.cjs +1 -1
- package/dist/types/plugin.d.ts +0 -3
- package/dist/types/plugin.js +1 -1
- package/dist/utils/click-data.cjs +1 -1
- package/dist/utils/click-data.js +1 -1
- package/dist/utils/data-structures.cjs +1 -1
- package/dist/utils/data-structures.js +1 -1
- package/dist/utils/dom2str.cjs +1 -0
- package/dist/utils/dom2str.js +1 -0
- package/dist/utils/get-base-data.cjs +1 -1
- package/dist/utils/get-base-data.js +1 -1
- package/dist/utils/logger.cjs +1 -1
- package/dist/utils/logger.js +1 -1
- package/dist/utils/noop.cjs +1 -0
- package/dist/utils/noop.js +1 -0
- package/dist/utils/sentry.cjs +1 -1
- package/dist/utils/sentry.js +1 -1
- package/dist/utils/session.cjs +1 -1
- package/dist/utils/session.js +1 -1
- package/dist/utils/throttle.cjs +1 -1
- package/dist/utils/throttle.js +1 -1
- package/dist/utils/transform-http-data.cjs +1 -1
- package/dist/utils/transform-http-data.js +1 -1
- package/dist/utils/uuid.cjs +1 -0
- package/dist/utils/uuid.js +1 -0
- package/dist/vite.cjs +1 -1
- package/dist/vite.d.ts +2 -2
- package/dist/vite.js +1 -1
- package/dist/vue.cjs +1 -1
- package/dist/vue.js +1 -1
- package/dist/webpack.cjs +1 -1
- package/dist/webpack.js +1 -1
- package/package.json +22 -26
- package/dist/core/ip.cjs +0 -1
- package/dist/core/ip.d.ts +0 -24
- package/dist/core/ip.js +0 -1
- package/dist/reporter/batch.cjs +0 -1
- package/dist/reporter/batch.js +0 -1
- package/dist/sourcemap/sourcemap.cjs +0 -1
- package/dist/sourcemap/sourcemap.js +0 -1
- package/dist/sourcemap/vite.cjs +0 -1
- package/dist/sourcemap/vite.js +0 -1
- package/dist/sourcemap/webpack.cjs +0 -1
- package/dist/sourcemap/webpack.js +0 -1
- package/dist/utils/base64.cjs +0 -1
- package/dist/utils/base64.js +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 hangtiancheng
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ npm install vue
|
|
|
23
23
|
## Package Exports
|
|
24
24
|
|
|
25
25
|
```ts
|
|
26
|
-
import { init, destroy, isInitialized,
|
|
26
|
+
import { init, destroy, isInitialized, enablePlugin } from "@swifty.js/sentry";
|
|
27
27
|
import { PerformancePlugin, ScreenRecordPlugin, ExposurePlugin } from "@swifty.js/sentry/plugins";
|
|
28
28
|
import { ReactErrorBoundary } from "@swifty.js/sentry/react";
|
|
29
29
|
import { vuePlugin } from "@swifty.js/sentry/vue";
|
|
@@ -34,7 +34,7 @@ Each public export provides ESM, CJS, and TypeScript declaration files.
|
|
|
34
34
|
## Quick Start
|
|
35
35
|
|
|
36
36
|
```ts
|
|
37
|
-
import { init,
|
|
37
|
+
import { init, enablePlugin } from "@swifty.js/sentry";
|
|
38
38
|
import { PerformancePlugin, ScreenRecordPlugin, ExposurePlugin } from "@swifty.js/sentry/plugins";
|
|
39
39
|
|
|
40
40
|
init({
|
|
@@ -43,9 +43,7 @@ init({
|
|
|
43
43
|
userId: "anonymous",
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
pluginEnable(ScreenRecordPlugin);
|
|
48
|
-
pluginEnable(ExposurePlugin);
|
|
46
|
+
enablePlugin(new PerformancePlugin(), new ScreenRecordPlugin(), new ExposurePlugin());
|
|
49
47
|
```
|
|
50
48
|
|
|
51
49
|
`dsn` must be a non-empty string. If `dsn` is empty, initialization is rejected.
|
|
@@ -71,7 +69,7 @@ init({
|
|
|
71
69
|
|
|
72
70
|
### destroy
|
|
73
71
|
|
|
74
|
-
`destroy()` cleans plugin instances, event subscriptions, browser listeners, and decorated global methods.
|
|
72
|
+
`destroy()` cleans plugin instances, event subscriptions, browser listeners, and decorated global methods, and resets per-session state (breadcrumbs, error deduplication, queued reports).
|
|
75
73
|
|
|
76
74
|
```ts
|
|
77
75
|
import { destroy } from "@swifty.js/sentry";
|
|
@@ -95,48 +93,43 @@ if (!isInitialized()) {
|
|
|
95
93
|
|
|
96
94
|
`init` accepts partial options. Values not provided by the caller use SDK defaults.
|
|
97
95
|
|
|
98
|
-
| Option
|
|
99
|
-
|
|
|
100
|
-
| `dsn`
|
|
101
|
-
| `projectId`
|
|
102
|
-
| `userId`
|
|
103
|
-
| `disabled`
|
|
104
|
-
| `enableXhr`
|
|
105
|
-
| `enableFetch`
|
|
106
|
-
| `enableClick`
|
|
107
|
-
| `enableError`
|
|
108
|
-
| `enableUnhandledRejection`
|
|
109
|
-
| `enableHashChange`
|
|
110
|
-
| `enableHistory`
|
|
111
|
-
| `
|
|
112
|
-
| `
|
|
113
|
-
| `
|
|
114
|
-
| `
|
|
115
|
-
| `
|
|
116
|
-
| `
|
|
117
|
-
| `
|
|
118
|
-
| `
|
|
119
|
-
| `
|
|
120
|
-
| `
|
|
121
|
-
| `
|
|
122
|
-
| `
|
|
123
|
-
| `
|
|
124
|
-
| `
|
|
125
|
-
| `
|
|
126
|
-
| `
|
|
127
|
-
| `
|
|
128
|
-
| `
|
|
129
|
-
| `
|
|
130
|
-
| `
|
|
131
|
-
| `
|
|
132
|
-
| `
|
|
133
|
-
| `
|
|
134
|
-
| `
|
|
135
|
-
| `onBeforePushBreadcrumb` | `function` | `undefined` | Hook before storing a breadcrumb. |
|
|
136
|
-
| `onBeforeReportData` | `function` | `undefined` | Hook before one event enters Reporter queue. |
|
|
137
|
-
| `beforePushEventList` | `function` | `undefined` | Hook before a batch enters transport. |
|
|
138
|
-
| `afterSendData` | `function` | `undefined` | Hook after a batch enters transport successfully. |
|
|
139
|
-
| `handleHttpError` | `function` | `undefined` | Custom HTTP error callback. |
|
|
96
|
+
| Option | Type | Default | Description |
|
|
97
|
+
| --------------------------- | ---------------------- | --------------------------------------------------- | ------------------------------------------------------ |
|
|
98
|
+
| `dsn` | `string` | `""` | Report endpoint. Required for initialization. |
|
|
99
|
+
| `projectId` | `string` | `"unknown"` | Frontend project identifier. |
|
|
100
|
+
| `userId` | `string` | `"unknown"` | Current user identifier. |
|
|
101
|
+
| `disabled` | `boolean` | `false` | Disable the SDK. |
|
|
102
|
+
| `enableXhr` | `boolean` | `true` | Capture XMLHttpRequest requests. |
|
|
103
|
+
| `enableFetch` | `boolean` | `true` | Capture fetch requests. |
|
|
104
|
+
| `enableClick` | `boolean` | `true` | Capture declarative click events. |
|
|
105
|
+
| `enableError` | `boolean` | `true` | Capture runtime and resource errors. |
|
|
106
|
+
| `enableUnhandledRejection` | `boolean` | `true` | Capture unhandled promise rejections. |
|
|
107
|
+
| `enableHashChange` | `boolean` | `true` | Capture hash navigation. |
|
|
108
|
+
| `enableHistory` | `boolean` | `true` | Capture history navigation. |
|
|
109
|
+
| `enableWhiteScreen` | `boolean` | `true` | Enable white-screen detection. |
|
|
110
|
+
| `enableFingerprint` | `boolean` | `false` | Enable FingerprintJS anonymous visitor identity. |
|
|
111
|
+
| `anonymousId` | `string` | `"unknown"` | SDK-generated anonymous visitor id. |
|
|
112
|
+
| `visitorId` | `string` | `"unknown"` | Backend-bound visitor id. |
|
|
113
|
+
| `screenRecordDurationMs` | `number` | `3000` | Rolling screen record window length. |
|
|
114
|
+
| `screenRecordEventTypes` | `EventType[]` | `[Error, Xhr, Fetch, Resource, UnhandledRejection]` | Event types that trigger screen record reporting. |
|
|
115
|
+
| `hasSkeleton` | `boolean` | `false` | Whether the page has a skeleton screen. |
|
|
116
|
+
| `rootCssSelectors` | `string[]` | `["html", "body", "#app", "#root"]` | Root selectors used by white-screen detection. |
|
|
117
|
+
| `clickThrottleDelay` | `number` | `0` | Click capture throttle delay in milliseconds. |
|
|
118
|
+
| `maxBreadcrumbs` | `number` | `30` | Breadcrumb capacity. |
|
|
119
|
+
| `repeatCodeError` | `boolean` | `false` | Report duplicate code errors. |
|
|
120
|
+
| `enableHttpPerformance` | `boolean` | `false` | Report successful HTTP requests as performance events. |
|
|
121
|
+
| `ignoreErrors` | `(string \| RegExp)[]` | `[]` | Runtime error ignore rules. |
|
|
122
|
+
| `excludeApis` | `(string \| RegExp)[]` | `[]` | HTTP request ignore rules. |
|
|
123
|
+
| `cacheMaxLength` | `number` | `10` | Maximum batch size. |
|
|
124
|
+
| `cacheWaitingTime` | `number` | `2000` | Batch wait time in milliseconds. |
|
|
125
|
+
| `maxQueueLength` | `number` | `200` | Maximum queued events while offline or retrying. |
|
|
126
|
+
| `retryIntervalMilliseconds` | `number` | `60000` | Server recovery probe interval. |
|
|
127
|
+
| `offlineCacheKey` | `string` | `"swifty_sentry_offline_cache"` | localStorage key for offline cache. |
|
|
128
|
+
| `tracesSampleRate` | `number` | `1` | Sampling rate from 0 to 1. |
|
|
129
|
+
| `beforeBreadcrumb` | `function` | `undefined` | Hook before storing a breadcrumb. |
|
|
130
|
+
| `beforeSend` | `function` | `undefined` | Hook before one event enters Reporter queue. |
|
|
131
|
+
| `beforeSendBatch` | `function` | `undefined` | Hook before a batch enters transport. |
|
|
132
|
+
| `afterSend` | `function` | `undefined` | Hook after a batch enters transport successfully. |
|
|
140
133
|
|
|
141
134
|
Example production configuration:
|
|
142
135
|
|
|
@@ -159,21 +152,23 @@ init({
|
|
|
159
152
|
|
|
160
153
|
Reporter sends `IReportData` objects to the configured `dsn`.
|
|
161
154
|
|
|
162
|
-
| Field
|
|
163
|
-
|
|
|
164
|
-
| `id`
|
|
165
|
-
| `type`
|
|
166
|
-
| `name`
|
|
167
|
-
| `message`
|
|
168
|
-
| `status`
|
|
169
|
-
| `time`
|
|
170
|
-
| `timestamp`
|
|
171
|
-
| `url`
|
|
172
|
-
| `userId`
|
|
173
|
-
| `
|
|
174
|
-
| `
|
|
175
|
-
| `
|
|
176
|
-
| `
|
|
155
|
+
| Field | Description |
|
|
156
|
+
| ------------- | ------------------------------------- |
|
|
157
|
+
| `id` | Reporter instance id. |
|
|
158
|
+
| `type` | Event type. |
|
|
159
|
+
| `name` | Event name. |
|
|
160
|
+
| `message` | Event message. |
|
|
161
|
+
| `status` | `OK` or `Error`. |
|
|
162
|
+
| `time` | Formatted time. |
|
|
163
|
+
| `timestamp` | Numeric timestamp. |
|
|
164
|
+
| `url` | Current page URL. |
|
|
165
|
+
| `userId` | User identifier. |
|
|
166
|
+
| `anonymousId` | FingerprintJS anonymous visitor id. |
|
|
167
|
+
| `visitorId` | Backend-bound visitor id. |
|
|
168
|
+
| `projectId` | Project identifier. |
|
|
169
|
+
| `sdkVersion` | SDK version. |
|
|
170
|
+
| `deviceInfo` | Device, browser, OS, and screen data. |
|
|
171
|
+
| `payload` | Original event payload. |
|
|
177
172
|
|
|
178
173
|
## Event Types
|
|
179
174
|
|
|
@@ -266,7 +261,7 @@ On hash or history route changes, it:
|
|
|
266
261
|
- Deduplicates unchanged URLs.
|
|
267
262
|
- Reports `PageDwell` for the previous page.
|
|
268
263
|
- Reports a new PV for the next page.
|
|
269
|
-
- Flushes current dwell time on `
|
|
264
|
+
- Flushes current dwell time on `pagehide` when possible.
|
|
270
265
|
|
|
271
266
|
Dwell time less than or equal to 100 ms is ignored to reduce noise.
|
|
272
267
|
|
|
@@ -317,20 +312,20 @@ Custom `swifty-sentry-*` attributes become `params`.
|
|
|
317
312
|
|
|
318
313
|
The reported click payload (`DeclarativeClickData`) includes:
|
|
319
314
|
|
|
320
|
-
| Field | Type | Description
|
|
321
|
-
| ---------------- | ------------------------------------------ |
|
|
322
|
-
| `ev` | `string` | Event ID (from `swifty-sentry-ev`, `title`, `swifty-sentry-el`, or tag).
|
|
323
|
-
| `msg` | `string` | Human-readable message (from `swifty-sentry-msg`, text, `aria-label`, or tag).
|
|
324
|
-
| `triggerPageUrl` | `string` | Current page URL (`location.href`).
|
|
325
|
-
| `x` | `number` | Click X coordinate (element offset + scroll offset).
|
|
326
|
-
| `y` | `number` | Click Y coordinate (element offset + scroll offset).
|
|
327
|
-
| `params` | `Readonly<Record<string, string \| null>>` | Custom `swifty-sentry-*` attributes (excluding reserved keys).
|
|
328
|
-
| `elementPath` | `string` |
|
|
329
|
-
| `triggerTime` | `number` | `Date.now()` at click time.
|
|
315
|
+
| Field | Type | Description |
|
|
316
|
+
| ---------------- | ------------------------------------------ | -------------------------------------------------------------------------------- |
|
|
317
|
+
| `ev` | `string` | Event ID (from `swifty-sentry-ev`, `title`, `swifty-sentry-el`, or tag). |
|
|
318
|
+
| `msg` | `string` | Human-readable message (from `swifty-sentry-msg`, text, `aria-label`, or tag). |
|
|
319
|
+
| `triggerPageUrl` | `string` | Current page URL (`location.href`). |
|
|
320
|
+
| `x` | `number` | Click X coordinate (element offset + scroll offset). |
|
|
321
|
+
| `y` | `number` | Click Y coordinate (element offset + scroll offset). |
|
|
322
|
+
| `params` | `Readonly<Record<string, string \| null>>` | Custom `swifty-sentry-*` attributes (excluding reserved keys). |
|
|
323
|
+
| `elementPath` | `string` | CSS-selector-like ancestor path (nearest 5 levels with id/class, max 128 chars). |
|
|
324
|
+
| `triggerTime` | `number` | `Date.now()` at click time. |
|
|
330
325
|
|
|
331
326
|
## White-Screen Detection
|
|
332
327
|
|
|
333
|
-
White-screen detection samples viewport points after the page is ready and checks whether those points still resolve to configured root elements.
|
|
328
|
+
White-screen detection samples viewport points every second after the page is ready and checks whether those points still resolve to configured root elements. Sampling stops as soon as real content is observed; a white screen is reported only when the page stays blank for 10 consecutive samples. In skeleton mode the first sample records a baseline of on-screen selectors, and a report is sent only when the skeleton never transitions to different content within the sampling window.
|
|
334
329
|
|
|
335
330
|
Default root selectors:
|
|
336
331
|
|
|
@@ -410,20 +405,19 @@ Reporter behavior:
|
|
|
410
405
|
- Flushes cached events after network recovery.
|
|
411
406
|
- Probes server recovery with HEAD requests after failed fetch reports.
|
|
412
407
|
- Avoids concurrent flush races with an `isFlushing` guard.
|
|
413
|
-
- Supports `sendBeacon
|
|
408
|
+
- Supports `sendBeacon` and fetch transports.
|
|
414
409
|
|
|
415
410
|
Transport priority:
|
|
416
411
|
|
|
417
412
|
1. Use `navigator.sendBeacon` for batches up to 60 KB.
|
|
418
|
-
2. Use
|
|
419
|
-
3. Use fetch POST as the fallback.
|
|
413
|
+
2. Use fetch POST as the fallback, with `keepalive` enabled for bodies up to 60 KB.
|
|
420
414
|
|
|
421
415
|
Flush offline cache manually:
|
|
422
416
|
|
|
423
417
|
```ts
|
|
424
|
-
import {
|
|
418
|
+
import { flushOfflineCache } from "@swifty.js/sentry";
|
|
425
419
|
|
|
426
|
-
await
|
|
420
|
+
await flushOfflineCache();
|
|
427
421
|
```
|
|
428
422
|
|
|
429
423
|
## Reporter Hooks
|
|
@@ -431,20 +425,20 @@ await sendLocal();
|
|
|
431
425
|
Register hooks after initialization or provide equivalent hooks in `init` options.
|
|
432
426
|
|
|
433
427
|
```ts
|
|
434
|
-
import {
|
|
428
|
+
import { afterSend, beforeSend, beforeSendBatch } from "@swifty.js/sentry";
|
|
435
429
|
|
|
436
|
-
|
|
430
|
+
beforeSend((data) => {
|
|
437
431
|
if (data.type === "Click") {
|
|
438
432
|
return false;
|
|
439
433
|
}
|
|
440
434
|
return data;
|
|
441
435
|
});
|
|
442
436
|
|
|
443
|
-
|
|
437
|
+
beforeSendBatch((eventList) => {
|
|
444
438
|
return eventList.filter((item) => item.status !== "OK");
|
|
445
439
|
});
|
|
446
440
|
|
|
447
|
-
|
|
441
|
+
afterSend((eventList) => {
|
|
448
442
|
console.log("reported", eventList.length);
|
|
449
443
|
});
|
|
450
444
|
```
|
|
@@ -454,13 +448,13 @@ Equivalent initialization form:
|
|
|
454
448
|
```ts
|
|
455
449
|
init({
|
|
456
450
|
dsn: "/api/log",
|
|
457
|
-
|
|
451
|
+
beforeSend(data) {
|
|
458
452
|
return data;
|
|
459
453
|
},
|
|
460
|
-
|
|
454
|
+
beforeSendBatch(eventList) {
|
|
461
455
|
return eventList;
|
|
462
456
|
},
|
|
463
|
-
|
|
457
|
+
afterSend(eventList) {
|
|
464
458
|
console.log(eventList.length);
|
|
465
459
|
},
|
|
466
460
|
});
|
|
@@ -517,34 +511,15 @@ tracePageView({
|
|
|
517
511
|
});
|
|
518
512
|
```
|
|
519
513
|
|
|
520
|
-
### getBaseInfo and getUserId
|
|
521
|
-
|
|
522
|
-
```ts
|
|
523
|
-
import { getBaseInfo, getUserId } from "@swifty.js/sentry";
|
|
524
|
-
|
|
525
|
-
const baseInfo = getBaseInfo();
|
|
526
|
-
const userId = getUserId();
|
|
527
|
-
```
|
|
528
|
-
|
|
529
|
-
### getIPs
|
|
530
|
-
|
|
531
|
-
`getIPs` attempts to collect WebRTC ICE candidate IP values in browsers that support the required APIs. It returns an empty array when unsupported.
|
|
532
|
-
|
|
533
|
-
```ts
|
|
534
|
-
import { getIPs } from "@swifty.js/sentry";
|
|
535
|
-
|
|
536
|
-
const ips = await getIPs();
|
|
537
|
-
```
|
|
538
|
-
|
|
539
514
|
## Plugin System
|
|
540
515
|
|
|
541
516
|
Plugins extend the SDK without coupling optional capabilities to the core entry. A plugin class extends `SentryPlugin`, implements `init`, and can implement `destroy` for cleanup.
|
|
542
517
|
|
|
543
518
|
```ts
|
|
544
|
-
import {
|
|
519
|
+
import { enablePlugin } from "@swifty.js/sentry";
|
|
545
520
|
import { PerformancePlugin } from "@swifty.js/sentry/plugins";
|
|
546
521
|
|
|
547
|
-
|
|
522
|
+
enablePlugin(new PerformancePlugin());
|
|
548
523
|
```
|
|
549
524
|
|
|
550
525
|
Enabled plugins are stored in the plugin registry. `destroy()` calls each plugin's `destroy()` method when available.
|
|
@@ -552,10 +527,10 @@ Enabled plugins are stored in the plugin registry. `destroy()` calls each plugin
|
|
|
552
527
|
## PerformancePlugin
|
|
553
528
|
|
|
554
529
|
```ts
|
|
555
|
-
import {
|
|
530
|
+
import { enablePlugin } from "@swifty.js/sentry";
|
|
556
531
|
import { PerformancePlugin } from "@swifty.js/sentry/plugins";
|
|
557
532
|
|
|
558
|
-
|
|
533
|
+
enablePlugin(new PerformancePlugin());
|
|
559
534
|
```
|
|
560
535
|
|
|
561
536
|
The plugin collects:
|
|
@@ -572,31 +547,31 @@ Unsupported browser capabilities are skipped safely.
|
|
|
572
547
|
## ScreenRecordPlugin
|
|
573
548
|
|
|
574
549
|
```ts
|
|
575
|
-
import {
|
|
550
|
+
import { enablePlugin } from "@swifty.js/sentry";
|
|
576
551
|
import { ScreenRecordPlugin, unzipScreenRecord } from "@swifty.js/sentry/plugins";
|
|
577
552
|
|
|
578
|
-
|
|
553
|
+
enablePlugin(new ScreenRecordPlugin());
|
|
579
554
|
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
});
|
|
555
|
+
// With custom options
|
|
556
|
+
enablePlugin(new ScreenRecordPlugin({ durationMs: 5000 }));
|
|
583
557
|
```
|
|
584
558
|
|
|
585
559
|
Screen recording is based on rrweb. The plugin keeps a rolling record window. When selected error or network events occur, the recent record window is reported as a `ScreenRecord` event.
|
|
586
560
|
|
|
587
|
-
Decode a record payload:
|
|
561
|
+
Decode a record payload (async — pako is loaded on demand):
|
|
588
562
|
|
|
589
563
|
```ts
|
|
590
|
-
const events = unzipScreenRecord(recordPayload);
|
|
564
|
+
const events = await unzipScreenRecord(recordPayload);
|
|
591
565
|
```
|
|
592
566
|
|
|
593
567
|
## ExposurePlugin
|
|
594
568
|
|
|
595
569
|
```ts
|
|
596
|
-
import {
|
|
570
|
+
import { enablePlugin } from "@swifty.js/sentry";
|
|
597
571
|
import { ExposurePlugin } from "@swifty.js/sentry/plugins";
|
|
598
572
|
|
|
599
|
-
const exposure =
|
|
573
|
+
const exposure = new ExposurePlugin();
|
|
574
|
+
enablePlugin(exposure);
|
|
600
575
|
```
|
|
601
576
|
|
|
602
577
|
Observe one element:
|
|
@@ -709,8 +684,8 @@ import { defineConfig } from "vite";
|
|
|
709
684
|
import { sentryPlugin } from "@swifty.js/sentry/vite";
|
|
710
685
|
|
|
711
686
|
export default defineConfig({
|
|
712
|
-
// `
|
|
713
|
-
plugins: [sentryPlugin({
|
|
687
|
+
// `dsn` should match the @swifty.js/sentry `init({ dsn: "/api/log" })` dsn value
|
|
688
|
+
plugins: [sentryPlugin({ dsn: "/api/log" })],
|
|
714
689
|
});
|
|
715
690
|
```
|
|
716
691
|
|
|
@@ -718,21 +693,44 @@ export default defineConfig({
|
|
|
718
693
|
|
|
719
694
|
| Export | Vite Version | Description |
|
|
720
695
|
| --------------- | ------------ | --------------------------------------- |
|
|
721
|
-
| `sentryPlugin` | Vite
|
|
696
|
+
| `sentryPlugin` | Vite 8 | Default export. For current Vite. |
|
|
722
697
|
| `sentryPlugin7` | Vite 7 | For projects using Vite 7 specifically. |
|
|
723
698
|
|
|
699
|
+
Both factories take an optional options object.
|
|
700
|
+
|
|
724
701
|
### Options
|
|
725
702
|
|
|
726
703
|
| Option | Type | Default | Description |
|
|
727
704
|
| ------ | -------- | ----------- | ---------------------------------------- |
|
|
728
|
-
| `
|
|
705
|
+
| `dsn` | `string` | `"/sentry"` | The URL path to intercept POST requests. |
|
|
706
|
+
|
|
707
|
+
The plugin only activates for the dev server (`apply: "serve"`), creates a `logs/` directory in `process.cwd()`, writes a timestamped JSONL log file (`sentry_YYYYMMDDHHMMSS.jsonl`), enriches error records with original source positions resolved from the dev server's module graph source maps, and returns `{ code: 0, message: "success" }`.
|
|
708
|
+
|
|
709
|
+
## Webpack Dev-Server Plugin
|
|
710
|
+
|
|
711
|
+
The `@swifty.js/sentry/webpack` subpath provides the same mock report endpoint for webpack-dev-server, plus source map resolution based on emitted `.map` assets.
|
|
729
712
|
|
|
730
|
-
|
|
713
|
+
```ts
|
|
714
|
+
// webpack.config.mjs
|
|
715
|
+
import { sentryPlugin } from "@swifty.js/sentry/webpack";
|
|
716
|
+
|
|
717
|
+
export default {
|
|
718
|
+
plugins: [sentryPlugin({ dsn: "/api/log" })],
|
|
719
|
+
devServer: {
|
|
720
|
+
// ...
|
|
721
|
+
},
|
|
722
|
+
};
|
|
723
|
+
```
|
|
724
|
+
|
|
725
|
+
| Export | Description |
|
|
726
|
+
| --------------------- | ----------------------------------------------------------------------------- |
|
|
727
|
+
| `sentryPlugin` | Factory returning a `SentryWebpackPlugin` instance. Default export. |
|
|
728
|
+
| `SentryWebpackPlugin` | Webpack plugin class. No-op unless `compiler.options.devServer` exists. |
|
|
729
|
+
| `sentryMiddleware` | Connect/express-style middleware for manual mounting (no source map support). |
|
|
731
730
|
|
|
732
731
|
## Browser Compatibility
|
|
733
732
|
|
|
734
|
-
- `sendBeacon` is preferred for
|
|
735
|
-
- Image and fetch transports are used as fallbacks.
|
|
733
|
+
- `sendBeacon` is preferred for batches up to 60 KB; `fetch` POST is the fallback, using `keepalive` only for bodies up to 60 KB.
|
|
736
734
|
- `PerformanceObserver` powers Web Vitals, long task, and resource timing when available.
|
|
737
735
|
- `MutationObserver` is used as a fallback for dynamically inserted resources.
|
|
738
736
|
- `IntersectionObserver` is required by `ExposurePlugin`.
|
|
@@ -750,21 +748,3 @@ pnpm build
|
|
|
750
748
|
```
|
|
751
749
|
|
|
752
750
|
Coverage thresholds are 70 for lines, functions, branches, and statements.
|
|
753
|
-
|
|
754
|
-
## Build and Publish
|
|
755
|
-
|
|
756
|
-
```bash
|
|
757
|
-
pnpm build
|
|
758
|
-
pnpm build:tsup
|
|
759
|
-
python3 publish.py --dry-run
|
|
760
|
-
```
|
|
761
|
-
|
|
762
|
-
Publish after npm login:
|
|
763
|
-
|
|
764
|
-
```bash
|
|
765
|
-
python3 publish.py --publish --registry https://registry.npmjs.org/
|
|
766
|
-
```
|
|
767
|
-
|
|
768
|
-
The publish script validates lint, typecheck, tests, coverage, build output, ESM imports, CJS requires, package exports, absence of sourcemaps, absence of `dist/node_modules`, and absence of package tarball residue.
|
|
769
|
-
|
|
770
|
-
Published npm files are limited to `dist` and package metadata. Source files, tests, sourcemaps, and temporary tarballs are not published.
|
package/dist/constants/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("../types/enums.cjs"),r=require("../package.json.cjs");const{version:n}=r.default,t="unknown",
|
|
1
|
+
"use strict";var e=require("../types/enums.cjs"),r=require("../package.json.cjs");const{version:n}=r.default,t="unknown",a={dsn:"",projectId:t,userId:t,disabled:!1,enableXhr:!0,enableFetch:!0,enableClick:!0,enableError:!0,enableUnhandledRejection:!0,enableHashChange:!0,enableHistory:!0,enableWhiteScreen:!0,enableFingerprint:!1,anonymousId:t,visitorId:t,maxBreadcrumbs:30,screenRecordEventTypes:[e.EventType.Error,e.EventType.Xhr,e.EventType.Fetch,e.EventType.Resource,e.EventType.UnhandledRejection],hasSkeleton:!1,rootCssSelectors:["html","body","#app","#root"],clickThrottleDelay:0,screenRecordDurationMs:3e3,repeatCodeError:!1,enableHttpPerformance:!1,ignoreErrors:[],excludeApis:[],cacheMaxLength:10,cacheWaitingTime:2e3,maxQueueLength:200,retryIntervalMilliseconds:6e4,offlineCacheKey:"swifty_sentry_offline_cache",tracesSampleRate:1,debug:!1};exports.DEFAULT_OPTIONS=a,exports.MAX_BREADCRUMBS=30,exports.MAX_WHITE_SCREEN_SAMPLE_COUNT=10,exports.SDK_VERSION=n,exports.UNKNOWN=t,exports.WHITE_SCREEN_SAMPLE_INTERVAL=1e3;
|
package/dist/constants/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EventType as e}from"../types/enums.js";import r from"../package.json.js";const{version:n}=r,o=30,a=10,t=1e3,s="unknown",c={dsn:"",projectId:s,userId:s,disabled:!1,enableXhr:!0,enableFetch:!0,enableClick:!0,enableError:!0,enableUnhandledRejection:!0,enableHashChange:!0,enableHistory:!0,
|
|
1
|
+
import{EventType as e}from"../types/enums.js";import r from"../package.json.js";const{version:n}=r,o=30,a=10,t=1e3,s="unknown",c={dsn:"",projectId:s,userId:s,disabled:!1,enableXhr:!0,enableFetch:!0,enableClick:!0,enableError:!0,enableUnhandledRejection:!0,enableHashChange:!0,enableHistory:!0,enableWhiteScreen:!0,enableFingerprint:!1,anonymousId:s,visitorId:s,maxBreadcrumbs:30,screenRecordEventTypes:[e.Error,e.Xhr,e.Fetch,e.Resource,e.UnhandledRejection],hasSkeleton:!1,rootCssSelectors:["html","body","#app","#root"],clickThrottleDelay:0,screenRecordDurationMs:3e3,repeatCodeError:!1,enableHttpPerformance:!1,ignoreErrors:[],excludeApis:[],cacheMaxLength:10,cacheWaitingTime:2e3,maxQueueLength:200,retryIntervalMilliseconds:6e4,offlineCacheKey:"swifty_sentry_offline_cache",tracesSampleRate:1,debug:!1};export{c as DEFAULT_OPTIONS,o as MAX_BREADCRUMBS,a as MAX_WHITE_SCREEN_SAMPLE_COUNT,n as SDK_VERSION,s as UNKNOWN,t as WHITE_SCREEN_SAMPLE_INTERVAL};
|
package/dist/core/api.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("../types/enums.cjs");require("../constants/index.cjs");var t=require("../utils/get-base-data.cjs"),r=require("../utils/sentry.cjs");require("../utils/is-type.cjs")
|
|
1
|
+
"use strict";var e=require("../types/enums.cjs");require("../constants/index.cjs");var t=require("../utils/get-base-data.cjs"),r=require("../utils/sentry.cjs");require("../utils/is-type.cjs"),require("../utils/logger.cjs");var s=require("./handle-error.cjs"),a=require("../reporter/index.cjs");exports.afterSend=function(e){r.default.setOptions({afterSend:e})},exports.beforeSend=function(e){r.default.setOptions({beforeSend:e})},exports.beforeSendBatch=function(e){r.default.setOptions({beforeSendBatch:e})},exports.flushOfflineCache=async function(){await a.default.flushOfflineCache()},exports.traceCustomEvent=function(r){a.default.send({...t.default(),type:e.EventType.Custom,status:e.Status.OK,name:r.name,message:r.message,extra:r.extra})},exports.traceError=function(r){s.handleError({...t.default(),type:e.EventType.Error,status:e.Status.Error,extra:r})},exports.tracePageView=function(r={}){a.default.send({...t.default(),type:e.EventType.PV,name:r.name??"ManualPageView",message:r.message??location.href,status:e.Status.OK,extra:r.extra??{url:location.href,referrer:document.referrer}})},exports.tracePerformance=function(r){a.default.send({...t.default(),type:e.EventType.Performance,status:e.Status.OK,...r})};
|
package/dist/core/api.d.ts
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { AfterSendHook, BeforeSendHook, BeforeSendBatchHook } from '../types/options.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Copyright (c) 2026 hangtiancheng
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in
|
|
14
|
+
* all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
3
24
|
|
|
4
25
|
declare function traceError(error: unknown): void;
|
|
5
26
|
declare function tracePerformance(input: {
|
|
@@ -17,11 +38,9 @@ declare function tracePageView(input?: {
|
|
|
17
38
|
readonly message?: string;
|
|
18
39
|
readonly extra?: unknown;
|
|
19
40
|
}): void;
|
|
20
|
-
declare function
|
|
21
|
-
declare function
|
|
22
|
-
declare function
|
|
23
|
-
declare function
|
|
24
|
-
declare function afterSendData(hook: AfterSendDataHook): void;
|
|
25
|
-
declare function sendLocal(): Promise<void>;
|
|
41
|
+
declare function beforeSend(hook: BeforeSendHook): void;
|
|
42
|
+
declare function beforeSendBatch(hook: BeforeSendBatchHook): void;
|
|
43
|
+
declare function afterSend(hook: AfterSendHook): void;
|
|
44
|
+
declare function flushOfflineCache(): Promise<void>;
|
|
26
45
|
|
|
27
|
-
export {
|
|
46
|
+
export { afterSend, beforeSend, beforeSendBatch, flushOfflineCache, traceCustomEvent, traceError, tracePageView, tracePerformance };
|
package/dist/core/api.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Status as e,EventType as t}from"../types/enums.js";import"../constants/index.js";import r from"../utils/get-base-data.js";import
|
|
1
|
+
import{Status as e,EventType as t}from"../types/enums.js";import"../constants/index.js";import r from"../utils/get-base-data.js";import s from"../utils/sentry.js";import"../utils/is-type.js";import"../utils/logger.js";import{handleError as n}from"./handle-error.js";import o from"../reporter/index.js";function a(s){n({...r(),type:t.Error,status:e.Error,extra:s})}function i(s){o.send({...r(),type:t.Performance,status:e.OK,...s})}function m(s){o.send({...r(),type:t.Custom,status:e.OK,name:s.name,message:s.message,extra:s.extra})}function f(s={}){o.send({...r(),type:t.PV,name:s.name??"ManualPageView",message:s.message??location.href,status:e.OK,extra:s.extra??{url:location.href,referrer:document.referrer}})}function u(e){s.setOptions({beforeSend:e})}function p(e){s.setOptions({beforeSendBatch:e})}function c(e){s.setOptions({afterSend:e})}async function l(){await o.flushOfflineCache()}export{c as afterSend,u as beforeSend,p as beforeSendBatch,l as flushOfflineCache,m as traceCustomEvent,a as traceError,f as tracePageView,i as tracePerformance};
|
package/dist/core/breadcrumb.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../utils/data-structures.cjs");require("../types/enums.cjs");var s=require("../utils/sentry.cjs");require("../utils/is-type.cjs");class
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../utils/data-structures.cjs");require("../types/enums.cjs");var s=require("../utils/sentry.cjs");require("../utils/is-type.cjs"),require("../utils/logger.cjs");class r extends e.BoundedList{push(e){const{beforeBreadcrumb:r}=s.default.options;super.push(r?r(e):e)}}const t=new r;exports.default=t;
|
package/dist/core/breadcrumb.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{BoundedList as s}from"../utils/data-structures.js";import"../types/enums.js";import t from"../utils/sentry.js";import"../utils/is-type.js";import"../utils/logger.js";const r=new class extends s{push(s){const{beforeBreadcrumb:r}=t.options;super.push(r?r(s):s)}};export{r as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("../types/enums.cjs");require("../constants/index.cjs");var t=require("../utils/decorate-prop.cjs"),s=require("../utils/get-base-data.cjs"),r=require("../utils/is-excluded-api.cjs"),n=require("../utils/sentry.cjs");require("../utils/is-type.cjs");var i=require("../utils/server-timing.cjs")
|
|
1
|
+
"use strict";var e=require("../types/enums.cjs");require("../constants/index.cjs");var t=require("../utils/decorate-prop.cjs"),s=require("../utils/get-base-data.cjs"),r=require("../utils/is-excluded-api.cjs"),n=require("../utils/sentry.cjs");require("../utils/is-type.cjs");var i=require("../utils/server-timing.cjs");require("../utils/logger.cjs");var a=require("./bus.cjs");function o(e){return e.length>8192?e.slice(0,8192):e}function u(e){return 0===e||e>=400}function p(e,t){return"POST"===e.toUpperCase()&&t===n.default.options.dsn||r.default(t)}exports.pubFetch=function(){return t.default(globalThis,"fetch",t=>function(r,n){const c=function(e){return"string"==typeof e?e:e instanceof URL?e.href:e.url}(r),h=function(e,t){return t?.method?t.method.toUpperCase():"undefined"!=typeof Request&&e instanceof Request?e.method.toUpperCase():"GET"}(r,n);if(p(h,c))return t.call(globalThis,r,n);const d={...s.default(),type:e.EventType.Fetch,method:h,name:"Fetch",api:c,elapsedTime:0,statusCode:200},l=d.timestamp;return t.call(globalThis,r,n).then(t=>(d.elapsedTime=Date.now()-l,d.statusCode=t.status,d.serverTiming=i.getServerTimingFromHeaders(t.headers),u(t.status)?(d.requestData={body:n?.body},t.clone().text().then(e=>{d.responseData=o(e)}).catch(()=>{}).finally(()=>{a.pub(e.EventType.Fetch,d)})):a.pub(e.EventType.Fetch,d),t)).catch(t=>{throw d.elapsedTime=Date.now()-l,d.statusCode=0,d.requestData={body:n?.body},d.message=t instanceof Error?t.message:"Network error",a.pub(e.EventType.Fetch,d),t})})},exports.pubXhr=function(){const r=XMLHttpRequest.prototype,n=t.default(r,"open",t=>function(r,n,i,...a){return this.__sentry__={...s.default(),name:"XMLHttpRequest",type:e.EventType.Xhr,method:r.toUpperCase(),api:String(n),elapsedTime:0,statusCode:200},t.call(this,r,n,i,...a)}),c=t.default(r,"send",t=>function(s){if(!this.__sentry__)return t.call(this,s);const{method:r,api:n}=this.__sentry__,c=Date.now();return this.__sentry__.timestamp=c,this.__sentry__.time=new Date(c).toISOString(),this.addEventListener("loadend",()=>{p(r,n)||(this.__sentry__.statusCode=this.status,u(this.status)&&(this.__sentry__.requestData={body:s},this.__sentry__.responseData={responseType:this.responseType,response:"string"==typeof this.response?o(this.response):this.response}),this.__sentry__.serverTiming=i.parseServerTiming(this.getResponseHeader("server-timing")),this.__sentry__.elapsedTime=Date.now()-c,a.pub(e.EventType.Xhr,this.__sentry__))},{once:!0}),t.call(this,s)});return()=>{c(),n()}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EventType as t
|
|
1
|
+
import{EventType as t}from"../types/enums.js";import"../constants/index.js";import e from"../utils/decorate-prop.js";import s from"../utils/get-base-data.js";import r from"../utils/is-excluded-api.js";import n from"../utils/sentry.js";import"../utils/is-type.js";import{parseServerTiming as o,getServerTimingFromHeaders as i}from"../utils/server-timing.js";import"../utils/logger.js";import{pub as a}from"./bus.js";function p(t){return t.length>8192?t.slice(0,8192):t}function u(t){return 0===t||t>=400}function h(){const r=XMLHttpRequest.prototype,n=e(r,"open",e=>function(r,n,o,...i){return this.__sentry__={...s(),name:"XMLHttpRequest",type:t.Xhr,method:r.toUpperCase(),api:String(n),elapsedTime:0,statusCode:200},e.call(this,r,n,o,...i)}),i=e(r,"send",e=>function(s){if(!this.__sentry__)return e.call(this,s);const{method:r,api:n}=this.__sentry__,i=Date.now();return this.__sentry__.timestamp=i,this.__sentry__.time=new Date(i).toISOString(),this.addEventListener("loadend",()=>{m(r,n)||(this.__sentry__.statusCode=this.status,u(this.status)&&(this.__sentry__.requestData={body:s},this.__sentry__.responseData={responseType:this.responseType,response:"string"==typeof this.response?p(this.response):this.response}),this.__sentry__.serverTiming=o(this.getResponseHeader("server-timing")),this.__sentry__.elapsedTime=Date.now()-i,a(t.Xhr,this.__sentry__))},{once:!0}),e.call(this,s)});return()=>{i(),n()}}function _(){return e(globalThis,"fetch",e=>function(r,n){const o=function(t){return"string"==typeof t?t:t instanceof URL?t.href:t.url}(r),h=function(t,e){return e?.method?e.method.toUpperCase():"undefined"!=typeof Request&&t instanceof Request?t.method.toUpperCase():"GET"}(r,n);if(m(h,o))return e.call(globalThis,r,n);const _={...s(),type:t.Fetch,method:h,name:"Fetch",api:o,elapsedTime:0,statusCode:200},c=_.timestamp;return e.call(globalThis,r,n).then(e=>(_.elapsedTime=Date.now()-c,_.statusCode=e.status,_.serverTiming=i(e.headers),u(e.status)?(_.requestData={body:n?.body},e.clone().text().then(t=>{_.responseData=p(t)}).catch(()=>{}).finally(()=>{a(t.Fetch,_)})):a(t.Fetch,_),e)).catch(e=>{throw _.elapsedTime=Date.now()-c,_.statusCode=0,_.requestData={body:n?.body},_.message=e instanceof Error?e.message:"Network error",a(t.Fetch,_),e})})}function m(t,e){return"POST"===t.toUpperCase()&&e===n.options.dsn||r(e)}export{_ as pubFetch,h as pubXhr};
|