@loggerjs/processors 0.0.2 → 0.3.0
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/README.md +68 -30
- package/dist/coalesce.d.ts +10 -0
- package/dist/coalesce.d.ts.map +1 -0
- package/dist/index.cjs +123 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +120 -7
- package/dist/index.js.map +1 -1
- package/dist/redact.d.ts +2 -0
- package/dist/redact.d.ts.map +1 -1
- package/dist/symbolicate-stack.d.ts +15 -0
- package/dist/symbolicate-stack.d.ts.map +1 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -3,7 +3,12 @@ import { createBoundContext, createMiddleware, eventToRecord, incrementLoggerMet
|
|
|
3
3
|
function matchesKey(key, path, value, matchers) {
|
|
4
4
|
return matchers.some((matcher) => {
|
|
5
5
|
if (typeof matcher === "string") return matcher.toLowerCase() === key.toLowerCase();
|
|
6
|
-
if (matcher instanceof RegExp)
|
|
6
|
+
if (matcher instanceof RegExp) {
|
|
7
|
+
matcher.lastIndex = 0;
|
|
8
|
+
const keyMatches = matcher.test(key);
|
|
9
|
+
matcher.lastIndex = 0;
|
|
10
|
+
return keyMatches || matcher.test(path);
|
|
11
|
+
}
|
|
7
12
|
return matcher(key, path, value);
|
|
8
13
|
});
|
|
9
14
|
}
|
|
@@ -28,8 +33,10 @@ function redactValue(value, options, path = "", depth = 0, seen = /* @__PURE__ *
|
|
|
28
33
|
seen.set(value, out);
|
|
29
34
|
for (const [key, child] of Object.entries(input)) {
|
|
30
35
|
const childPath = path ? `${path}.${key}` : key;
|
|
31
|
-
if (matchesKey(key, childPath, child, options.keys ?? []) || pathMatches(childPath, options.paths ?? []))
|
|
32
|
-
|
|
36
|
+
if (matchesKey(key, childPath, child, options.keys ?? []) || pathMatches(childPath, options.paths ?? [])) {
|
|
37
|
+
if (options.remove) continue;
|
|
38
|
+
out[key] = options.replacement;
|
|
39
|
+
} else out[key] = redactValue(child, options, childPath, depth + 1, seen);
|
|
33
40
|
}
|
|
34
41
|
return out;
|
|
35
42
|
}
|
|
@@ -47,7 +54,8 @@ function redactProcessor(options = {}) {
|
|
|
47
54
|
"api_key"
|
|
48
55
|
],
|
|
49
56
|
paths: options.paths ?? [],
|
|
50
|
-
replacement: options.replacement ?? "[REDACTED]",
|
|
57
|
+
replacement: options.replacement ?? options.censor ?? "[REDACTED]",
|
|
58
|
+
remove: options.remove ?? false,
|
|
51
59
|
maxDepth: options.maxDepth ?? 8
|
|
52
60
|
};
|
|
53
61
|
return (event) => ({
|
|
@@ -126,6 +134,58 @@ function contextProcessor(context) {
|
|
|
126
134
|
});
|
|
127
135
|
}
|
|
128
136
|
//#endregion
|
|
137
|
+
//#region src/coalesce.ts
|
|
138
|
+
function attachCoalesced(event, field, key, state, updateMessage) {
|
|
139
|
+
if (state.count <= 1) return event;
|
|
140
|
+
const payload = {
|
|
141
|
+
key,
|
|
142
|
+
count: state.count,
|
|
143
|
+
firstSeen: state.firstSeen,
|
|
144
|
+
lastSeen: state.lastSeen
|
|
145
|
+
};
|
|
146
|
+
return {
|
|
147
|
+
...event,
|
|
148
|
+
message: updateMessage ? `${event.message} (x${state.count})` : event.message,
|
|
149
|
+
data: event.data && typeof event.data === "object" && !Array.isArray(event.data) ? {
|
|
150
|
+
...event.data,
|
|
151
|
+
[field]: payload
|
|
152
|
+
} : {
|
|
153
|
+
value: event.data,
|
|
154
|
+
[field]: payload
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
function coalesceProcessor(options = {}) {
|
|
159
|
+
const windowMs = options.windowMs ?? 1e3;
|
|
160
|
+
const maxEntries = options.maxEntries ?? 1e3;
|
|
161
|
+
const field = options.field ?? "coalesced";
|
|
162
|
+
const updateMessage = options.updateMessage ?? true;
|
|
163
|
+
const keyFor = options.key ?? ((event) => `${event.levelName}:${event.message}:${event.error?.message ?? ""}`);
|
|
164
|
+
const seen = /* @__PURE__ */ new Map();
|
|
165
|
+
return (event, context) => {
|
|
166
|
+
const now = context.now();
|
|
167
|
+
const key = keyFor(event);
|
|
168
|
+
const previous = seen.get(key);
|
|
169
|
+
if (previous && now - previous.lastSeen < windowMs) {
|
|
170
|
+
previous.count += 1;
|
|
171
|
+
previous.lastSeen = now;
|
|
172
|
+
incrementLoggerMetaCounter("processor.coalesce.suppressed");
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
const next = {
|
|
176
|
+
firstSeen: now,
|
|
177
|
+
lastSeen: now,
|
|
178
|
+
count: 1
|
|
179
|
+
};
|
|
180
|
+
seen.set(key, next);
|
|
181
|
+
if (seen.size > maxEntries) {
|
|
182
|
+
const cutoff = now - windowMs;
|
|
183
|
+
for (const [entryKey, state] of seen) if (state.lastSeen < cutoff || seen.size > maxEntries) seen.delete(entryKey);
|
|
184
|
+
}
|
|
185
|
+
return previous ? attachCoalesced(event, field, key, previous, updateMessage) : event;
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
//#endregion
|
|
129
189
|
//#region src/dedupe.ts
|
|
130
190
|
function dedupeProcessor(options = {}) {
|
|
131
191
|
const windowMs = options.windowMs ?? 1e3;
|
|
@@ -824,7 +884,7 @@ function normalizeFrames(frames, options) {
|
|
|
824
884
|
}
|
|
825
885
|
return out;
|
|
826
886
|
}
|
|
827
|
-
function writeFrames(event, options, frames) {
|
|
887
|
+
function writeFrames$1(event, options, frames) {
|
|
828
888
|
if (options.target === "context") return {
|
|
829
889
|
...event,
|
|
830
890
|
context: {
|
|
@@ -857,7 +917,60 @@ function stackParserProcessor(options = {}) {
|
|
|
857
917
|
const stack = event.error?.stack;
|
|
858
918
|
if (!stack || normalized.maxFrames === 0) return event;
|
|
859
919
|
const frames = normalizeFrames(normalized.parser(stack), normalized);
|
|
860
|
-
return frames.length > 0 ? writeFrames(event, normalized, frames) : event;
|
|
920
|
+
return frames.length > 0 ? writeFrames$1(event, normalized, frames) : event;
|
|
921
|
+
};
|
|
922
|
+
}
|
|
923
|
+
//#endregion
|
|
924
|
+
//#region src/symbolicate-stack.ts
|
|
925
|
+
function frameListFromEvent(event, sourceKey) {
|
|
926
|
+
const existing = event.error?.[sourceKey];
|
|
927
|
+
if (Array.isArray(existing)) return existing;
|
|
928
|
+
const stack = event.error?.stack;
|
|
929
|
+
return stack ? parseStack(stack) : [];
|
|
930
|
+
}
|
|
931
|
+
function applySymbolication(frame, event, options) {
|
|
932
|
+
const original = options.symbolicate(frame, event);
|
|
933
|
+
if (!original) return frame;
|
|
934
|
+
if (options.mode === "replace") return {
|
|
935
|
+
...original,
|
|
936
|
+
raw: frame.raw
|
|
937
|
+
};
|
|
938
|
+
return {
|
|
939
|
+
...frame,
|
|
940
|
+
original
|
|
941
|
+
};
|
|
942
|
+
}
|
|
943
|
+
function writeFrames(event, target, key, frames) {
|
|
944
|
+
if (target === "context") return {
|
|
945
|
+
...event,
|
|
946
|
+
context: {
|
|
947
|
+
...event.context,
|
|
948
|
+
[key]: frames
|
|
949
|
+
}
|
|
950
|
+
};
|
|
951
|
+
return {
|
|
952
|
+
...event,
|
|
953
|
+
error: {
|
|
954
|
+
message: event.error?.message ?? event.message,
|
|
955
|
+
...event.error,
|
|
956
|
+
[key]: frames
|
|
957
|
+
}
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
function symbolicateStackProcessor(options) {
|
|
961
|
+
const maxFrames = Math.max(0, Math.floor(options.maxFrames ?? 20));
|
|
962
|
+
const sourceKey = options.sourceKey ?? "frames";
|
|
963
|
+
const target = options.target ?? "error";
|
|
964
|
+
const key = options.key ?? "symbolicatedFrames";
|
|
965
|
+
const mode = options.mode ?? "annotate";
|
|
966
|
+
return (event) => {
|
|
967
|
+
if (maxFrames === 0) return event;
|
|
968
|
+
const frames = frameListFromEvent(event, sourceKey).slice(0, maxFrames);
|
|
969
|
+
if (frames.length === 0) return event;
|
|
970
|
+
return writeFrames(event, target, key, frames.map((frame) => applySymbolication(frame, event, {
|
|
971
|
+
mode,
|
|
972
|
+
symbolicate: options.symbolicate
|
|
973
|
+
})));
|
|
861
974
|
};
|
|
862
975
|
}
|
|
863
976
|
//#endregion
|
|
@@ -1323,6 +1436,6 @@ function breadcrumbBufferProcessor(options = {}) {
|
|
|
1323
1436
|
return processor;
|
|
1324
1437
|
}
|
|
1325
1438
|
//#endregion
|
|
1326
|
-
export { breadcrumbBufferProcessor as breadcrumbBuffer, breadcrumbBufferProcessor, contextProcessor as context, contextProcessor, contextMiddleware, contextMiddleware as contextMw, dedupeProcessor as dedupe, dedupeProcessor, dynamicSamplerProcessor as dynamicSampler, dynamicSamplerProcessor, enrichProcessor as enrich, enrichProcessor, enrichMiddleware, enrichMiddleware as enrichMw, filterProcessor as filter, filterProcessor, fingerprintProcessor as fingerprint, fingerprintProcessor, fingersCrossedProcessor as fingersCrossed, fingersCrossedProcessor, levelOverrideProcessor as levelOverride, levelOverrideProcessor, typeProcessor as logType, typeProcessor, typeMiddleware as logTypeMw, typeMiddleware, normalizeErrorProcessor as normalizeError, normalizeErrorProcessor, parseStack, privacyGuardProcessor as privacyGuard, privacyGuardProcessor, rateLimitProcessor as rateLimit, rateLimitProcessor, redactProcessor as redact, redactProcessor, routeProcessor as route, routeProcessor, sampleProcessor as sample, sampleProcessor, schemaDevCheckProcessor as schemaDevCheck, schemaDevCheckProcessor, stackParserProcessor as stackParser, stackParserProcessor, tagsProcessor as tags, tagsProcessor, tagsMiddleware, tagsMiddleware as tagsMw, traceContextProcessor as traceContext, traceContextProcessor, traceContextMiddleware, traceContextMiddleware as traceContextMw };
|
|
1439
|
+
export { breadcrumbBufferProcessor as breadcrumbBuffer, breadcrumbBufferProcessor, coalesceProcessor as coalesce, coalesceProcessor, contextProcessor as context, contextProcessor, contextMiddleware, contextMiddleware as contextMw, dedupeProcessor as dedupe, dedupeProcessor, dynamicSamplerProcessor as dynamicSampler, dynamicSamplerProcessor, enrichProcessor as enrich, enrichProcessor, enrichMiddleware, enrichMiddleware as enrichMw, filterProcessor as filter, filterProcessor, fingerprintProcessor as fingerprint, fingerprintProcessor, fingersCrossedProcessor as fingersCrossed, fingersCrossedProcessor, levelOverrideProcessor as levelOverride, levelOverrideProcessor, typeProcessor as logType, typeProcessor, typeMiddleware as logTypeMw, typeMiddleware, normalizeErrorProcessor as normalizeError, normalizeErrorProcessor, parseStack, privacyGuardProcessor as privacyGuard, privacyGuardProcessor, rateLimitProcessor as rateLimit, rateLimitProcessor, redactProcessor as redact, redactProcessor, routeProcessor as route, routeProcessor, sampleProcessor as sample, sampleProcessor, schemaDevCheckProcessor as schemaDevCheck, schemaDevCheckProcessor, stackParserProcessor as stackParser, stackParserProcessor, symbolicateStackProcessor as symbolicateStack, symbolicateStackProcessor, tagsProcessor as tags, tagsProcessor, tagsMiddleware, tagsMiddleware as tagsMw, traceContextProcessor as traceContext, traceContextProcessor, traceContextMiddleware, traceContextMiddleware as traceContextMw };
|
|
1327
1440
|
|
|
1328
1441
|
//# sourceMappingURL=index.js.map
|