@vouchington/utils 0.7.1 → 0.7.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.
|
@@ -46,9 +46,7 @@ export function scrubSpanUrlAttributes(data, options = {}) {
|
|
|
46
46
|
return transformRecord(data, (key, value) => {
|
|
47
47
|
if (URL_COMPONENT_ATTRIBUTE_KEYS.includes(key))
|
|
48
48
|
return DROP;
|
|
49
|
-
return URL_ATTRIBUTE_KEYS.includes(key)
|
|
50
|
-
? scrubUrl(value, options)
|
|
51
|
-
: value;
|
|
49
|
+
return URL_ATTRIBUTE_KEYS.includes(key) ? scrubUrlValue(value, options) : value;
|
|
52
50
|
});
|
|
53
51
|
}
|
|
54
52
|
/** Scrub the `referer`/`referrer` header values of a headers record. */
|
package/dist/observability.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { SENSITIVE_VALUE } from './observability-records.mts';
|
|
2
|
-
export { createSpikeWindowTracker, type SpikeWindowTracker } from './spike-window.mts';
|
|
2
|
+
export { createSpikeWindowTracker, DEFAULT_MAX_SPIKE_FINGERPRINTS, type SpikeWindowTracker, } from './spike-window.mts';
|
|
3
3
|
export { composeBeforeSend, scrubBreadcrumbs, scrubEvent, scrubHeaders, scrubRequest, scrubSpanAttributes, type ObservableEvent, type ScrubOptions, } from './observability-event.mts';
|
|
4
4
|
export { scrubCredentialHeaders, scrubRequestCredentialFields, scrubSpanCredentialAttributes, } from './observability-credentials.mts';
|
|
5
5
|
export { SCRUBBED_URL_ATTRIBUTE_KEYS, URL_ATTRIBUTE_KEYS, URL_COMPONENT_ATTRIBUTE_KEYS, scrubHeaderUrls, scrubRequestUrlFields, scrubSpanUrlAttributes, scrubUrlValue, stripUrlQueryAndFragment, type UrlScrubOptions, } from './observability-url.mts';
|
package/dist/observability.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { SENSITIVE_VALUE } from './observability-records.mjs';
|
|
2
|
-
export { createSpikeWindowTracker } from './spike-window.mjs';
|
|
2
|
+
export { createSpikeWindowTracker, DEFAULT_MAX_SPIKE_FINGERPRINTS, } from './spike-window.mjs';
|
|
3
3
|
export { composeBeforeSend, scrubBreadcrumbs, scrubEvent, scrubHeaders, scrubRequest, scrubSpanAttributes, } from './observability-event.mjs';
|
|
4
4
|
export { scrubCredentialHeaders, scrubRequestCredentialFields, scrubSpanCredentialAttributes, } from './observability-credentials.mjs';
|
|
5
5
|
export { SCRUBBED_URL_ATTRIBUTE_KEYS, URL_ATTRIBUTE_KEYS, URL_COMPONENT_ATTRIBUTE_KEYS, scrubHeaderUrls, scrubRequestUrlFields, scrubSpanUrlAttributes, scrubUrlValue, stripUrlQueryAndFragment, } from './observability-url.mjs';
|
package/dist/spike-window.d.mts
CHANGED
|
@@ -2,5 +2,10 @@ export interface SpikeWindowTracker {
|
|
|
2
2
|
readonly size: number;
|
|
3
3
|
recordAndCheck(fingerprint: string, timestamp: number): boolean;
|
|
4
4
|
}
|
|
5
|
-
/**
|
|
6
|
-
export declare
|
|
5
|
+
/** Default cap on distinct fingerprints tracked at once. */
|
|
6
|
+
export declare const DEFAULT_MAX_SPIKE_FINGERPRINTS = 1000;
|
|
7
|
+
/**
|
|
8
|
+
* Tracks per-fingerprint occurrence counts while evicting expired windows. At most
|
|
9
|
+
* `maxFingerprints` distinct fingerprints are kept; the least recently seen is evicted first.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createSpikeWindowTracker(limit: number, windowMs: number, maxFingerprints?: number): SpikeWindowTracker;
|
package/dist/spike-window.mjs
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
/**
|
|
2
|
-
export
|
|
1
|
+
/** Default cap on distinct fingerprints tracked at once. */
|
|
2
|
+
export const DEFAULT_MAX_SPIKE_FINGERPRINTS = 1000;
|
|
3
|
+
/**
|
|
4
|
+
* Tracks per-fingerprint occurrence counts while evicting expired windows. At most
|
|
5
|
+
* `maxFingerprints` distinct fingerprints are kept; the least recently seen is evicted first.
|
|
6
|
+
*/
|
|
7
|
+
export function createSpikeWindowTracker(limit, windowMs, maxFingerprints = DEFAULT_MAX_SPIKE_FINGERPRINTS) {
|
|
3
8
|
if (!Number.isSafeInteger(limit) || limit < 0)
|
|
4
9
|
throw new RangeError('limit must be a non-negative safe integer');
|
|
5
10
|
if (!Number.isFinite(windowMs) || windowMs <= 0)
|
|
6
11
|
throw new RangeError('windowMs must be positive and finite');
|
|
12
|
+
if (!Number.isSafeInteger(maxFingerprints) || maxFingerprints < 1)
|
|
13
|
+
throw new RangeError('maxFingerprints must be a positive safe integer');
|
|
7
14
|
const windows = new Map();
|
|
8
15
|
let lastSweepAt = -Infinity;
|
|
9
16
|
let lastTimestamp = -Infinity;
|
|
@@ -34,7 +41,14 @@ export function createSpikeWindowTracker(limit, windowMs) {
|
|
|
34
41
|
? existing
|
|
35
42
|
: { count: 0, windowStart: timestamp };
|
|
36
43
|
window.count += 1;
|
|
44
|
+
windows.delete(fingerprint);
|
|
37
45
|
windows.set(fingerprint, window);
|
|
46
|
+
if (windows.size > maxFingerprints) {
|
|
47
|
+
for (const oldest of windows.keys()) {
|
|
48
|
+
windows.delete(oldest);
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
38
52
|
return window.count <= limit;
|
|
39
53
|
},
|
|
40
54
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vouchington/utils",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"description": "Dependency-free runtime utilities for Vouchington-style applications.",
|
|
5
5
|
"homepage": "https://github.com/vouchington/vouchington-platform/tree/main/packages/utils#readme",
|
|
6
6
|
"bugs": {
|