@devkitio/faultlens 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-DQD732MN.js → chunk-ZEZNKS4A.js} +76 -13
- package/dist/{chunk-YQKZEUXA.js → chunk-ZUSG3UKB.js} +58 -9
- package/dist/http-error-DTUBVanG.d.ts +10 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +2 -2
- package/dist/node/index.d.ts +4 -1
- package/dist/node/index.js +67 -11
- package/dist/nuxt/runtime/nitro-plugin.js +1 -1
- package/dist/nuxt/runtime/plugin.js +2 -2
- package/dist/react/index.js +2 -2
- package/dist/testing/index.js +1 -1
- package/package.json +9 -8
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createMonitorRuntime } from './chunk-
|
|
1
|
+
import { createMonitorRuntime, captureHttpError, createHttpErrorContext } from './chunk-ZUSG3UKB.js';
|
|
2
2
|
|
|
3
3
|
// src/browser-queue.ts
|
|
4
4
|
var DATABASE_NAME = "faultlens";
|
|
@@ -170,6 +170,8 @@ function installGlobalHandlers(monitor, transportPath) {
|
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
// src/instrumentation.ts
|
|
173
|
+
var fetchInstallations = /* @__PURE__ */ new WeakMap();
|
|
174
|
+
var xhrInstallations = /* @__PURE__ */ new WeakMap();
|
|
173
175
|
function requestUrl(input) {
|
|
174
176
|
const raw = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
|
|
175
177
|
try {
|
|
@@ -188,6 +190,11 @@ function defaultShouldPropagate(url) {
|
|
|
188
190
|
}
|
|
189
191
|
function installFetchInstrumentation(monitor, options = {}) {
|
|
190
192
|
const target = options.target ?? globalThis;
|
|
193
|
+
const existing = fetchInstallations.get(target);
|
|
194
|
+
if (existing) {
|
|
195
|
+
existing.references += 1;
|
|
196
|
+
return releaseFetchInstallation(target, existing);
|
|
197
|
+
}
|
|
191
198
|
const originalFetch = target.fetch;
|
|
192
199
|
if (typeof originalFetch !== "function") return () => void 0;
|
|
193
200
|
const instrumentedFetch = async function instrumentedFetch2(input, init) {
|
|
@@ -212,16 +219,41 @@ function installFetchInstrumentation(monitor, options = {}) {
|
|
|
212
219
|
try {
|
|
213
220
|
const response = await originalFetch.call(target, input, { ...init, headers });
|
|
214
221
|
span.setAttribute("http.status_code", response.status);
|
|
215
|
-
span.end(response.status
|
|
222
|
+
span.end(response.status === 200 ? "ok" : "error");
|
|
223
|
+
captureHttpError(
|
|
224
|
+
monitor,
|
|
225
|
+
"http.fetch",
|
|
226
|
+
void 0,
|
|
227
|
+
createHttpErrorContext("response", method, url, response.status),
|
|
228
|
+
options.shouldCaptureHttpError
|
|
229
|
+
);
|
|
216
230
|
return response;
|
|
217
231
|
} catch (error) {
|
|
218
232
|
span.end("error");
|
|
233
|
+
captureHttpError(
|
|
234
|
+
monitor,
|
|
235
|
+
"http.fetch",
|
|
236
|
+
error,
|
|
237
|
+
createHttpErrorContext("network", method, url, 0),
|
|
238
|
+
options.shouldCaptureHttpError
|
|
239
|
+
);
|
|
219
240
|
throw error;
|
|
220
241
|
}
|
|
221
242
|
};
|
|
222
243
|
target.fetch = instrumentedFetch;
|
|
244
|
+
const installation = { instrumentedFetch, originalFetch, references: 1 };
|
|
245
|
+
fetchInstallations.set(target, installation);
|
|
246
|
+
return releaseFetchInstallation(target, installation);
|
|
247
|
+
}
|
|
248
|
+
function releaseFetchInstallation(target, installation) {
|
|
249
|
+
let released = false;
|
|
223
250
|
return () => {
|
|
224
|
-
if (
|
|
251
|
+
if (released) return;
|
|
252
|
+
released = true;
|
|
253
|
+
installation.references -= 1;
|
|
254
|
+
if (installation.references > 0) return;
|
|
255
|
+
if (target.fetch === installation.instrumentedFetch) target.fetch = installation.originalFetch;
|
|
256
|
+
if (fetchInstallations.get(target) === installation) fetchInstallations.delete(target);
|
|
225
257
|
};
|
|
226
258
|
}
|
|
227
259
|
function installXhrInstrumentation(monitor, options = {}) {
|
|
@@ -229,6 +261,11 @@ function installXhrInstrumentation(monitor, options = {}) {
|
|
|
229
261
|
const target = options.target ?? (defaultTarget.XMLHttpRequest ? defaultTarget : void 0);
|
|
230
262
|
if (!target?.XMLHttpRequest) return () => void 0;
|
|
231
263
|
const prototype = target.XMLHttpRequest.prototype;
|
|
264
|
+
const existing = xhrInstallations.get(prototype);
|
|
265
|
+
if (existing) {
|
|
266
|
+
existing.references += 1;
|
|
267
|
+
return releaseXhrInstallation(prototype, existing);
|
|
268
|
+
}
|
|
232
269
|
const originalOpen = prototype.open;
|
|
233
270
|
const originalSend = prototype.send;
|
|
234
271
|
const originalSetRequestHeader = prototype.setRequestHeader;
|
|
@@ -257,27 +294,53 @@ function installXhrInstrumentation(monitor, options = {}) {
|
|
|
257
294
|
}
|
|
258
295
|
}
|
|
259
296
|
let finished = false;
|
|
260
|
-
const finish = () => {
|
|
297
|
+
const finish = (kind, error) => {
|
|
261
298
|
if (finished) return;
|
|
262
299
|
finished = true;
|
|
263
300
|
if (this.status > 0) span.setAttribute("http.status_code", this.status);
|
|
264
|
-
span.end(this.status ===
|
|
301
|
+
span.end(this.status === 200 ? "ok" : "error");
|
|
302
|
+
captureHttpError(
|
|
303
|
+
monitor,
|
|
304
|
+
"http.xhr",
|
|
305
|
+
error,
|
|
306
|
+
createHttpErrorContext(kind, state.method, state.url, this.status),
|
|
307
|
+
options.shouldCaptureHttpError
|
|
308
|
+
);
|
|
265
309
|
};
|
|
266
|
-
this.addEventListener("loadend", finish, { once: true });
|
|
267
|
-
this.addEventListener("error", finish, { once: true });
|
|
268
|
-
this.addEventListener("abort", finish, { once: true });
|
|
310
|
+
this.addEventListener("loadend", () => finish(this.status === 0 ? "network" : "response"), { once: true });
|
|
311
|
+
this.addEventListener("error", () => finish("network"), { once: true });
|
|
312
|
+
this.addEventListener("abort", () => finish("network"), { once: true });
|
|
269
313
|
try {
|
|
270
314
|
return originalSend.apply(this, args);
|
|
271
315
|
} catch (error) {
|
|
272
|
-
finish();
|
|
316
|
+
finish("network", error);
|
|
273
317
|
throw error;
|
|
274
318
|
}
|
|
275
319
|
};
|
|
276
|
-
|
|
277
|
-
|
|
320
|
+
const installedOpen = instrumentedOpen;
|
|
321
|
+
const installedSend = instrumentedSend;
|
|
322
|
+
prototype.open = installedOpen;
|
|
323
|
+
prototype.send = installedSend;
|
|
324
|
+
const installation = {
|
|
325
|
+
instrumentedOpen: installedOpen,
|
|
326
|
+
instrumentedSend: installedSend,
|
|
327
|
+
originalOpen,
|
|
328
|
+
originalSend,
|
|
329
|
+
references: 1
|
|
330
|
+
};
|
|
331
|
+
xhrInstallations.set(prototype, installation);
|
|
332
|
+
return releaseXhrInstallation(prototype, installation);
|
|
333
|
+
}
|
|
334
|
+
function releaseXhrInstallation(prototype, installation) {
|
|
335
|
+
let released = false;
|
|
278
336
|
return () => {
|
|
279
|
-
if (
|
|
280
|
-
|
|
337
|
+
if (released) return;
|
|
338
|
+
released = true;
|
|
339
|
+
installation.references -= 1;
|
|
340
|
+
if (installation.references > 0) return;
|
|
341
|
+
if (prototype.open === installation.instrumentedOpen) prototype.open = installation.originalOpen;
|
|
342
|
+
if (prototype.send === installation.instrumentedSend) prototype.send = installation.originalSend;
|
|
343
|
+
if (xhrInstallations.get(prototype) === installation) xhrInstallations.delete(prototype);
|
|
281
344
|
};
|
|
282
345
|
}
|
|
283
346
|
|
|
@@ -1,3 +1,50 @@
|
|
|
1
|
+
// src/http-error.ts
|
|
2
|
+
var httpInstrumentationErrors = /* @__PURE__ */ new WeakSet();
|
|
3
|
+
function isHttpInstrumentationError(error) {
|
|
4
|
+
return typeof error === "object" && error !== null && httpInstrumentationErrors.has(error);
|
|
5
|
+
}
|
|
6
|
+
function defaultShouldCaptureHttpError(context) {
|
|
7
|
+
return context.kind === "network" || context.status !== 200;
|
|
8
|
+
}
|
|
9
|
+
function createHttpErrorContext(kind, method, url, status) {
|
|
10
|
+
return {
|
|
11
|
+
kind,
|
|
12
|
+
method,
|
|
13
|
+
status,
|
|
14
|
+
...url ? { path: url.pathname.slice(0, 2048) || "/" } : {}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function captureHttpError(monitor, mechanism, error, context, shouldCapture = defaultShouldCaptureHttpError) {
|
|
18
|
+
let accepted = false;
|
|
19
|
+
try {
|
|
20
|
+
accepted = shouldCapture(context);
|
|
21
|
+
} catch {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (!accepted) return;
|
|
25
|
+
const normalizedError = error instanceof Error ? error : new Error(
|
|
26
|
+
context.kind === "response" ? `HTTP \u8BF7\u6C42\u8FD4\u56DE ${context.status}` : "HTTP \u8BF7\u6C42\u53D1\u751F\u7F51\u7EDC\u9519\u8BEF"
|
|
27
|
+
);
|
|
28
|
+
httpInstrumentationErrors.add(normalizedError);
|
|
29
|
+
try {
|
|
30
|
+
monitor.captureException(normalizedError, {
|
|
31
|
+
handled: true,
|
|
32
|
+
mechanism,
|
|
33
|
+
tags: {
|
|
34
|
+
method: context.method,
|
|
35
|
+
status: String(context.status)
|
|
36
|
+
},
|
|
37
|
+
context: {
|
|
38
|
+
request: {
|
|
39
|
+
kind: context.kind,
|
|
40
|
+
...context.path ? { path: context.path } : {}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
} catch {
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
1
48
|
// ../security/dist/redaction.js
|
|
2
49
|
var REDACTED = "[\u5DF2\u8131\u654F]";
|
|
3
50
|
var MAX_STRING_LENGTH = 32768;
|
|
@@ -411,7 +458,7 @@ function traceContextHeaders(context) {
|
|
|
411
458
|
}
|
|
412
459
|
|
|
413
460
|
// src/monitor.ts
|
|
414
|
-
var SDK_VERSION = "1.0.
|
|
461
|
+
var SDK_VERSION = "1.0.2";
|
|
415
462
|
var PROTOCOL_VERSION = "1.0";
|
|
416
463
|
var REVOKED_CREDENTIAL_CODES = /* @__PURE__ */ new Set(["invalid_dsn", "relay_key_revoked", "credential_revoked"]);
|
|
417
464
|
function eventId() {
|
|
@@ -934,14 +981,16 @@ function createMonitorRuntime(options, overrides = {}) {
|
|
|
934
981
|
}
|
|
935
982
|
seenErrors.add(error);
|
|
936
983
|
}
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
984
|
+
if (!isHttpInstrumentationError(error)) {
|
|
985
|
+
const fingerprint = shallowFingerprint(event);
|
|
986
|
+
const seenAt = recentFingerprints.get(fingerprint);
|
|
987
|
+
const now = dependencies.now().getTime();
|
|
988
|
+
if (seenAt !== void 0 && now - seenAt < 2e3) {
|
|
989
|
+
drop("duplicate");
|
|
990
|
+
return true;
|
|
991
|
+
}
|
|
992
|
+
recentFingerprints.set(fingerprint, now);
|
|
943
993
|
}
|
|
944
|
-
recentFingerprints.set(fingerprint, now);
|
|
945
994
|
if (dependencies.random() >= sampleRate) {
|
|
946
995
|
drop("sampled");
|
|
947
996
|
return true;
|
|
@@ -1279,4 +1328,4 @@ function createMonitorRuntime(options, overrides = {}) {
|
|
|
1279
1328
|
return monitor;
|
|
1280
1329
|
}
|
|
1281
1330
|
|
|
1282
|
-
export { FetchTelemetryTransport, SDK_VERSION, clientRedact, createMonitorRuntime, formatTraceParent, parseErrorStack, parseRemoteSdkConfig, parseTelemetryTransportResponse, parseTraceParent, parseTransportResponse, traceContextHeaders };
|
|
1331
|
+
export { FetchTelemetryTransport, SDK_VERSION, captureHttpError, clientRedact, createHttpErrorContext, createMonitorRuntime, defaultShouldCaptureHttpError, formatTraceParent, parseErrorStack, parseRemoteSdkConfig, parseTelemetryTransportResponse, parseTraceParent, parseTransportResponse, traceContextHeaders };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
interface HttpErrorContext {
|
|
2
|
+
kind: "response" | "network";
|
|
3
|
+
method: string;
|
|
4
|
+
status: number;
|
|
5
|
+
path?: string;
|
|
6
|
+
}
|
|
7
|
+
type ShouldCaptureHttpError = (context: HttpErrorContext) => boolean;
|
|
8
|
+
declare function defaultShouldCaptureHttpError(context: HttpErrorContext): boolean;
|
|
9
|
+
|
|
10
|
+
export { type HttpErrorContext as H, type ShouldCaptureHttpError as S, defaultShouldCaptureHttpError as d };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { T as TelemetryTransport, I as IngestConfig, a as TelemetryEnvelope, b as TelemetryTransportOutcome, E as ErrorMonitor, M as MonitorOptions } from './types-hWS-GSV1.js';
|
|
2
2
|
export { B as Breadcrumb, C as CaptureOptions, c as ContextMode, d as MonitorStatus, S as Span, e as SpanOptions, f as TelemetryOptions, g as TraceContext, W as WebVitalInput, h as formatTraceParent, p as parseTraceParent, t as traceContextHeaders } from './types-hWS-GSV1.js';
|
|
3
|
+
import { S as ShouldCaptureHttpError } from './http-error-DTUBVanG.js';
|
|
4
|
+
export { H as HttpErrorContext, d as defaultShouldCaptureHttpError } from './http-error-DTUBVanG.js';
|
|
3
5
|
|
|
4
6
|
declare class FetchTelemetryTransport implements TelemetryTransport {
|
|
5
7
|
private readonly ingest;
|
|
@@ -16,6 +18,7 @@ interface FetchInstrumentationOptions {
|
|
|
16
18
|
target?: FetchInstrumentationTarget;
|
|
17
19
|
shouldTrace?: (input: RequestInfo | URL, init?: RequestInit) => boolean;
|
|
18
20
|
shouldPropagateTraceContext?: (url: URL) => boolean;
|
|
21
|
+
shouldCaptureHttpError?: ShouldCaptureHttpError;
|
|
19
22
|
}
|
|
20
23
|
interface XhrInstrumentationTarget {
|
|
21
24
|
XMLHttpRequest: typeof XMLHttpRequest;
|
|
@@ -24,10 +27,11 @@ interface XhrInstrumentationOptions {
|
|
|
24
27
|
target?: XhrInstrumentationTarget;
|
|
25
28
|
shouldTrace?: (method: string, url: URL | undefined) => boolean;
|
|
26
29
|
shouldPropagateTraceContext?: (url: URL) => boolean;
|
|
30
|
+
shouldCaptureHttpError?: ShouldCaptureHttpError;
|
|
27
31
|
}
|
|
28
32
|
declare function installFetchInstrumentation(monitor: ErrorMonitor, options?: FetchInstrumentationOptions): () => void;
|
|
29
33
|
declare function installXhrInstrumentation(monitor: ErrorMonitor, options?: XhrInstrumentationOptions): () => void;
|
|
30
34
|
|
|
31
35
|
declare function createErrorMonitor(options: MonitorOptions): ErrorMonitor;
|
|
32
36
|
|
|
33
|
-
export { ErrorMonitor, type FetchInstrumentationOptions, type FetchInstrumentationTarget, FetchTelemetryTransport, IngestConfig, MonitorOptions, type XhrInstrumentationOptions, type XhrInstrumentationTarget, createErrorMonitor, installFetchInstrumentation, installXhrInstrumentation };
|
|
37
|
+
export { ErrorMonitor, type FetchInstrumentationOptions, type FetchInstrumentationTarget, FetchTelemetryTransport, IngestConfig, MonitorOptions, ShouldCaptureHttpError, type XhrInstrumentationOptions, type XhrInstrumentationTarget, createErrorMonitor, installFetchInstrumentation, installXhrInstrumentation };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { createErrorMonitor, installFetchInstrumentation, installXhrInstrumentation } from './chunk-
|
|
2
|
-
export { FetchTelemetryTransport, formatTraceParent, parseTraceParent, traceContextHeaders } from './chunk-
|
|
1
|
+
export { createErrorMonitor, installFetchInstrumentation, installXhrInstrumentation } from './chunk-ZEZNKS4A.js';
|
|
2
|
+
export { FetchTelemetryTransport, defaultShouldCaptureHttpError, formatTraceParent, parseTraceParent, traceContextHeaders } from './chunk-ZUSG3UKB.js';
|
package/dist/node/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { P as PersistentEventQueue, i as PersistedQueueItem, E as ErrorMonitor, M as MonitorOptions, T as TelemetryTransport, a as TelemetryEnvelope, b as TelemetryTransportOutcome, j as EventTransport, k as EventEnvelope, l as TransportOutcome, R as RemoteSdkConfig, m as RemoteConfigLoadResult, n as RuntimeDependencies } from '../types-hWS-GSV1.js';
|
|
2
|
+
import { S as ShouldCaptureHttpError } from '../http-error-DTUBVanG.js';
|
|
3
|
+
export { H as HttpErrorContext, d as defaultShouldCaptureHttpError } from '../http-error-DTUBVanG.js';
|
|
2
4
|
import { ClientRequest } from 'node:http';
|
|
3
5
|
|
|
4
6
|
interface NodeQueueEncryptionKey {
|
|
@@ -45,6 +47,7 @@ interface NodeHttpInstrumentationOptions {
|
|
|
45
47
|
modules?: NodeHttpInstrumentationModule[];
|
|
46
48
|
shouldTrace?: (method: string, url: URL | undefined) => boolean;
|
|
47
49
|
shouldPropagateTraceContext?: (url: URL | undefined) => boolean;
|
|
50
|
+
shouldCaptureHttpError?: ShouldCaptureHttpError;
|
|
48
51
|
}
|
|
49
52
|
declare function installNodeHttpInstrumentation(monitor: ErrorMonitor, options?: NodeHttpInstrumentationOptions): () => void;
|
|
50
53
|
|
|
@@ -90,4 +93,4 @@ declare function createNodeErrorMonitor(options: NodeMonitorOptions, overrides?:
|
|
|
90
93
|
transport?: EventTransport;
|
|
91
94
|
} & Partial<RuntimeDependencies>): ErrorMonitor;
|
|
92
95
|
|
|
93
|
-
export { NodeEncryptedFileQueue, type NodeEncryptedFileQueueOptions, type NodeHttpInstrumentationModule, type NodeHttpInstrumentationOptions, type NodeMonitorOptions, type NodeQueueEncryptionKey, type NodeRelayIngestConfig, NodeRelayTelemetryTransport, NodeRelayTransport, type NodeRelayTransportOptions, createNodeErrorMonitor, installNodeHttpInstrumentation };
|
|
96
|
+
export { NodeEncryptedFileQueue, type NodeEncryptedFileQueueOptions, type NodeHttpInstrumentationModule, type NodeHttpInstrumentationOptions, type NodeMonitorOptions, type NodeQueueEncryptionKey, type NodeRelayIngestConfig, NodeRelayTelemetryTransport, NodeRelayTransport, type NodeRelayTransportOptions, ShouldCaptureHttpError, createNodeErrorMonitor, installNodeHttpInstrumentation };
|
package/dist/node/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { parseTransportResponse, parseRemoteSdkConfig, parseTelemetryTransportResponse, createMonitorRuntime } from '../chunk-
|
|
1
|
+
import { parseTransportResponse, parseRemoteSdkConfig, parseTelemetryTransportResponse, createMonitorRuntime, captureHttpError, createHttpErrorContext } from '../chunk-ZUSG3UKB.js';
|
|
2
|
+
export { defaultShouldCaptureHttpError } from '../chunk-ZUSG3UKB.js';
|
|
2
3
|
import { createSignedRelayHeaders } from '../chunk-RXQF7F2E.js';
|
|
3
4
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
4
5
|
import { createDecipheriv, randomBytes, createCipheriv } from 'crypto';
|
|
@@ -216,6 +217,7 @@ var NodeEncryptedFileQueue = class {
|
|
|
216
217
|
}
|
|
217
218
|
}
|
|
218
219
|
};
|
|
220
|
+
var nodeHttpInstallations = /* @__PURE__ */ new WeakMap();
|
|
219
221
|
function builtInModules() {
|
|
220
222
|
const require2 = createRequire(import.meta.url);
|
|
221
223
|
return [
|
|
@@ -267,6 +269,13 @@ function instrumentedArguments(args, headers) {
|
|
|
267
269
|
function installNodeHttpInstrumentation(monitor, options = {}) {
|
|
268
270
|
const restorers = [];
|
|
269
271
|
for (const module of options.modules ?? builtInModules()) {
|
|
272
|
+
const existing = nodeHttpInstallations.get(module);
|
|
273
|
+
if (existing) {
|
|
274
|
+
existing.references += 1;
|
|
275
|
+
restorers.push(releaseNodeHttpInstallation(module, existing));
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
const moduleRestorers = [];
|
|
270
279
|
for (const key of ["request", "get"]) {
|
|
271
280
|
const original = module[key];
|
|
272
281
|
if (typeof original !== "function") continue;
|
|
@@ -292,35 +301,82 @@ function installNodeHttpInstrumentation(monitor, options = {}) {
|
|
|
292
301
|
request = original.apply(module, instrumentedArguments(args, headers));
|
|
293
302
|
} catch (error) {
|
|
294
303
|
span.end("error");
|
|
304
|
+
captureHttpError(
|
|
305
|
+
monitor,
|
|
306
|
+
"http.node",
|
|
307
|
+
error,
|
|
308
|
+
createHttpErrorContext("network", method, url, 0),
|
|
309
|
+
options.shouldCaptureHttpError
|
|
310
|
+
);
|
|
295
311
|
throw error;
|
|
296
312
|
}
|
|
297
|
-
let
|
|
298
|
-
const
|
|
299
|
-
if (
|
|
300
|
-
|
|
313
|
+
let spanFinished = false;
|
|
314
|
+
const finishSpan = (status, response) => {
|
|
315
|
+
if (spanFinished) return false;
|
|
316
|
+
spanFinished = true;
|
|
301
317
|
if (response?.statusCode) span.setAttribute("http.status_code", response.statusCode);
|
|
302
318
|
span.end(status);
|
|
319
|
+
return true;
|
|
320
|
+
};
|
|
321
|
+
let networkCaptured = false;
|
|
322
|
+
const captureNetwork = (error, response) => {
|
|
323
|
+
if (networkCaptured) return;
|
|
324
|
+
networkCaptured = true;
|
|
325
|
+
finishSpan("error", response);
|
|
326
|
+
captureHttpError(
|
|
327
|
+
monitor,
|
|
328
|
+
"http.node",
|
|
329
|
+
error,
|
|
330
|
+
createHttpErrorContext("network", method, url, response?.statusCode ?? 0),
|
|
331
|
+
options.shouldCaptureHttpError
|
|
332
|
+
);
|
|
303
333
|
};
|
|
304
334
|
request.once("response", (response) => {
|
|
305
335
|
const status = response.statusCode ?? 0;
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
336
|
+
finishSpan(status === 200 ? "ok" : "error", response);
|
|
337
|
+
captureHttpError(
|
|
338
|
+
monitor,
|
|
339
|
+
"http.node",
|
|
340
|
+
void 0,
|
|
341
|
+
createHttpErrorContext("response", method, url, status),
|
|
342
|
+
options.shouldCaptureHttpError
|
|
343
|
+
);
|
|
344
|
+
response.once("aborted", () => captureNetwork(void 0, response));
|
|
345
|
+
response.once("error", (error) => captureNetwork(error, response));
|
|
309
346
|
});
|
|
310
|
-
request.once("error", () =>
|
|
311
|
-
request.once("abort", () =>
|
|
347
|
+
request.once("error", (error) => captureNetwork(error));
|
|
348
|
+
request.once("abort", () => captureNetwork());
|
|
312
349
|
return request;
|
|
313
350
|
};
|
|
314
351
|
module[key] = instrumented;
|
|
315
|
-
|
|
352
|
+
moduleRestorers.push(() => {
|
|
316
353
|
if (module[key] === instrumented) module[key] = original;
|
|
317
354
|
});
|
|
318
355
|
}
|
|
356
|
+
const installation = {
|
|
357
|
+
references: 1,
|
|
358
|
+
restore() {
|
|
359
|
+
for (const restore of moduleRestorers.reverse()) restore();
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
nodeHttpInstallations.set(module, installation);
|
|
363
|
+
restorers.push(releaseNodeHttpInstallation(module, installation));
|
|
319
364
|
}
|
|
320
365
|
return () => {
|
|
321
366
|
for (const restore of restorers.reverse()) restore();
|
|
322
367
|
};
|
|
323
368
|
}
|
|
369
|
+
function releaseNodeHttpInstallation(module, installation) {
|
|
370
|
+
let released = false;
|
|
371
|
+
return () => {
|
|
372
|
+
if (released) return;
|
|
373
|
+
released = true;
|
|
374
|
+
installation.references -= 1;
|
|
375
|
+
if (installation.references > 0) return;
|
|
376
|
+
installation.restore();
|
|
377
|
+
if (nodeHttpInstallations.get(module) === installation) nodeHttpInstallations.delete(module);
|
|
378
|
+
};
|
|
379
|
+
}
|
|
324
380
|
|
|
325
381
|
// src/node/index.ts
|
|
326
382
|
function delay(timeoutMs) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { clientRedact, SDK_VERSION, parseErrorStack } from '../../chunk-
|
|
1
|
+
import { clientRedact, SDK_VERSION, parseErrorStack } from '../../chunk-ZUSG3UKB.js';
|
|
2
2
|
import { createSignedRelayHeaders } from '../../chunk-RXQF7F2E.js';
|
|
3
3
|
import { randomUUID } from 'crypto';
|
|
4
4
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createErrorMonitor } from '../../chunk-
|
|
1
|
+
import { createErrorMonitor } from '../../chunk-ZEZNKS4A.js';
|
|
2
2
|
import { installVueErrorMonitor } from '../../chunk-P6Q63P6L.js';
|
|
3
|
-
import '../../chunk-
|
|
3
|
+
import '../../chunk-ZUSG3UKB.js';
|
|
4
4
|
import { defineNuxtPlugin, useRuntimeConfig } from '#app';
|
|
5
5
|
|
|
6
6
|
var plugin_default = defineNuxtPlugin({
|
package/dist/react/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createErrorMonitor } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
1
|
+
import { createErrorMonitor } from '../chunk-ZEZNKS4A.js';
|
|
2
|
+
import '../chunk-ZUSG3UKB.js';
|
|
3
3
|
import { Component, createElement } from 'react';
|
|
4
4
|
|
|
5
5
|
function createReactErrorMonitor(options) {
|
package/dist/testing/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devkitio/faultlens",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "FaultLens 的 Browser、Node、Vue、Nuxt、React 与 Web 框架错误采集 SDK",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"private": false,
|
|
@@ -59,6 +59,11 @@
|
|
|
59
59
|
"registry": "https://registry.npmjs.org/",
|
|
60
60
|
"access": "public"
|
|
61
61
|
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"build": "tsup",
|
|
64
|
+
"check": "tsc -p tsconfig.json --noEmit",
|
|
65
|
+
"prepack": "pnpm build"
|
|
66
|
+
},
|
|
62
67
|
"peerDependencies": {
|
|
63
68
|
"@nuxt/kit": ">=4.1.0 <5",
|
|
64
69
|
"@nuxt/schema": ">=4.1.0 <5",
|
|
@@ -92,20 +97,16 @@
|
|
|
92
97
|
}
|
|
93
98
|
},
|
|
94
99
|
"devDependencies": {
|
|
100
|
+
"@faultlens/security": "workspace:*",
|
|
95
101
|
"@nuxt/kit": "4.1.0",
|
|
96
102
|
"@nuxt/schema": "4.1.0",
|
|
97
103
|
"@types/react": "19.1.11",
|
|
98
104
|
"h3": "1.15.9",
|
|
99
105
|
"react": "19.1.1",
|
|
100
106
|
"tsup": "8.5.0",
|
|
101
|
-
"vue": "3.5.20"
|
|
102
|
-
"@faultlens/security": "1.0.1"
|
|
107
|
+
"vue": "3.5.20"
|
|
103
108
|
},
|
|
104
109
|
"dependencies": {
|
|
105
110
|
"web-vitals": "6.2.0"
|
|
106
|
-
},
|
|
107
|
-
"scripts": {
|
|
108
|
-
"build": "tsup",
|
|
109
|
-
"check": "tsc -p tsconfig.json --noEmit"
|
|
110
111
|
}
|
|
111
|
-
}
|
|
112
|
+
}
|