@visulima/pail 4.0.0-alpha.11 → 4.0.0-alpha.13
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 +33 -0
- package/LICENSE.md +131 -900
- package/dist/error.d.ts +95 -96
- package/dist/error.js +5 -76
- package/dist/index.browser.d.ts +557 -47
- package/dist/index.browser.js +19 -1499
- package/dist/index.server.d.ts +722 -61
- package/dist/index.server.js +31 -2803
- package/dist/middleware/elysia.d.ts +65 -63
- package/dist/middleware/elysia.js +1 -70
- package/dist/middleware/express.d.ts +73 -71
- package/dist/middleware/express.js +1 -29
- package/dist/middleware/fastify.d.ts +69 -67
- package/dist/middleware/fastify.js +1 -46
- package/dist/middleware/hono.d.ts +74 -72
- package/dist/middleware/hono.js +1 -33
- package/dist/middleware/next/handler.d.ts +101 -34
- package/dist/middleware/next/handler.js +1 -53
- package/dist/middleware/sveltekit.d.ts +100 -98
- package/dist/middleware/sveltekit.js +1 -43
- package/dist/object-tree.d.ts +67 -70
- package/dist/object-tree.js +2 -89
- package/dist/packem_shared/AbstractJsonReporter-BawNFYxI.js +1 -0
- package/dist/packem_shared/AbstractJsonReporter-Dt5-5x2R.js +1 -0
- package/dist/packem_shared/JsonReporter-15ln04rX.js +2 -0
- package/dist/packem_shared/JsonReporter-CerNvhg-.js +1 -0
- package/dist/packem_shared/PrettyReporter-Br5njEEy.js +5 -0
- package/dist/packem_shared/PrettyReporter-CgXnwIip.js +44 -0
- package/dist/packem_shared/abstract-json-reporter.d-Bz3lZEDi.d.ts +61 -0
- package/dist/packem_shared/abstract-pretty-reporter-BiHgKxG_.js +33 -0
- package/dist/packem_shared/constants-DKfCaSUR.js +1 -0
- package/dist/packem_shared/constants-ep2nsfdy.js +1 -0
- package/dist/packem_shared/create-middleware-logger.d-DeNLii5l.d.ts +47 -0
- package/dist/packem_shared/createPailError-53jAfQ-T.js +5 -0
- package/dist/packem_shared/headers-S8WyX-2m.js +1 -0
- package/dist/packem_shared/index-Bzp4LnJ5.js +1 -0
- package/dist/packem_shared/pailMiddleware-CWOJRmJq.js +1 -0
- package/dist/packem_shared/storage-DHM1EP2P.js +1 -0
- package/dist/packem_shared/types.d-ByY2ZuYG.d.ts +246 -0
- package/dist/packem_shared/types.d-C51XNfQz.d.ts +194 -0
- package/dist/packem_shared/types.d-CM5ie2qm.d.ts +236 -0
- package/dist/packem_shared/useLogger-qyZrjy4D.js +1 -0
- package/dist/packem_shared/wide-event.d-Ke44zirU.d.ts +704 -0
- package/dist/packem_shared/write-console-log-based-on-level-DfD64owL.js +1 -0
- package/dist/packem_shared/write-stream-Dd4_PTcm.js +1 -0
- package/dist/processor/caller/caller-processor.d.ts +49 -47
- package/dist/processor/caller/caller-processor.js +1 -59
- package/dist/processor/environment-processor.d.ts +113 -113
- package/dist/processor/environment-processor.js +1 -89
- package/dist/processor/message-formatter-processor.d.ts +51 -49
- package/dist/processor/message-formatter-processor.js +1 -715
- package/dist/processor/opentelemetry-processor.d.ts +69 -66
- package/dist/processor/opentelemetry-processor.js +1 -52
- package/dist/processor/redact-processor.d.ts +60 -41
- package/dist/processor/redact-processor.js +1 -31
- package/dist/processor/sampling-processor.d.ts +102 -101
- package/dist/processor/sampling-processor.js +1 -59
- package/dist/reporter/file/json-file-reporter.d.ts +91 -42
- package/dist/reporter/file/json-file-reporter.js +2 -136
- package/dist/reporter/http/abstract-http-reporter.d.ts +213 -211
- package/dist/reporter/http/abstract-http-reporter.js +2 -432
- package/dist/reporter/http/http-reporter.d.ts +40 -36
- package/dist/reporter/http/http-reporter.edge-light.d.ts +430 -38
- package/dist/reporter/http/http-reporter.edge-light.js +2 -728
- package/dist/reporter/http/http-reporter.js +1 -13
- package/dist/reporter/json/index.browser.d.ts +99 -3
- package/dist/reporter/json/index.browser.js +1 -2
- package/dist/reporter/json/index.d.ts +51 -3
- package/dist/reporter/json/index.js +1 -2
- package/dist/reporter/pretty/index.browser.d.ts +106 -2
- package/dist/reporter/pretty/index.browser.js +1 -1
- package/dist/reporter/pretty/index.d.ts +186 -2
- package/dist/reporter/pretty/index.js +1 -1
- package/dist/reporter/simple/simple-reporter.server.d.ts +168 -18
- package/dist/reporter/simple/simple-reporter.server.js +8 -182
- package/dist/wide-event.d.ts +5 -300
- package/dist/wide-event.js +1 -284
- package/package.json +29 -30
- package/dist/constants.d.ts +0 -37
- package/dist/middleware/next/middleware.d.ts +0 -59
- package/dist/middleware/next/storage.d.ts +0 -14
- package/dist/middleware/shared/create-middleware-logger.d.ts +0 -82
- package/dist/middleware/shared/headers.d.ts +0 -14
- package/dist/middleware/shared/routes.d.ts +0 -30
- package/dist/middleware/shared/storage.d.ts +0 -29
- package/dist/packem_shared/AbstractJsonReporter-BO8Calb4.js +0 -284
- package/dist/packem_shared/AbstractJsonReporter-nOj0Ft1F.js +0 -284
- package/dist/packem_shared/JsonReporter-CCmj7oYL.js +0 -28
- package/dist/packem_shared/JsonReporter-Ck2PIAEw.js +0 -58
- package/dist/packem_shared/PrettyReporter-BCvyNzXO.js +0 -2720
- package/dist/packem_shared/PrettyReporter-BtTr13Ha.js +0 -213
- package/dist/packem_shared/abstract-pretty-reporter-CXAKYCb8.js +0 -2635
- package/dist/packem_shared/constants-B1RjD_ps.js +0 -99
- package/dist/packem_shared/constants-omsTHUWB.js +0 -119
- package/dist/packem_shared/createPailError-B_sgL0nF.js +0 -76
- package/dist/packem_shared/headers-BxHWM6KI.js +0 -127
- package/dist/packem_shared/index-Bx3-C0j9.js +0 -658
- package/dist/packem_shared/pailMiddleware-Ci88geIF.js +0 -24
- package/dist/packem_shared/storage-D0vqz8OX.js +0 -36
- package/dist/packem_shared/useLogger-D0rU3lcX.js +0 -33
- package/dist/packem_shared/write-console-log-based-on-level-ree2lDPw.js +0 -15
- package/dist/packem_shared/write-stream-MDqyXmc_.js +0 -6
- package/dist/pail.browser.d.ts +0 -412
- package/dist/pail.server.d.ts +0 -158
- package/dist/processor/caller/get-caller-filename.d.ts +0 -23
- package/dist/reporter/file/utils/rotating-file-stream.d.ts +0 -48
- package/dist/reporter/http/utils/compression.d.ts +0 -7
- package/dist/reporter/http/utils/log-size-error.d.ts +0 -30
- package/dist/reporter/http/utils/retry.d.ts +0 -27
- package/dist/reporter/json/abstract-json-reporter.d.ts +0 -61
- package/dist/reporter/json/json-reporter.browser.d.ts +0 -40
- package/dist/reporter/json/json-reporter.server.d.ts +0 -50
- package/dist/reporter/pretty/abstract-pretty-reporter.d.ts +0 -83
- package/dist/reporter/pretty/pretty-reporter.browser.d.ts +0 -36
- package/dist/reporter/pretty/pretty-reporter.server.d.ts +0 -70
- package/dist/reporter/raw/raw-reporter.browser.d.ts +0 -5
- package/dist/reporter/raw/raw-reporter.server.d.ts +0 -13
- package/dist/reporter/utils/default-inspector-config.d.ts +0 -3
- package/dist/reporter/utils/format-label.d.ts +0 -3
- package/dist/types.d.ts +0 -241
- package/dist/utils/arrayify.d.ts +0 -2
- package/dist/utils/get-longest-badge.d.ts +0 -4
- package/dist/utils/get-longest-label.d.ts +0 -4
- package/dist/utils/merge-types.d.ts +0 -4
- package/dist/utils/stream/safe-stream-handler.d.ts +0 -21
- package/dist/utils/write-console-log-based-on-level.d.ts +0 -4
- package/dist/utils/write-stream.d.ts +0 -2
|
@@ -1,70 +1,73 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { M as Meta, P as Processor } from "../packem_shared/types.d-ByY2ZuYG.js";
|
|
2
|
+
import '@visulima/colorize';
|
|
3
|
+
import '@visulima/interactive-manager';
|
|
2
4
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
5
|
+
* Configuration options for the OpenTelemetry processor.
|
|
6
|
+
*/
|
|
7
|
+
interface OpenTelemetryProcessorOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Field name for the span ID. Defaults to 'span_id'
|
|
10
|
+
*/
|
|
11
|
+
spanIdFieldName?: string;
|
|
12
|
+
/**
|
|
13
|
+
* If specified, all trace fields will be nested under this key
|
|
14
|
+
*/
|
|
15
|
+
traceFieldName?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Field name for the trace flags. Defaults to 'trace_flags'
|
|
18
|
+
*/
|
|
19
|
+
traceFlagsFieldName?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Field name for the trace ID. Defaults to 'trace_id'
|
|
22
|
+
*/
|
|
23
|
+
traceIdFieldName?: string;
|
|
22
24
|
}
|
|
23
25
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
26
|
+
* OpenTelemetry Processor.
|
|
27
|
+
*
|
|
28
|
+
* A processor that adds OpenTelemetry trace context to log metadata.
|
|
29
|
+
* Extracts trace ID, span ID, and trace flags from the active OpenTelemetry span
|
|
30
|
+
* and adds them to the log context for distributed tracing correlation.
|
|
31
|
+
* @template L - The log level type
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { createPail } from "@visulima/pail";
|
|
35
|
+
* import { OpenTelemetryProcessor } from "@visulima/pail/processor/opentelemetry";
|
|
36
|
+
*
|
|
37
|
+
* const logger = createPail({
|
|
38
|
+
* processors: [new OpenTelemetryProcessor()]
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* logger.info("Processing request");
|
|
42
|
+
* // Context includes: { trace_id: "...", span_id: "...", trace_flags: "01" }
|
|
43
|
+
* ```
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* // With custom field names
|
|
47
|
+
* const logger = createPail({
|
|
48
|
+
* processors: [new OpenTelemetryProcessor({
|
|
49
|
+
* traceFieldName: "trace",
|
|
50
|
+
* traceIdFieldName: "traceId",
|
|
51
|
+
* spanIdFieldName: "spanId"
|
|
52
|
+
* })]
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
declare class OpenTelemetryProcessor<L extends string = string> implements Processor<L> {
|
|
57
|
+
#private;
|
|
58
|
+
/**
|
|
59
|
+
* Creates a new OpenTelemetryProcessor instance.
|
|
60
|
+
* @param options Configuration options for field names and nesting
|
|
61
|
+
*/
|
|
62
|
+
constructor(options?: OpenTelemetryProcessorOptions);
|
|
63
|
+
/**
|
|
64
|
+
* Processes log metadata to add OpenTelemetry trace context.
|
|
65
|
+
*
|
|
66
|
+
* Extracts trace information from the active OpenTelemetry span and adds it
|
|
67
|
+
* to the log context. If no valid span is found, the metadata is returned unchanged.
|
|
68
|
+
* @param meta The log metadata to process
|
|
69
|
+
* @returns The processed metadata with trace context added
|
|
70
|
+
*/
|
|
71
|
+
process(meta: Meta<L>): Meta<L>;
|
|
70
72
|
}
|
|
73
|
+
export { OpenTelemetryProcessor, OpenTelemetryProcessorOptions };
|
|
@@ -1,52 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
class OpenTelemetryProcessor {
|
|
4
|
-
/** Field name for trace ID */
|
|
5
|
-
#traceIdField;
|
|
6
|
-
/** Field name for span ID */
|
|
7
|
-
#spanIdField;
|
|
8
|
-
/** Field name for trace flags */
|
|
9
|
-
#traceFlagsField;
|
|
10
|
-
/** Optional field name to nest all trace fields under */
|
|
11
|
-
#traceFieldName;
|
|
12
|
-
/**
|
|
13
|
-
* Creates a new OpenTelemetryProcessor instance.
|
|
14
|
-
* @param options Configuration options for field names and nesting
|
|
15
|
-
*/
|
|
16
|
-
constructor(options = {}) {
|
|
17
|
-
this.#traceIdField = options.traceIdFieldName ?? "trace_id";
|
|
18
|
-
this.#spanIdField = options.spanIdFieldName ?? "span_id";
|
|
19
|
-
this.#traceFlagsField = options.traceFlagsFieldName ?? "trace_flags";
|
|
20
|
-
this.#traceFieldName = options.traceFieldName;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Processes log metadata to add OpenTelemetry trace context.
|
|
24
|
-
*
|
|
25
|
-
* Extracts trace information from the active OpenTelemetry span and adds it
|
|
26
|
-
* to the log context. If no valid span is found, the metadata is returned unchanged.
|
|
27
|
-
* @param meta The log metadata to process
|
|
28
|
-
* @returns The processed metadata with trace context added
|
|
29
|
-
*/
|
|
30
|
-
process(meta) {
|
|
31
|
-
const span = trace.getSpan(context.active());
|
|
32
|
-
if (!span) {
|
|
33
|
-
return meta;
|
|
34
|
-
}
|
|
35
|
-
const spanContext = span.spanContext();
|
|
36
|
-
if (!isSpanContextValid(spanContext)) {
|
|
37
|
-
return meta;
|
|
38
|
-
}
|
|
39
|
-
const fields = {
|
|
40
|
-
[this.#spanIdField]: spanContext.spanId,
|
|
41
|
-
[this.#traceFlagsField]: `0${spanContext.traceFlags.toString(16)}`,
|
|
42
|
-
[this.#traceIdField]: spanContext.traceId
|
|
43
|
-
};
|
|
44
|
-
const traceData = this.#traceFieldName ? {
|
|
45
|
-
[this.#traceFieldName]: fields
|
|
46
|
-
} : fields;
|
|
47
|
-
meta.context = [...meta.context ?? [], traceData];
|
|
48
|
-
return meta;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export { OpenTelemetryProcessor };
|
|
1
|
+
var n=Object.defineProperty;var s=(e,t)=>n(e,"name",{value:t,configurable:!0});import{trace as o,context as l,isSpanContextValid as d}from"@opentelemetry/api";var p=Object.defineProperty,h=s((e,t)=>p(e,"name",{value:t,configurable:!0}),"i");class f{static{s(this,"OpenTelemetryProcessor")}static{h(this,"OpenTelemetryProcessor")}#e;#r;#s;#t;constructor(t={}){this.#e=t.traceIdFieldName??"trace_id",this.#r=t.spanIdFieldName??"span_id",this.#s=t.traceFlagsFieldName??"trace_flags",this.#t=t.traceFieldName}process(t){const a=o.getSpan(l.active());if(!a)return t;const r=a.spanContext();if(!d(r))return t;const i={[this.#r]:r.spanId,[this.#s]:`0${r.traceFlags.toString(16)}`,[this.#e]:r.traceId},c=this.#t?{[this.#t]:i}:i;return t.context=[...t.context??[],c],t}}export{f as OpenTelemetryProcessor};
|
|
@@ -1,44 +1,63 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { M as Meta, P as Processor } from "../packem_shared/types.d-ByY2ZuYG.js";
|
|
2
|
+
import '@visulima/colorize';
|
|
3
|
+
import '@visulima/interactive-manager';
|
|
4
|
+
type StringAnonymize = {
|
|
5
|
+
key: string;
|
|
6
|
+
pattern: RegExp | string;
|
|
7
|
+
replacement?: string;
|
|
8
|
+
};
|
|
9
|
+
type Anonymize = {
|
|
10
|
+
deep?: boolean;
|
|
11
|
+
key: string;
|
|
12
|
+
pattern?: RegExp | string;
|
|
13
|
+
replacement?: unknown;
|
|
14
|
+
};
|
|
15
|
+
type Rules = (Anonymize | StringAnonymize | number | string)[];
|
|
16
|
+
type RedactOptions = {
|
|
17
|
+
exclude?: (number | string)[];
|
|
18
|
+
logger?: {
|
|
19
|
+
debug: (message?: unknown, ...optionalParameters: unknown[]) => void;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
3
22
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
* Redact Processor.
|
|
24
|
+
*
|
|
25
|
+
* A processor that redacts sensitive information from log messages and metadata.
|
|
26
|
+
* Uses the {@link https://visulima.com/packages/redact/|@visulima/redact} library to identify and mask sensitive data like
|
|
27
|
+
* passwords, API keys, credit card numbers, and other PII.
|
|
28
|
+
* @template L - The log level type
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import { createPail } from "@visulima/pail";
|
|
32
|
+
* import RedactProcessor from "@visulima/pail/processor/redact";
|
|
33
|
+
*
|
|
34
|
+
* const logger = createPail({
|
|
35
|
+
* processors: [new RedactProcessor()]
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* logger.info("User login", {
|
|
39
|
+
* username: "john",
|
|
40
|
+
* password: "secret123", // Will be redacted
|
|
41
|
+
* apiKey: "sk-123456" // Will be redacted
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
26
45
|
declare class RedactProcessor<L extends string = string> implements Processor<L> {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
#private;
|
|
47
|
+
/**
|
|
48
|
+
* Creates a new RedactProcessor instance.
|
|
49
|
+
* @param rules Custom redaction rules (uses standardRules if not provided)
|
|
50
|
+
* @param options Additional redaction options
|
|
51
|
+
*/
|
|
52
|
+
constructor(rules?: Rules, options?: RedactOptions);
|
|
53
|
+
/**
|
|
54
|
+
* Processes log metadata to redact sensitive information.
|
|
55
|
+
*
|
|
56
|
+
* Applies redaction rules to the message, context, and error properties
|
|
57
|
+
* in the log metadata to prevent sensitive data from being logged.
|
|
58
|
+
* @param meta The log metadata to process
|
|
59
|
+
* @returns The processed metadata with sensitive data redacted
|
|
60
|
+
*/
|
|
61
|
+
process(meta: Meta<L>): Meta<L>;
|
|
43
62
|
}
|
|
44
|
-
export default
|
|
63
|
+
export { RedactProcessor as default };
|
|
@@ -1,31 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
class RedactProcessor {
|
|
4
|
-
/** The redact function configured with custom rules and options */
|
|
5
|
-
#redact;
|
|
6
|
-
/**
|
|
7
|
-
* Creates a new RedactProcessor instance.
|
|
8
|
-
* @param rules Custom redaction rules (uses standardRules if not provided)
|
|
9
|
-
* @param options Additional redaction options
|
|
10
|
-
*/
|
|
11
|
-
constructor(rules, options) {
|
|
12
|
-
const effectiveRules = rules ?? standardRules;
|
|
13
|
-
this.#redact = (input) => redact(input, effectiveRules, options);
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Processes log metadata to redact sensitive information.
|
|
17
|
-
*
|
|
18
|
-
* Applies redaction rules to the message, context, and error properties
|
|
19
|
-
* in the log metadata to prevent sensitive data from being logged.
|
|
20
|
-
* @param meta The log metadata to process
|
|
21
|
-
* @returns The processed metadata with sensitive data redacted
|
|
22
|
-
*/
|
|
23
|
-
process(meta) {
|
|
24
|
-
meta.message = this.#redact(meta.message);
|
|
25
|
-
meta.context = this.#redact(meta.context);
|
|
26
|
-
meta.error = this.#redact(meta.error);
|
|
27
|
-
return meta;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export { RedactProcessor as default };
|
|
1
|
+
var c=Object.defineProperty;var s=(r,t)=>c(r,"name",{value:t,configurable:!0});import{redact as i,standardRules as n}from"@visulima/redact";var u=Object.defineProperty,d=s((r,t)=>u(r,"name",{value:t,configurable:!0}),"t");class m{static{s(this,"l")}static{d(this,"RedactProcessor")}#t;constructor(t,e){const o=t??n;this.#t=a=>i(a,o,e)}process(t){return t.message=this.#t(t.message),t.context=this.#t(t.context),t.error=this.#t(t.error),t}}export{m as default};
|
|
@@ -1,111 +1,112 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { M as Meta, P as Processor } from "../packem_shared/types.d-ByY2ZuYG.js";
|
|
2
|
+
import '@visulima/colorize';
|
|
3
|
+
import '@visulima/interactive-manager';
|
|
2
4
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
5
|
+
* Head sampling configuration.
|
|
6
|
+
*
|
|
7
|
+
* Controls random sampling rates per log level. Each key is a log level name
|
|
8
|
+
* and the value is the percentage (0-100) of logs at that level to keep.
|
|
9
|
+
* Levels not listed default to 100 (keep all).
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const headSampling: HeadSamplingConfig = {
|
|
13
|
+
* debug: 0, // Drop all debug logs
|
|
14
|
+
* informational: 10, // Keep 10% of info logs
|
|
15
|
+
* warning: 50, // Keep 50% of warning logs
|
|
16
|
+
* error: 100, // Keep all error logs
|
|
17
|
+
* };
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
18
20
|
type HeadSamplingConfig = Partial<Record<string, number>>;
|
|
19
21
|
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
* Tail sampling condition function.
|
|
23
|
+
*
|
|
24
|
+
* A function that receives the log metadata and returns true if the log
|
|
25
|
+
* should be force-kept regardless of head sampling. This allows keeping
|
|
26
|
+
* important logs based on their content (e.g., errors, slow operations).
|
|
27
|
+
* @template L - The log level type
|
|
28
|
+
*/
|
|
27
29
|
type TailSamplingCondition<L extends string = string> = (meta: Readonly<Meta<L>>) => boolean;
|
|
28
30
|
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
* Sampling processor configuration options.
|
|
32
|
+
*/
|
|
31
33
|
interface SamplingProcessorOptions<L extends string = string> {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Head sampling rates per log level.
|
|
36
|
+
*
|
|
37
|
+
* A map of log level to sampling percentage (0-100).
|
|
38
|
+
* Levels not specified default to 100 (keep all).
|
|
39
|
+
* Set to 0 to drop all logs at that level.
|
|
40
|
+
*/
|
|
41
|
+
head?: HeadSamplingConfig;
|
|
42
|
+
/**
|
|
43
|
+
* Tail sampling conditions.
|
|
44
|
+
*
|
|
45
|
+
* An array of condition functions that can force-keep a log entry
|
|
46
|
+
* even if it was dropped by head sampling. If any condition returns true,
|
|
47
|
+
* the log is kept.
|
|
48
|
+
*/
|
|
49
|
+
tail?: TailSamplingCondition<L>[];
|
|
48
50
|
}
|
|
49
51
|
/**
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
52
|
+
* Sampling Processor.
|
|
53
|
+
*
|
|
54
|
+
* Inspired by evlog's production sampling strategy, this processor implements
|
|
55
|
+
* both head sampling (random per-level) and tail sampling (force-keep based
|
|
56
|
+
* on conditions) to control log volume in production environments.
|
|
57
|
+
*
|
|
58
|
+
* **Head sampling** randomly drops a percentage of logs per level. This is
|
|
59
|
+
* evaluated first and provides broad volume control.
|
|
60
|
+
*
|
|
61
|
+
* **Tail sampling** can override head sampling to force-keep important logs
|
|
62
|
+
* based on their content. For example, you might drop 90% of info logs but
|
|
63
|
+
* force-keep any that contain error information or relate to slow operations.
|
|
64
|
+
*
|
|
65
|
+
* When a log is dropped by sampling, the processor sets a `__dropped: true`
|
|
66
|
+
* boolean flag on the meta object. Reporters should check for this flag and
|
|
67
|
+
* skip entries where `__dropped` is `true`.
|
|
68
|
+
* @template L - The log level type
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* import { createPail } from "@visulima/pail";
|
|
72
|
+
* import SamplingProcessor from "@visulima/pail/processor/sampling";
|
|
73
|
+
*
|
|
74
|
+
* const logger = createPail({
|
|
75
|
+
* processors: [
|
|
76
|
+
* new SamplingProcessor({
|
|
77
|
+
* head: {
|
|
78
|
+
* debug: 0, // Drop all debug logs
|
|
79
|
+
* informational: 10, // Keep 10% of info logs
|
|
80
|
+
* warning: 50, // Keep 50% of warnings
|
|
81
|
+
* error: 100, // Keep all errors
|
|
82
|
+
* },
|
|
83
|
+
* tail: [
|
|
84
|
+
* // Force-keep logs with errors regardless of head sampling
|
|
85
|
+
* (meta) => meta.error !== undefined,
|
|
86
|
+
* // Force-keep logs from critical scopes
|
|
87
|
+
* (meta) => meta.scope?.includes("payment") ?? false,
|
|
88
|
+
* ],
|
|
89
|
+
* }),
|
|
90
|
+
* ],
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
92
94
|
declare class SamplingProcessor<L extends string = string> implements Processor<L> {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
95
|
+
#private;
|
|
96
|
+
/**
|
|
97
|
+
* Creates a new SamplingProcessor instance.
|
|
98
|
+
* @param options Sampling configuration options
|
|
99
|
+
*/
|
|
100
|
+
constructor(options?: SamplingProcessorOptions<L>);
|
|
101
|
+
/**
|
|
102
|
+
* Processes log metadata to apply sampling rules.
|
|
103
|
+
*
|
|
104
|
+
* First evaluates head sampling (random per-level), then checks tail
|
|
105
|
+
* sampling conditions. If a log is dropped, the meta is marked with
|
|
106
|
+
* `__dropped: true` so reporters can skip it.
|
|
107
|
+
* @param meta The log metadata to process
|
|
108
|
+
* @returns The processed metadata, potentially marked as dropped
|
|
109
|
+
*/
|
|
110
|
+
process(meta: Meta<L>): Meta<L>;
|
|
109
111
|
}
|
|
110
|
-
export default
|
|
111
|
-
export type { HeadSamplingConfig, SamplingProcessorOptions, TailSamplingCondition };
|
|
112
|
+
export { type HeadSamplingConfig, type SamplingProcessorOptions, type TailSamplingCondition, SamplingProcessor as default };
|
|
@@ -1,59 +1 @@
|
|
|
1
|
-
class SamplingProcessor {
|
|
2
|
-
#headRates;
|
|
3
|
-
#tailConditions;
|
|
4
|
-
/**
|
|
5
|
-
* Creates a new SamplingProcessor instance.
|
|
6
|
-
* @param options Sampling configuration options
|
|
7
|
-
*/
|
|
8
|
-
constructor(options = {}) {
|
|
9
|
-
this.#headRates = options.head ?? {};
|
|
10
|
-
this.#tailConditions = options.tail ?? [];
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Processes log metadata to apply sampling rules.
|
|
14
|
-
*
|
|
15
|
-
* First evaluates head sampling (random per-level), then checks tail
|
|
16
|
-
* sampling conditions. If a log is dropped, the meta is marked with
|
|
17
|
-
* `__dropped: true` so reporters can skip it.
|
|
18
|
-
* @param meta The log metadata to process
|
|
19
|
-
* @returns The processed metadata, potentially marked as dropped
|
|
20
|
-
*/
|
|
21
|
-
process(meta) {
|
|
22
|
-
const level = meta.type.level;
|
|
23
|
-
if (this.#shouldDrop(level) && !this.#shouldForceKeep(meta)) {
|
|
24
|
-
return { ...meta, dropped: true };
|
|
25
|
-
}
|
|
26
|
-
return meta;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Evaluates head sampling for the given log level.
|
|
30
|
-
* @returns true if the log should be dropped
|
|
31
|
-
*/
|
|
32
|
-
#shouldDrop(level) {
|
|
33
|
-
const rate = this.#headRates[level];
|
|
34
|
-
if (rate === void 0) {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
if (rate <= 0) {
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
if (rate >= 100) {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
return Math.random() * 100 >= rate;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Evaluates tail sampling conditions.
|
|
47
|
-
* @returns true if any condition forces keeping the log
|
|
48
|
-
*/
|
|
49
|
-
#shouldForceKeep(meta) {
|
|
50
|
-
for (let i = 0; i < this.#tailConditions.length; i += 1) {
|
|
51
|
-
if (this.#tailConditions[i](meta)) {
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export { SamplingProcessor as default };
|
|
1
|
+
var a=Object.defineProperty;var s=(e,t)=>a(e,"name",{value:t,configurable:!0});var i=Object.defineProperty,n=s((e,t)=>i(e,"name",{value:t,configurable:!0}),"i");class l{static{s(this,"o")}static{n(this,"SamplingProcessor")}#r;#t;constructor(t={}){this.#r=t.head??{},this.#t=t.tail??[]}process(t){const r=t.type.level;return this.#e(r)&&!this.#s(t)?{...t,dropped:!0}:t}#e(t){const r=this.#r[t];return r===void 0?!1:r<=0?!0:r>=100?!1:Math.random()*100>=r}#s(t){for(let r=0;r<this.#t.length;r+=1)if(this.#t[r](t))return!0;return!1}}export{l as default};
|