@oconde/radar 0.3.0 → 0.4.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/CHANGELOG.md +23 -0
- package/README.md +14 -1
- package/dist/{client-BB-to8cr.d.cts → client-DRZ7htMJ.d.cts} +16 -2
- package/dist/{client-BS798K3S.d.ts → client-FkXWx8sJ.d.ts} +16 -2
- package/dist/index.cjs +49 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +49 -15
- package/dist/index.js.map +1 -1
- package/dist/nest/index.cjs +49 -15
- package/dist/nest/index.cjs.map +1 -1
- package/dist/nest/index.d.cts +1 -1
- package/dist/nest/index.d.ts +1 -1
- package/dist/nest/index.js +49 -15
- package/dist/nest/index.js.map +1 -1
- package/dist/sveltekit/index.cjs +56 -16
- package/dist/sveltekit/index.cjs.map +1 -1
- package/dist/sveltekit/index.d.cts +1 -1
- package/dist/sveltekit/index.d.ts +1 -1
- package/dist/sveltekit/index.js +56 -16
- package/dist/sveltekit/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RequestEvent, RequestHandler, Handle, HandleServerError } from '@sveltejs/kit';
|
|
2
|
-
import { R as RadarClient } from '../client-
|
|
2
|
+
import { R as RadarClient } from '../client-DRZ7htMJ.cjs';
|
|
3
3
|
import '../protocol/index.cjs';
|
|
4
4
|
|
|
5
5
|
declare function moveClientSourceMaps(buildDir?: string): number;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RequestEvent, RequestHandler, Handle, HandleServerError } from '@sveltejs/kit';
|
|
2
|
-
import { R as RadarClient } from '../client-
|
|
2
|
+
import { R as RadarClient } from '../client-FkXWx8sJ.js';
|
|
3
3
|
import '../protocol/index.js';
|
|
4
4
|
|
|
5
5
|
declare function moveClientSourceMaps(buildDir?: string): number;
|
package/dist/sveltekit/index.js
CHANGED
|
@@ -258,6 +258,12 @@ function requestPath(req) {
|
|
|
258
258
|
const end = url.indexOf("?");
|
|
259
259
|
return end >= 0 ? url.slice(0, end) : url;
|
|
260
260
|
}
|
|
261
|
+
function matchesRequest(pattern, path, route) {
|
|
262
|
+
const candidates = route === void 0 ? [path] : [path, route];
|
|
263
|
+
if (pattern instanceof RegExp) return candidates.some((value) => value.search(pattern) !== -1);
|
|
264
|
+
const prefix = pattern.endsWith("/") ? pattern : `${pattern}/`;
|
|
265
|
+
return candidates.some((value) => value === pattern || value.startsWith(prefix));
|
|
266
|
+
}
|
|
261
267
|
function requestRoute(req, route) {
|
|
262
268
|
if (route) return route;
|
|
263
269
|
if (typeof req.route?.path !== "string") return void 0;
|
|
@@ -397,11 +403,24 @@ function createMiddleware(logger) {
|
|
|
397
403
|
// src/options.ts
|
|
398
404
|
var DEFAULT_ENDPOINT = "https://radar-ingest.oconde.dev";
|
|
399
405
|
var LEVELS = ["debug", "info", "warn", "error"];
|
|
406
|
+
function patterns(value) {
|
|
407
|
+
if (!Array.isArray(value)) return [];
|
|
408
|
+
return value.flatMap((item) => {
|
|
409
|
+
if (item instanceof RegExp) return [item];
|
|
410
|
+
if (typeof item === "string" && item.trim() !== "") return [item.trim()];
|
|
411
|
+
return [];
|
|
412
|
+
});
|
|
413
|
+
}
|
|
400
414
|
function resolveTraceFetch(value) {
|
|
401
|
-
if (!value) return { enabled: false, propagateTo: [] };
|
|
402
|
-
if (value === true) return { enabled: true, propagateTo: [] };
|
|
403
|
-
|
|
404
|
-
|
|
415
|
+
if (!value) return { enabled: false, propagateTo: [], ignore: [] };
|
|
416
|
+
if (value === true) return { enabled: true, propagateTo: [], ignore: [] };
|
|
417
|
+
return { enabled: true, propagateTo: patterns(value.propagateTo), ignore: patterns(value.ignore) };
|
|
418
|
+
}
|
|
419
|
+
function resolveLogRequests(value) {
|
|
420
|
+
if (value === false) return { enabled: false, include: [], exclude: [], sample: 1 };
|
|
421
|
+
if (value === void 0 || value === true || typeof value !== "object" || value === null) return { enabled: true, include: [], exclude: [], sample: 1 };
|
|
422
|
+
const sample = typeof value.sample === "number" && Number.isFinite(value.sample) && value.sample >= 0 && value.sample <= 1 ? value.sample : 1;
|
|
423
|
+
return { enabled: true, include: patterns(value.include), exclude: patterns(value.exclude), sample };
|
|
405
424
|
}
|
|
406
425
|
function resolveOptions(options = {}, env = process.env) {
|
|
407
426
|
const key = options.key?.trim() || void 0;
|
|
@@ -415,7 +434,7 @@ function resolveOptions(options = {}, env = process.env) {
|
|
|
415
434
|
minLevel: options.minLevel && LEVELS.includes(options.minLevel) ? options.minLevel : "info",
|
|
416
435
|
redact: options.redact === "none" ? "none" : "mask",
|
|
417
436
|
requestDetail: options.requestDetail === "route" ? "route" : "full",
|
|
418
|
-
logRequests: options.logRequests
|
|
437
|
+
logRequests: resolveLogRequests(options.logRequests),
|
|
419
438
|
ignorePaths: options.ignorePaths ?? ["/healthz", "/health"],
|
|
420
439
|
captureUnhandled: options.captureUnhandled ?? true,
|
|
421
440
|
traceFetch: resolveTraceFetch(options.traceFetch),
|
|
@@ -569,8 +588,8 @@ function headerOf(code, index, prefix) {
|
|
|
569
588
|
return header;
|
|
570
589
|
}
|
|
571
590
|
function nameIn(header) {
|
|
572
|
-
const
|
|
573
|
-
for (const pattern of
|
|
591
|
+
const patterns2 = ANONYMOUS_FUNCTION.test(header) ? NAME_PATTERNS : [...NAME_PATTERNS, METHOD_PATTERN];
|
|
592
|
+
for (const pattern of patterns2) {
|
|
574
593
|
const name = pattern.exec(header)?.[1];
|
|
575
594
|
if (name && !KEYWORDS.has(name)) return name.slice(0, MAX_NAME_LENGTH);
|
|
576
595
|
}
|
|
@@ -913,12 +932,19 @@ function originOf(value) {
|
|
|
913
932
|
return null;
|
|
914
933
|
}
|
|
915
934
|
}
|
|
916
|
-
function
|
|
917
|
-
|
|
918
|
-
const wanted = target.trim().toLowerCase();
|
|
935
|
+
function hostMatches(url, host) {
|
|
936
|
+
const wanted = host.trim().toLowerCase();
|
|
919
937
|
if (wanted.startsWith(".")) return url.hostname.toLowerCase().endsWith(wanted);
|
|
920
938
|
return url.host.toLowerCase() === wanted || url.hostname.toLowerCase() === wanted;
|
|
921
939
|
}
|
|
940
|
+
function targets(url, target) {
|
|
941
|
+
if (target instanceof RegExp) return url.host.search(target) !== -1;
|
|
942
|
+
return hostMatches(url, target);
|
|
943
|
+
}
|
|
944
|
+
function ignored(url, target) {
|
|
945
|
+
if (target instanceof RegExp) return `${url.host}${url.pathname}`.search(target) !== -1;
|
|
946
|
+
return hostMatches(url, target);
|
|
947
|
+
}
|
|
922
948
|
function isPlainObject(value) {
|
|
923
949
|
if (value === null || typeof value !== "object") return false;
|
|
924
950
|
const prototype = Object.getPrototypeOf(value);
|
|
@@ -942,6 +968,7 @@ function traceFetch(config) {
|
|
|
942
968
|
const method = (init?.method ?? (input instanceof Request ? input.method : "GET")).toUpperCase();
|
|
943
969
|
const context = currentContext();
|
|
944
970
|
const [nextInput, nextInit] = context && config.propagateTo.some((target) => targets(url, target)) ? withRequestId(input, init, context.requestId) : [input, init];
|
|
971
|
+
if (config.ignore?.some((target) => ignored(url, target))) return original(nextInput, nextInit);
|
|
945
972
|
const attrs = { method, host: url.host, path: outboundPath(url.pathname, config.redact) };
|
|
946
973
|
const started = performance.now();
|
|
947
974
|
try {
|
|
@@ -1190,7 +1217,7 @@ function withTimeout(promise, ms) {
|
|
|
1190
1217
|
|
|
1191
1218
|
// src/version.ts
|
|
1192
1219
|
var SDK_NAME = "@oconde/radar";
|
|
1193
|
-
var SDK_VERSION = true ? "0.
|
|
1220
|
+
var SDK_VERSION = true ? "0.4.2" : "0.0.0-dev";
|
|
1194
1221
|
|
|
1195
1222
|
// src/client.ts
|
|
1196
1223
|
var MAX_CHECK_IN_DURATION_MS = 7 * 864e5;
|
|
@@ -1234,6 +1261,7 @@ var RadarClient = class {
|
|
|
1234
1261
|
this.restoreFetch = traceFetch({
|
|
1235
1262
|
endpoint: this.options.endpoint,
|
|
1236
1263
|
propagateTo: this.options.traceFetch.propagateTo,
|
|
1264
|
+
ignore: this.options.traceFetch.ignore,
|
|
1237
1265
|
redact: this.options.redact,
|
|
1238
1266
|
record: (level, attrs) => this.safely(() => this.emitLog(level, "http.client", attrs))
|
|
1239
1267
|
});
|
|
@@ -1344,22 +1372,28 @@ var RadarClient = class {
|
|
|
1344
1372
|
return createMiddleware(this);
|
|
1345
1373
|
}
|
|
1346
1374
|
shouldLogRequest(req) {
|
|
1347
|
-
return this.options.logRequests && !this.options.ignorePaths.includes(requestPath(req));
|
|
1375
|
+
return this.options.logRequests.enabled && !this.options.ignorePaths.includes(requestPath(req));
|
|
1348
1376
|
}
|
|
1349
1377
|
logHttpRequest(context, status) {
|
|
1350
1378
|
this.safely(() => {
|
|
1351
1379
|
const req = context.req;
|
|
1352
1380
|
if (!req) return;
|
|
1353
|
-
const level = status >= 500 ? "error" : status >= 400 ? "warn" : "info";
|
|
1354
1381
|
const route = requestRoute(req, context.route);
|
|
1382
|
+
const path = requestPath(req);
|
|
1383
|
+
const { include, exclude, sample } = this.options.logRequests;
|
|
1384
|
+
if (include.length > 0 && !include.some((pattern) => matchesRequest(pattern, path, route))) return;
|
|
1385
|
+
if (exclude.some((pattern) => matchesRequest(pattern, path, route))) return;
|
|
1386
|
+
if (sample < 1 && Math.random() >= sample) return;
|
|
1387
|
+
const level = status >= 500 ? "error" : status >= 400 ? "warn" : "info";
|
|
1355
1388
|
runWithContext(
|
|
1356
1389
|
context,
|
|
1357
1390
|
() => this.emitLog(level, "http.request", {
|
|
1358
1391
|
method: (req.method ?? "GET").toUpperCase(),
|
|
1359
1392
|
...route ? { route } : {},
|
|
1360
|
-
...this.options.requestDetail === "full" ? { path: redactPath(
|
|
1393
|
+
...this.options.requestDetail === "full" ? { path: redactPath(path, pathParams(req, path), this.options.redact) } : {},
|
|
1361
1394
|
status,
|
|
1362
|
-
durationMs: elapsedSince(context.startedAt)
|
|
1395
|
+
durationMs: elapsedSince(context.startedAt),
|
|
1396
|
+
...sample < 1 ? { sampleRate: sample } : {}
|
|
1363
1397
|
})
|
|
1364
1398
|
);
|
|
1365
1399
|
});
|
|
@@ -1773,6 +1807,12 @@ function withRequestId2(response, requestId) {
|
|
|
1773
1807
|
}
|
|
1774
1808
|
}
|
|
1775
1809
|
}
|
|
1810
|
+
function thrownStatus(error) {
|
|
1811
|
+
if (typeof error !== "object" || error === null) return 500;
|
|
1812
|
+
const status = error.status;
|
|
1813
|
+
const fromKit = "location" in error || "body" in error;
|
|
1814
|
+
return fromKit && typeof status === "number" && Number.isInteger(status) && status >= 300 && status <= 599 ? status : 500;
|
|
1815
|
+
}
|
|
1776
1816
|
function radarHandle(options = {}) {
|
|
1777
1817
|
const client = options.client ?? radar;
|
|
1778
1818
|
return async ({ event, resolve: resolveEvent }) => {
|
|
@@ -1788,7 +1828,7 @@ function radarHandle(options = {}) {
|
|
|
1788
1828
|
try {
|
|
1789
1829
|
response = await resolveEvent(event);
|
|
1790
1830
|
} catch (error) {
|
|
1791
|
-
if (client.shouldLogRequest(req)) client.logHttpRequest(context,
|
|
1831
|
+
if (client.shouldLogRequest(req)) client.logHttpRequest(context, thrownStatus(error));
|
|
1792
1832
|
throw error;
|
|
1793
1833
|
}
|
|
1794
1834
|
const tagged = withRequestId2(response, context.requestId);
|