@zudojs/observability 0.0.1 → 1.0.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 +260 -13
- package/dist/errors/index.d.ts +5 -0
- package/dist/errors/index.js +5 -0
- package/dist/errors/observabilityError.core.d.ts +32 -0
- package/dist/errors/observabilityError.core.js +56 -0
- package/dist/exporter/exporter.console.d.ts +51 -3
- package/dist/exporter/exporter.console.js +110 -23
- package/dist/exporter/index.d.ts +2 -2
- package/dist/exporter/index.js +2 -2
- package/dist/index.d.ts +17 -11
- package/dist/index.js +20 -12
- package/dist/internal/ids.core.d.ts +26 -0
- package/dist/internal/ids.core.js +51 -0
- package/dist/internal/index.d.ts +5 -0
- package/dist/internal/index.js +5 -0
- package/dist/logLevel/index.d.ts +1 -1
- package/dist/logLevel/index.js +1 -1
- package/dist/logLevel/logLevel.type.d.ts +8 -2
- package/dist/logLevel/logLevel.type.js +27 -20
- package/dist/logRecord/index.d.ts +1 -1
- package/dist/logRecord/index.js +1 -1
- package/dist/logRecord/logRecord.core.d.ts +15 -3
- package/dist/logRecord/logRecord.core.js +48 -26
- package/dist/logger/logger.core.d.ts +16 -8
- package/dist/logger/logger.core.js +54 -23
- package/dist/metrics/counter/counter.core.d.ts +4 -1
- package/dist/metrics/counter/counter.core.js +11 -3
- package/dist/metrics/gauge/gauge.core.d.ts +1 -0
- package/dist/metrics/gauge/gauge.core.js +9 -0
- package/dist/metrics/histogram/histogram.core.d.ts +22 -11
- package/dist/metrics/histogram/histogram.core.js +102 -7
- package/dist/metrics/histogram/index.d.ts +1 -1
- package/dist/metrics/histogram/index.js +1 -1
- package/dist/metrics/index.d.ts +4 -3
- package/dist/metrics/index.js +4 -3
- package/dist/metrics/metrics.reader.d.ts +39 -0
- package/dist/metrics/metrics.reader.js +81 -0
- package/dist/metrics/metrics.registry.d.ts +55 -4
- package/dist/metrics/metrics.registry.js +136 -49
- package/dist/noop/index.d.ts +1 -1
- package/dist/noop/index.js +1 -1
- package/dist/noop/noopObservability.core.d.ts +14 -2
- package/dist/noop/noopObservability.core.js +48 -11
- package/dist/observability/observability.core.d.ts +57 -3
- package/dist/observability/observability.core.js +206 -50
- package/dist/processor/index.d.ts +4 -3
- package/dist/processor/index.js +4 -3
- package/dist/processor/processor.batch.d.ts +66 -11
- package/dist/processor/processor.batch.js +130 -29
- package/dist/processor/processor.log.d.ts +56 -0
- package/dist/processor/processor.log.js +119 -0
- package/dist/propagation/index.d.ts +1 -1
- package/dist/propagation/index.js +1 -1
- package/dist/propagation/propagation.core.d.ts +26 -6
- package/dist/propagation/propagation.core.js +35 -19
- package/dist/redaction/index.d.ts +1 -1
- package/dist/redaction/index.js +1 -1
- package/dist/redaction/redaction.core.d.ts +37 -5
- package/dist/redaction/redaction.core.js +180 -36
- package/dist/sampling/index.d.ts +1 -1
- package/dist/sampling/index.js +1 -1
- package/dist/sampling/sampler.type.d.ts +38 -6
- package/dist/sampling/sampler.type.js +64 -23
- package/dist/tracing/index.d.ts +2 -2
- package/dist/tracing/index.js +2 -2
- package/dist/tracing/span/index.d.ts +1 -1
- package/dist/tracing/span/index.js +1 -1
- package/dist/tracing/span/span.core.d.ts +51 -8
- package/dist/tracing/span/span.core.js +90 -10
- package/dist/tracing/span/spanContext.type.d.ts +12 -3
- package/dist/tracing/span/spanContext.type.js +19 -16
- package/dist/tracing/tracer/index.d.ts +2 -2
- package/dist/tracing/tracer/index.js +2 -2
- package/dist/tracing/tracer/tracer.core.d.ts +44 -14
- package/dist/tracing/tracer/tracer.core.js +81 -25
- package/dist/types/config.types.d.ts +138 -0
- package/dist/types/config.types.js +5 -0
- package/dist/types/logging.types.d.ts +94 -0
- package/dist/types/logging.types.js +20 -0
- package/dist/types/metrics.types.d.ts +93 -0
- package/dist/types/metrics.types.js +5 -0
- package/dist/types/tracing.types.d.ts +115 -0
- package/dist/types/tracing.types.js +28 -0
- package/package.json +17 -8
- package/dist/exporter/exporter.console.d.ts.map +0 -1
- package/dist/exporter/exporter.console.js.map +0 -1
- package/dist/exporter/index.d.ts.map +0 -1
- package/dist/exporter/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/logLevel/index.d.ts.map +0 -1
- package/dist/logLevel/index.js.map +0 -1
- package/dist/logLevel/logLevel.type.d.ts.map +0 -1
- package/dist/logLevel/logLevel.type.js.map +0 -1
- package/dist/logRecord/index.d.ts.map +0 -1
- package/dist/logRecord/index.js.map +0 -1
- package/dist/logRecord/logRecord.core.d.ts.map +0 -1
- package/dist/logRecord/logRecord.core.js.map +0 -1
- package/dist/logger/index.d.ts.map +0 -1
- package/dist/logger/index.js.map +0 -1
- package/dist/logger/logger.core.d.ts.map +0 -1
- package/dist/logger/logger.core.js.map +0 -1
- package/dist/metrics/counter/counter.core.d.ts.map +0 -1
- package/dist/metrics/counter/counter.core.js.map +0 -1
- package/dist/metrics/counter/index.d.ts.map +0 -1
- package/dist/metrics/counter/index.js.map +0 -1
- package/dist/metrics/gauge/gauge.core.d.ts.map +0 -1
- package/dist/metrics/gauge/gauge.core.js.map +0 -1
- package/dist/metrics/gauge/index.d.ts.map +0 -1
- package/dist/metrics/gauge/index.js.map +0 -1
- package/dist/metrics/histogram/histogram.core.d.ts.map +0 -1
- package/dist/metrics/histogram/histogram.core.js.map +0 -1
- package/dist/metrics/histogram/index.d.ts.map +0 -1
- package/dist/metrics/histogram/index.js.map +0 -1
- package/dist/metrics/index.d.ts.map +0 -1
- package/dist/metrics/index.js.map +0 -1
- package/dist/metrics/metrics.registry.d.ts.map +0 -1
- package/dist/metrics/metrics.registry.js.map +0 -1
- package/dist/noop/index.d.ts.map +0 -1
- package/dist/noop/index.js.map +0 -1
- package/dist/noop/noopObservability.core.d.ts.map +0 -1
- package/dist/noop/noopObservability.core.js.map +0 -1
- package/dist/observability/index.d.ts.map +0 -1
- package/dist/observability/index.js.map +0 -1
- package/dist/observability/observability.core.d.ts.map +0 -1
- package/dist/observability/observability.core.js.map +0 -1
- package/dist/processor/index.d.ts.map +0 -1
- package/dist/processor/index.js.map +0 -1
- package/dist/processor/processor.batch.d.ts.map +0 -1
- package/dist/processor/processor.batch.js.map +0 -1
- package/dist/propagation/index.d.ts.map +0 -1
- package/dist/propagation/index.js.map +0 -1
- package/dist/propagation/propagation.core.d.ts.map +0 -1
- package/dist/propagation/propagation.core.js.map +0 -1
- package/dist/redaction/index.d.ts.map +0 -1
- package/dist/redaction/index.js.map +0 -1
- package/dist/redaction/redaction.core.d.ts.map +0 -1
- package/dist/redaction/redaction.core.js.map +0 -1
- package/dist/sampling/index.d.ts.map +0 -1
- package/dist/sampling/index.js.map +0 -1
- package/dist/sampling/sampler.type.d.ts.map +0 -1
- package/dist/sampling/sampler.type.js.map +0 -1
- package/dist/tracing/index.d.ts.map +0 -1
- package/dist/tracing/index.js.map +0 -1
- package/dist/tracing/span/index.d.ts.map +0 -1
- package/dist/tracing/span/index.js.map +0 -1
- package/dist/tracing/span/span.core.d.ts.map +0 -1
- package/dist/tracing/span/span.core.js.map +0 -1
- package/dist/tracing/span/spanContext.type.d.ts.map +0 -1
- package/dist/tracing/span/spanContext.type.js.map +0 -1
- package/dist/tracing/tracer/index.d.ts.map +0 -1
- package/dist/tracing/tracer/index.js.map +0 -1
- package/dist/tracing/tracer/tracer.core.d.ts.map +0 -1
- package/dist/tracing/tracer/tracer.core.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
package/dist/exporter/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @zudojs/observability — Exporters
|
|
3
3
|
*
|
|
4
|
-
* Console exporters for spans, logs, and metrics.
|
|
4
|
+
* Console exporters for spans, logs, and metrics, plus no-op exporters.
|
|
5
5
|
*/
|
|
6
|
-
export { ConsoleSpanExporter, ConsoleLogExporter, ConsoleMetricExporter, createConsoleSpanExporter, createConsoleLogExporter, createConsoleMetricExporter, } from "./exporter.console.js";
|
|
6
|
+
export { ConsoleSpanExporter, ConsoleLogExporter, ConsoleMetricExporter, createConsoleSpanExporter, createConsoleLogExporter, createConsoleMetricExporter, noopLogExporter, noopMetricExporter, safeStringify, } from "./exporter.console.js";
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -16,27 +16,33 @@
|
|
|
16
16
|
* const obs = createObservability({
|
|
17
17
|
* serviceName: "my-api",
|
|
18
18
|
* logLevel: LogLevel.INFO,
|
|
19
|
+
* redaction: {}, // opt in to redaction
|
|
20
|
+
* sampler: createProbabilitySampler(0.1),
|
|
19
21
|
* });
|
|
20
22
|
*
|
|
21
23
|
* obs.logger.info("Server started", { port: 3000 });
|
|
22
24
|
* obs.metrics.counter("http.requests.total").increment();
|
|
23
25
|
* const span = obs.tracer.startSpan("handle-request");
|
|
24
26
|
* span.end();
|
|
27
|
+
*
|
|
28
|
+
* await obs.shutdown();
|
|
25
29
|
* ```
|
|
26
30
|
*
|
|
27
31
|
* @packageDocumentation
|
|
28
32
|
*/
|
|
29
|
-
export { LogLevel, SpanStatus, SpanKind, type LogLevelName, type LogRecord, type Logger, type LoggerOptions, type LogTransport, type PropagationContext, type PropagationContextOptions, type PropagationManager, type Counter, type Gauge, type Histogram, type MetricsRegistry, type MetricSnapshot, type Span, type SpanContext, type SpanEvent, type SpanOptions, type Tracer, type ReadableSpan, type SpanExporter, type LogExporter, type MetricExporter, type SpanProcessor, type SamplingResult, type Sampler, type RedactionConfig, type Observability, type ObservabilityConfig, } from "./types.js";
|
|
30
|
-
export {
|
|
31
|
-
export {
|
|
33
|
+
export { LogLevel, SpanStatus, SpanKind, TraceFlags, type LogLevelName, type LogRecord, type LogRecordError, type Logger, type LoggerOptions, type LogTransport, type PropagationContext, type PropagationContextOptions, type PropagationManager, type Counter, type Gauge, type Histogram, type HistogramValue, type MetricsRegistry, type MetricSnapshot, type Span, type SpanContext, type SpanEvent, type SpanOptions, type SpanLimits, type Tracer, type ReadableSpan, type SpanExporter, type LogExporter, type MetricExporter, type SpanProcessor, type SamplingResult, type Sampler, type RedactionConfig, type RedactionMatchMode, type Observability, type ObservabilityConfig, } from "./types.js";
|
|
34
|
+
export { ObservabilityError, ExporterError, ObservabilityConfigError, MetricValueError, isObservabilityError, } from "./errors/index.js";
|
|
35
|
+
export { generateTraceId, generateSpanId, isValidTraceId, isValidSpanId, } from "./internal/index.js";
|
|
36
|
+
export { logLevelToName, logLevelFromName, parseLogLevel, shouldLog, getLogLevelNames, } from "./logLevel/index.js";
|
|
37
|
+
export { createLogRecord, createErrorLogRecord, serializeError, } from "./logRecord/index.js";
|
|
32
38
|
export { StructuredLogger, createStructuredLogger } from "./logger/index.js";
|
|
33
|
-
export { createPropagationContext, derivePropagationContext, getCurrentContext, AsyncPropagationManager, createPropagationManager, } from "./propagation/index.js";
|
|
34
|
-
export { DefaultCounter, createCounter, DefaultGauge, createGauge, DefaultHistogram, createHistogram, DefaultMetricsRegistry, createMetricsRegistry, } from "./metrics/index.js";
|
|
35
|
-
export { DefaultSpan, createSpan, createSpanContext, createChildSpanContext, DefaultTracer, createTracer, } from "./tracing/index.js";
|
|
36
|
-
export { AlwaysOnSampler, AlwaysOffSampler, ProbabilitySampler, ParentBasedSampler, createAlwaysOnSampler, createAlwaysOffSampler, createProbabilitySampler, createParentBasedSampler, } from "./sampling/index.js";
|
|
37
|
-
export { ConsoleSpanExporter, ConsoleLogExporter, ConsoleMetricExporter, createConsoleSpanExporter, createConsoleLogExporter, createConsoleMetricExporter, } from "./exporter/index.js";
|
|
38
|
-
export { BatchSpanProcessor, createBatchSpanProcessor, } from "./processor/index.js";
|
|
39
|
-
export { createRedactor, redactObject, isSensitiveField, } from "./redaction/index.js";
|
|
40
|
-
export { NoopObservability, createNoopObservability, noopLogger, noopCounter, noopGauge, noopHistogram, noopMetricsRegistry, noopSpan, noopTracer, noopPropagationManager, } from "./noop/index.js";
|
|
39
|
+
export { createPropagationContext, derivePropagationContext, getCurrentContext, requireCurrentContext, AsyncPropagationManager, createPropagationManager, } from "./propagation/index.js";
|
|
40
|
+
export { DefaultCounter, createCounter, DefaultGauge, createGauge, DefaultHistogram, createHistogram, DEFAULT_BUCKET_BOUNDARIES, DefaultMetricsRegistry, createMetricsRegistry, metricKey, PeriodicMetricReader, createPeriodicMetricReader, type MetricsRegistryOptions, type PeriodicMetricReaderOptions, } from "./metrics/index.js";
|
|
41
|
+
export { DefaultSpan, createSpan, createSpanContext, createChildSpanContext, isSampledContext, DefaultTracer, createTracer, type TracerOptions, } from "./tracing/index.js";
|
|
42
|
+
export { AlwaysOnSampler, AlwaysOffSampler, ProbabilitySampler, ParentBasedSampler, createAlwaysOnSampler, createAlwaysOffSampler, createProbabilitySampler, createParentBasedSampler, isSampled, isRecording, type ParentBasedSamplerOptions, } from "./sampling/index.js";
|
|
43
|
+
export { ConsoleSpanExporter, ConsoleLogExporter, ConsoleMetricExporter, createConsoleSpanExporter, createConsoleLogExporter, createConsoleMetricExporter, noopLogExporter, noopMetricExporter, safeStringify, type ConsoleExporterOptions, type ConsoleLike, } from "./exporter/index.js";
|
|
44
|
+
export { BatchSpanProcessor, createBatchSpanProcessor, SimpleSpanProcessor, createSimpleSpanProcessor, BatchLogProcessor, createBatchLogProcessor, noopSpanExporter, type BatchSpanProcessorOptions, type BatchLogProcessorOptions, } from "./processor/index.js";
|
|
45
|
+
export { createRedactor, createStructureRedactor, redactObject, redactValue, isSensitiveField, DEFAULT_SENSITIVE_FIELDS, CIRCULAR_MARKER, MAX_DEPTH_MARKER, } from "./redaction/index.js";
|
|
46
|
+
export { NoopObservability, createNoopObservability, noopLogger, noopCounter, noopGauge, noopHistogram, noopMetricsRegistry, noopSpan, noopTracer, noopPropagationManager, INVALID_PROPAGATION_CONTEXT, } from "./noop/index.js";
|
|
41
47
|
export { DefaultObservability, createObservability, } from "./observability/index.js";
|
|
42
48
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -16,40 +16,48 @@
|
|
|
16
16
|
* const obs = createObservability({
|
|
17
17
|
* serviceName: "my-api",
|
|
18
18
|
* logLevel: LogLevel.INFO,
|
|
19
|
+
* redaction: {}, // opt in to redaction
|
|
20
|
+
* sampler: createProbabilitySampler(0.1),
|
|
19
21
|
* });
|
|
20
22
|
*
|
|
21
23
|
* obs.logger.info("Server started", { port: 3000 });
|
|
22
24
|
* obs.metrics.counter("http.requests.total").increment();
|
|
23
25
|
* const span = obs.tracer.startSpan("handle-request");
|
|
24
26
|
* span.end();
|
|
27
|
+
*
|
|
28
|
+
* await obs.shutdown();
|
|
25
29
|
* ```
|
|
26
30
|
*
|
|
27
31
|
* @packageDocumentation
|
|
28
32
|
*/
|
|
29
33
|
/* ─── Core Types ────────────────────────────────────────────────────────── */
|
|
30
|
-
export { LogLevel, SpanStatus, SpanKind, } from "./types.js";
|
|
34
|
+
export { LogLevel, SpanStatus, SpanKind, TraceFlags, } from "./types.js";
|
|
35
|
+
/* ─── Errors ────────────────────────────────────────────────────────────── */
|
|
36
|
+
export { ObservabilityError, ExporterError, ObservabilityConfigError, MetricValueError, isObservabilityError, } from "./errors/index.js";
|
|
37
|
+
/* ─── Identifiers ───────────────────────────────────────────────────────── */
|
|
38
|
+
export { generateTraceId, generateSpanId, isValidTraceId, isValidSpanId, } from "./internal/index.js";
|
|
31
39
|
/* ─── Log Level ─────────────────────────────────────────────────────────── */
|
|
32
|
-
export { logLevelToName, logLevelFromName, shouldLog, getLogLevelNames, } from "./logLevel/index.js";
|
|
40
|
+
export { logLevelToName, logLevelFromName, parseLogLevel, shouldLog, getLogLevelNames, } from "./logLevel/index.js";
|
|
33
41
|
/* ─── Log Record ────────────────────────────────────────────────────────── */
|
|
34
|
-
export { createLogRecord, createErrorLogRecord } from "./logRecord/index.js";
|
|
42
|
+
export { createLogRecord, createErrorLogRecord, serializeError, } from "./logRecord/index.js";
|
|
35
43
|
/* ─── Logger ────────────────────────────────────────────────────────────── */
|
|
36
44
|
export { StructuredLogger, createStructuredLogger } from "./logger/index.js";
|
|
37
45
|
/* ─── Propagation ───────────────────────────────────────────────────────── */
|
|
38
|
-
export { createPropagationContext, derivePropagationContext, getCurrentContext, AsyncPropagationManager, createPropagationManager, } from "./propagation/index.js";
|
|
46
|
+
export { createPropagationContext, derivePropagationContext, getCurrentContext, requireCurrentContext, AsyncPropagationManager, createPropagationManager, } from "./propagation/index.js";
|
|
39
47
|
/* ─── Metrics ───────────────────────────────────────────────────────────── */
|
|
40
|
-
export { DefaultCounter, createCounter, DefaultGauge, createGauge, DefaultHistogram, createHistogram, DefaultMetricsRegistry, createMetricsRegistry, } from "./metrics/index.js";
|
|
48
|
+
export { DefaultCounter, createCounter, DefaultGauge, createGauge, DefaultHistogram, createHistogram, DEFAULT_BUCKET_BOUNDARIES, DefaultMetricsRegistry, createMetricsRegistry, metricKey, PeriodicMetricReader, createPeriodicMetricReader, } from "./metrics/index.js";
|
|
41
49
|
/* ─── Tracing ───────────────────────────────────────────────────────────── */
|
|
42
|
-
export { DefaultSpan, createSpan, createSpanContext, createChildSpanContext, DefaultTracer, createTracer, } from "./tracing/index.js";
|
|
50
|
+
export { DefaultSpan, createSpan, createSpanContext, createChildSpanContext, isSampledContext, DefaultTracer, createTracer, } from "./tracing/index.js";
|
|
43
51
|
/* ─── Sampling ──────────────────────────────────────────────────────────── */
|
|
44
|
-
export { AlwaysOnSampler, AlwaysOffSampler, ProbabilitySampler, ParentBasedSampler, createAlwaysOnSampler, createAlwaysOffSampler, createProbabilitySampler, createParentBasedSampler, } from "./sampling/index.js";
|
|
52
|
+
export { AlwaysOnSampler, AlwaysOffSampler, ProbabilitySampler, ParentBasedSampler, createAlwaysOnSampler, createAlwaysOffSampler, createProbabilitySampler, createParentBasedSampler, isSampled, isRecording, } from "./sampling/index.js";
|
|
45
53
|
/* ─── Exporters ─────────────────────────────────────────────────────────── */
|
|
46
|
-
export { ConsoleSpanExporter, ConsoleLogExporter, ConsoleMetricExporter, createConsoleSpanExporter, createConsoleLogExporter, createConsoleMetricExporter, } from "./exporter/index.js";
|
|
47
|
-
/* ───
|
|
48
|
-
export { BatchSpanProcessor, createBatchSpanProcessor, } from "./processor/index.js";
|
|
54
|
+
export { ConsoleSpanExporter, ConsoleLogExporter, ConsoleMetricExporter, createConsoleSpanExporter, createConsoleLogExporter, createConsoleMetricExporter, noopLogExporter, noopMetricExporter, safeStringify, } from "./exporter/index.js";
|
|
55
|
+
/* ─── Processors ────────────────────────────────────────────────────────── */
|
|
56
|
+
export { BatchSpanProcessor, createBatchSpanProcessor, SimpleSpanProcessor, createSimpleSpanProcessor, BatchLogProcessor, createBatchLogProcessor, noopSpanExporter, } from "./processor/index.js";
|
|
49
57
|
/* ─── Redaction ─────────────────────────────────────────────────────────── */
|
|
50
|
-
export { createRedactor, redactObject, isSensitiveField, } from "./redaction/index.js";
|
|
58
|
+
export { createRedactor, createStructureRedactor, redactObject, redactValue, isSensitiveField, DEFAULT_SENSITIVE_FIELDS, CIRCULAR_MARKER, MAX_DEPTH_MARKER, } from "./redaction/index.js";
|
|
51
59
|
/* ─── Noop ──────────────────────────────────────────────────────────────── */
|
|
52
|
-
export { NoopObservability, createNoopObservability, noopLogger, noopCounter, noopGauge, noopHistogram, noopMetricsRegistry, noopSpan, noopTracer, noopPropagationManager, } from "./noop/index.js";
|
|
60
|
+
export { NoopObservability, createNoopObservability, noopLogger, noopCounter, noopGauge, noopHistogram, noopMetricsRegistry, noopSpan, noopTracer, noopPropagationManager, INVALID_PROPAGATION_CONTEXT, } from "./noop/index.js";
|
|
53
61
|
/* ─── Observability Facade ──────────────────────────────────────────────── */
|
|
54
62
|
export { DefaultObservability, createObservability, } from "./observability/index.js";
|
|
55
63
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zudojs/observability — Identifier generation
|
|
3
|
+
*
|
|
4
|
+
* One generator, used by both the propagation context and the span context.
|
|
5
|
+
* IDs come from `node:crypto`, not `Math.random()`: trace, span, request and
|
|
6
|
+
* correlation IDs routinely end up in idempotency keys, log correlation and
|
|
7
|
+
* access decisions, and a predictable stream of them is a liability that a
|
|
8
|
+
* CSPRNG costs nothing to avoid.
|
|
9
|
+
*/
|
|
10
|
+
/** Bytes in a W3C trace ID. */
|
|
11
|
+
export declare const TRACE_ID_BYTES = 16;
|
|
12
|
+
/** Bytes in a W3C span ID. */
|
|
13
|
+
export declare const SPAN_ID_BYTES = 8;
|
|
14
|
+
/** Generates a cryptographically random lowercase hex ID. */
|
|
15
|
+
export declare function generateHexId(byteLength: number): string;
|
|
16
|
+
/** Generates a 16-byte trace ID, never the all-zero (invalid) value. */
|
|
17
|
+
export declare function generateTraceId(): string;
|
|
18
|
+
/** Generates an 8-byte span ID, never the all-zero (invalid) value. */
|
|
19
|
+
export declare function generateSpanId(): string;
|
|
20
|
+
/** True when `id` is valid lowercase hex of the expected width and non-zero. */
|
|
21
|
+
export declare function isValidId(id: string, byteLength: number): boolean;
|
|
22
|
+
/** True when `traceId` is a valid W3C trace ID. */
|
|
23
|
+
export declare function isValidTraceId(traceId: string): boolean;
|
|
24
|
+
/** True when `spanId` is a valid W3C span ID. */
|
|
25
|
+
export declare function isValidSpanId(spanId: string): boolean;
|
|
26
|
+
//# sourceMappingURL=ids.core.d.ts.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zudojs/observability — Identifier generation
|
|
3
|
+
*
|
|
4
|
+
* One generator, used by both the propagation context and the span context.
|
|
5
|
+
* IDs come from `node:crypto`, not `Math.random()`: trace, span, request and
|
|
6
|
+
* correlation IDs routinely end up in idempotency keys, log correlation and
|
|
7
|
+
* access decisions, and a predictable stream of them is a liability that a
|
|
8
|
+
* CSPRNG costs nothing to avoid.
|
|
9
|
+
*/
|
|
10
|
+
import { randomBytes } from "node:crypto";
|
|
11
|
+
/** Bytes in a W3C trace ID. */
|
|
12
|
+
export const TRACE_ID_BYTES = 16;
|
|
13
|
+
/** Bytes in a W3C span ID. */
|
|
14
|
+
export const SPAN_ID_BYTES = 8;
|
|
15
|
+
const INVALID_TRACE_ID = "0".repeat(TRACE_ID_BYTES * 2);
|
|
16
|
+
const INVALID_SPAN_ID = "0".repeat(SPAN_ID_BYTES * 2);
|
|
17
|
+
/** Generates a cryptographically random lowercase hex ID. */
|
|
18
|
+
export function generateHexId(byteLength) {
|
|
19
|
+
return randomBytes(byteLength).toString("hex");
|
|
20
|
+
}
|
|
21
|
+
/** Generates a 16-byte trace ID, never the all-zero (invalid) value. */
|
|
22
|
+
export function generateTraceId() {
|
|
23
|
+
let id = generateHexId(TRACE_ID_BYTES);
|
|
24
|
+
while (id === INVALID_TRACE_ID)
|
|
25
|
+
id = generateHexId(TRACE_ID_BYTES);
|
|
26
|
+
return id;
|
|
27
|
+
}
|
|
28
|
+
/** Generates an 8-byte span ID, never the all-zero (invalid) value. */
|
|
29
|
+
export function generateSpanId() {
|
|
30
|
+
let id = generateHexId(SPAN_ID_BYTES);
|
|
31
|
+
while (id === INVALID_SPAN_ID)
|
|
32
|
+
id = generateHexId(SPAN_ID_BYTES);
|
|
33
|
+
return id;
|
|
34
|
+
}
|
|
35
|
+
/** True when `id` is valid lowercase hex of the expected width and non-zero. */
|
|
36
|
+
export function isValidId(id, byteLength) {
|
|
37
|
+
if (id.length !== byteLength * 2)
|
|
38
|
+
return false;
|
|
39
|
+
if (!/^[0-9a-f]+$/.test(id))
|
|
40
|
+
return false;
|
|
41
|
+
return !/^0+$/.test(id);
|
|
42
|
+
}
|
|
43
|
+
/** True when `traceId` is a valid W3C trace ID. */
|
|
44
|
+
export function isValidTraceId(traceId) {
|
|
45
|
+
return isValidId(traceId, TRACE_ID_BYTES);
|
|
46
|
+
}
|
|
47
|
+
/** True when `spanId` is a valid W3C span ID. */
|
|
48
|
+
export function isValidSpanId(spanId) {
|
|
49
|
+
return isValidId(spanId, SPAN_ID_BYTES);
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=ids.core.js.map
|
package/dist/logLevel/index.d.ts
CHANGED
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Level names, conversion, and filtering utilities.
|
|
5
5
|
*/
|
|
6
|
-
export { logLevelToName, logLevelFromName, shouldLog, getLogLevelNames, } from "./logLevel.type.js";
|
|
6
|
+
export { logLevelToName, logLevelFromName, parseLogLevel, shouldLog, getLogLevelNames, } from "./logLevel.type.js";
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/logLevel/index.js
CHANGED
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Level names, conversion, and filtering utilities.
|
|
5
5
|
*/
|
|
6
|
-
export { logLevelToName, logLevelFromName, shouldLog, getLogLevelNames, } from "./logLevel.type.js";
|
|
6
|
+
export { logLevelToName, logLevelFromName, parseLogLevel, shouldLog, getLogLevelNames, } from "./logLevel.type.js";
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @zudojs/observability — Log Level
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* The single source of truth for the level↔name mapping, and the filtering
|
|
5
|
+
* predicate every logger uses.
|
|
6
6
|
*/
|
|
7
7
|
import { LogLevel, type LogLevelName } from "../types.js";
|
|
8
8
|
/** Converts a numeric level to its name. */
|
|
9
9
|
export declare function logLevelToName(level: LogLevel): LogLevelName;
|
|
10
10
|
/** Converts a level name to its numeric value. */
|
|
11
11
|
export declare function logLevelFromName(name: LogLevelName): LogLevel;
|
|
12
|
+
/**
|
|
13
|
+
* Parses an arbitrary string — an environment variable, a config file entry —
|
|
14
|
+
* into a level, returning `undefined` when it names no level. Use this at a
|
|
15
|
+
* trust boundary; {@link logLevelFromName} assumes the name is already valid.
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseLogLevel(value: string): LogLevel | undefined;
|
|
12
18
|
/** Returns true if a message at `messageLevel` should pass the `threshold`. */
|
|
13
19
|
export declare function shouldLog(threshold: LogLevel, messageLevel: LogLevel): boolean;
|
|
14
20
|
/** Returns all log level names. */
|
|
@@ -1,38 +1,45 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @zudojs/observability — Log Level
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* The single source of truth for the level↔name mapping, and the filtering
|
|
5
|
+
* predicate every logger uses.
|
|
6
6
|
*/
|
|
7
7
|
import { LogLevel } from "../types.js";
|
|
8
|
-
const
|
|
9
|
-
"trace",
|
|
10
|
-
"debug",
|
|
11
|
-
"info",
|
|
12
|
-
"warn",
|
|
13
|
-
"error",
|
|
14
|
-
"fatal",
|
|
15
|
-
"off",
|
|
16
|
-
];
|
|
17
|
-
const NAME_TO_LEVEL = new Map([
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
["error", LogLevel.ERROR],
|
|
23
|
-
["fatal", LogLevel.FATAL],
|
|
24
|
-
["off", LogLevel.OFF],
|
|
8
|
+
const LEVEL_TO_NAME = new Map([
|
|
9
|
+
[LogLevel.TRACE, "trace"],
|
|
10
|
+
[LogLevel.DEBUG, "debug"],
|
|
11
|
+
[LogLevel.INFO, "info"],
|
|
12
|
+
[LogLevel.WARN, "warn"],
|
|
13
|
+
[LogLevel.ERROR, "error"],
|
|
14
|
+
[LogLevel.FATAL, "fatal"],
|
|
15
|
+
[LogLevel.OFF, "off"],
|
|
16
|
+
]);
|
|
17
|
+
const NAME_TO_LEVEL = new Map([...LEVEL_TO_NAME].map(([level, name]) => [name, level]));
|
|
18
|
+
// Frozen: this array is handed straight to callers, and an unfrozen module
|
|
19
|
+
// singleton is one `push` away from corrupting every later reader.
|
|
20
|
+
const LEVEL_NAMES = Object.freeze([
|
|
21
|
+
...LEVEL_TO_NAME.values(),
|
|
25
22
|
]);
|
|
26
23
|
/** Converts a numeric level to its name. */
|
|
27
24
|
export function logLevelToName(level) {
|
|
28
|
-
return
|
|
25
|
+
return LEVEL_TO_NAME.get(level) ?? "off";
|
|
29
26
|
}
|
|
30
27
|
/** Converts a level name to its numeric value. */
|
|
31
28
|
export function logLevelFromName(name) {
|
|
32
29
|
return NAME_TO_LEVEL.get(name) ?? LogLevel.OFF;
|
|
33
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Parses an arbitrary string — an environment variable, a config file entry —
|
|
33
|
+
* into a level, returning `undefined` when it names no level. Use this at a
|
|
34
|
+
* trust boundary; {@link logLevelFromName} assumes the name is already valid.
|
|
35
|
+
*/
|
|
36
|
+
export function parseLogLevel(value) {
|
|
37
|
+
return NAME_TO_LEVEL.get(value.trim().toLowerCase());
|
|
38
|
+
}
|
|
34
39
|
/** Returns true if a message at `messageLevel` should pass the `threshold`. */
|
|
35
40
|
export function shouldLog(threshold, messageLevel) {
|
|
41
|
+
if (threshold >= LogLevel.OFF)
|
|
42
|
+
return false;
|
|
36
43
|
return messageLevel >= threshold;
|
|
37
44
|
}
|
|
38
45
|
/** Returns all log level names. */
|
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Structured log record creation and error log records.
|
|
5
5
|
*/
|
|
6
|
-
export { createLogRecord, createErrorLogRecord } from "./logRecord.core.js";
|
|
6
|
+
export { createLogRecord, createErrorLogRecord, serializeError, } from "./logRecord.core.js";
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/logRecord/index.js
CHANGED
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Structured log record creation and error log records.
|
|
5
5
|
*/
|
|
6
|
-
export { createLogRecord, createErrorLogRecord } from "./logRecord.core.js";
|
|
6
|
+
export { createLogRecord, createErrorLogRecord, serializeError, } from "./logRecord.core.js";
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -3,16 +3,28 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Factory functions for creating structured log records.
|
|
5
5
|
*/
|
|
6
|
-
import type { LogRecord } from "../types.js";
|
|
6
|
+
import type { LogRecord, LogRecordError } from "../types.js";
|
|
7
7
|
import { LogLevel } from "../types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Serializes a thrown value into something a JSON transport can carry.
|
|
10
|
+
*
|
|
11
|
+
* `Error`'s own fields are non-enumerable, so an error placed in a log
|
|
12
|
+
* context stringifies to `{}` — this is what turns it back into data.
|
|
13
|
+
* `cause` chains are followed, with a depth cap so a self-referential cause
|
|
14
|
+
* cannot recurse forever.
|
|
15
|
+
*/
|
|
16
|
+
export declare function serializeError(error: unknown, depth?: number): LogRecordError;
|
|
8
17
|
/** Creates a structured log record. */
|
|
9
18
|
export declare function createLogRecord(options: {
|
|
10
19
|
readonly level: LogLevel;
|
|
11
20
|
readonly message: string;
|
|
12
21
|
readonly loggerName: string;
|
|
13
22
|
readonly context?: Record<string, unknown>;
|
|
14
|
-
readonly error?:
|
|
23
|
+
readonly error?: unknown;
|
|
24
|
+
readonly traceId?: string;
|
|
25
|
+
readonly spanId?: string;
|
|
26
|
+
readonly timestamp?: Date;
|
|
15
27
|
}): LogRecord;
|
|
16
28
|
/** Creates a log record for an error. */
|
|
17
|
-
export declare function createErrorLogRecord(error:
|
|
29
|
+
export declare function createErrorLogRecord(error: unknown, level: LogLevel, loggerName: string, context?: Record<string, unknown>): LogRecord;
|
|
18
30
|
//# sourceMappingURL=logRecord.core.d.ts.map
|
|
@@ -4,46 +4,68 @@
|
|
|
4
4
|
* Factory functions for creating structured log records.
|
|
5
5
|
*/
|
|
6
6
|
import { LogLevel } from "../types.js";
|
|
7
|
+
import { logLevelToName } from "../logLevel/index.js";
|
|
8
|
+
/**
|
|
9
|
+
* Serializes a thrown value into something a JSON transport can carry.
|
|
10
|
+
*
|
|
11
|
+
* `Error`'s own fields are non-enumerable, so an error placed in a log
|
|
12
|
+
* context stringifies to `{}` — this is what turns it back into data.
|
|
13
|
+
* `cause` chains are followed, with a depth cap so a self-referential cause
|
|
14
|
+
* cannot recurse forever.
|
|
15
|
+
*/
|
|
16
|
+
export function serializeError(error, depth = 0) {
|
|
17
|
+
if (error instanceof Error) {
|
|
18
|
+
const cause = error.cause !== undefined && depth < 4
|
|
19
|
+
? serializeError(error.cause, depth + 1)
|
|
20
|
+
: undefined;
|
|
21
|
+
return {
|
|
22
|
+
name: error.name,
|
|
23
|
+
message: error.message,
|
|
24
|
+
stack: error.stack,
|
|
25
|
+
cause,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
if (typeof error === "object" && error !== null) {
|
|
29
|
+
const record = error;
|
|
30
|
+
const name = typeof record["name"] === "string" ? record["name"] : "Error";
|
|
31
|
+
const message = typeof record["message"] === "string"
|
|
32
|
+
? record["message"]
|
|
33
|
+
: safeStringify(error);
|
|
34
|
+
return { name, message };
|
|
35
|
+
}
|
|
36
|
+
return { name: "Error", message: String(error) };
|
|
37
|
+
}
|
|
38
|
+
function safeStringify(value) {
|
|
39
|
+
try {
|
|
40
|
+
return JSON.stringify(value) ?? String(value);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return String(value);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
7
46
|
/** Creates a structured log record. */
|
|
8
47
|
export function createLogRecord(options) {
|
|
9
|
-
const error = options.error
|
|
10
|
-
? {
|
|
11
|
-
name: options.error.name,
|
|
12
|
-
message: options.error.message,
|
|
13
|
-
stack: options.error.stack,
|
|
14
|
-
cause: options.error.cause,
|
|
15
|
-
}
|
|
16
|
-
: undefined;
|
|
17
48
|
return {
|
|
18
49
|
level: options.level,
|
|
19
|
-
levelName:
|
|
50
|
+
levelName: logLevelToName(options.level),
|
|
20
51
|
message: options.message,
|
|
21
|
-
timestamp: new Date(),
|
|
52
|
+
timestamp: options.timestamp ?? new Date(),
|
|
22
53
|
loggerName: options.loggerName,
|
|
23
54
|
context: options.context,
|
|
24
|
-
error,
|
|
55
|
+
error: options.error === undefined ? undefined : serializeError(options.error),
|
|
56
|
+
traceId: options.traceId,
|
|
57
|
+
spanId: options.spanId,
|
|
25
58
|
};
|
|
26
59
|
}
|
|
27
60
|
/** Creates a log record for an error. */
|
|
28
|
-
export function createErrorLogRecord(error, level, loggerName) {
|
|
61
|
+
export function createErrorLogRecord(error, level, loggerName, context) {
|
|
62
|
+
const serialized = serializeError(error);
|
|
29
63
|
return createLogRecord({
|
|
30
64
|
level,
|
|
31
|
-
message:
|
|
65
|
+
message: serialized.message,
|
|
32
66
|
loggerName,
|
|
33
|
-
context
|
|
67
|
+
context,
|
|
34
68
|
error,
|
|
35
69
|
});
|
|
36
70
|
}
|
|
37
|
-
function logLevelToNameInternal(level) {
|
|
38
|
-
const names = {
|
|
39
|
-
[LogLevel.TRACE]: "trace",
|
|
40
|
-
[LogLevel.DEBUG]: "debug",
|
|
41
|
-
[LogLevel.INFO]: "info",
|
|
42
|
-
[LogLevel.WARN]: "warn",
|
|
43
|
-
[LogLevel.ERROR]: "error",
|
|
44
|
-
[LogLevel.FATAL]: "fatal",
|
|
45
|
-
[LogLevel.OFF]: "off",
|
|
46
|
-
};
|
|
47
|
-
return names[level] ?? "off";
|
|
48
|
-
}
|
|
49
71
|
//# sourceMappingURL=logRecord.core.js.map
|
|
@@ -2,26 +2,34 @@
|
|
|
2
2
|
* @zudojs/observability — Logger Core
|
|
3
3
|
*
|
|
4
4
|
* Structured logger implementation with level filtering, transport support,
|
|
5
|
-
* child loggers,
|
|
5
|
+
* child loggers, persistent context, trace correlation and redaction.
|
|
6
6
|
*/
|
|
7
7
|
import type { Logger, LoggerOptions } from "../types.js";
|
|
8
8
|
import { LogLevel } from "../types.js";
|
|
9
9
|
/**
|
|
10
10
|
* Core structured logger with level filtering, child loggers,
|
|
11
11
|
* persistent context, and transport support.
|
|
12
|
+
*
|
|
13
|
+
* Every record is stamped with the ambient `traceId`/`spanId` when a
|
|
14
|
+
* propagation context is active, so logs and traces line up without the
|
|
15
|
+
* caller threading IDs through by hand.
|
|
12
16
|
*/
|
|
13
17
|
export declare class StructuredLogger implements Logger {
|
|
14
18
|
readonly name: string;
|
|
15
|
-
|
|
19
|
+
private currentLevel;
|
|
16
20
|
private readonly context;
|
|
17
21
|
private readonly transport;
|
|
22
|
+
private readonly correlate;
|
|
23
|
+
private readonly redact?;
|
|
18
24
|
constructor(options: LoggerOptions);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
get level(): LogLevel;
|
|
26
|
+
setLevel(level: LogLevel): void;
|
|
27
|
+
trace(message: string, context?: Record<string, unknown>, error?: unknown): void;
|
|
28
|
+
debug(message: string, context?: Record<string, unknown>, error?: unknown): void;
|
|
29
|
+
info(message: string, context?: Record<string, unknown>, error?: unknown): void;
|
|
30
|
+
warn(message: string, context?: Record<string, unknown>, error?: unknown): void;
|
|
31
|
+
error(message: string, context?: Record<string, unknown>, error?: unknown): void;
|
|
32
|
+
fatal(message: string, context?: Record<string, unknown>, error?: unknown): void;
|
|
25
33
|
child(name: string, context?: Record<string, unknown>): Logger;
|
|
26
34
|
isLevelEnabled(level: LogLevel): boolean;
|
|
27
35
|
flush(): Promise<void>;
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
* @zudojs/observability — Logger Core
|
|
3
3
|
*
|
|
4
4
|
* Structured logger implementation with level filtering, transport support,
|
|
5
|
-
* child loggers,
|
|
5
|
+
* child loggers, persistent context, trace correlation and redaction.
|
|
6
6
|
*/
|
|
7
7
|
import { LogLevel } from "../types.js";
|
|
8
|
-
import { shouldLog
|
|
8
|
+
import { shouldLog } from "../logLevel/index.js";
|
|
9
9
|
import { createLogRecord } from "../logRecord/index.js";
|
|
10
|
+
import { getCurrentContext } from "../propagation/index.js";
|
|
10
11
|
/** Default no-op transport that discards all records. */
|
|
11
12
|
const noopTransport = {
|
|
12
13
|
name: "noop",
|
|
@@ -15,63 +16,93 @@ const noopTransport = {
|
|
|
15
16
|
/**
|
|
16
17
|
* Core structured logger with level filtering, child loggers,
|
|
17
18
|
* persistent context, and transport support.
|
|
19
|
+
*
|
|
20
|
+
* Every record is stamped with the ambient `traceId`/`spanId` when a
|
|
21
|
+
* propagation context is active, so logs and traces line up without the
|
|
22
|
+
* caller threading IDs through by hand.
|
|
18
23
|
*/
|
|
19
24
|
export class StructuredLogger {
|
|
20
25
|
name;
|
|
21
|
-
|
|
26
|
+
currentLevel;
|
|
22
27
|
context;
|
|
23
28
|
transport;
|
|
29
|
+
correlate;
|
|
30
|
+
redact;
|
|
24
31
|
constructor(options) {
|
|
25
32
|
this.name = options.name;
|
|
26
|
-
this.
|
|
33
|
+
this.currentLevel = options.level ?? LogLevel.INFO;
|
|
27
34
|
this.context = { ...(options.context ?? {}) };
|
|
28
35
|
this.transport = options.transport ?? noopTransport;
|
|
36
|
+
this.correlate = options.correlate ?? true;
|
|
37
|
+
this.redact = options.redact;
|
|
38
|
+
}
|
|
39
|
+
get level() {
|
|
40
|
+
return this.currentLevel;
|
|
41
|
+
}
|
|
42
|
+
setLevel(level) {
|
|
43
|
+
this.currentLevel = level;
|
|
29
44
|
}
|
|
30
|
-
trace(message, context) {
|
|
31
|
-
this.log(LogLevel.TRACE, message, context);
|
|
45
|
+
trace(message, context, error) {
|
|
46
|
+
this.log(LogLevel.TRACE, message, context, error);
|
|
32
47
|
}
|
|
33
|
-
debug(message, context) {
|
|
34
|
-
this.log(LogLevel.DEBUG, message, context);
|
|
48
|
+
debug(message, context, error) {
|
|
49
|
+
this.log(LogLevel.DEBUG, message, context, error);
|
|
35
50
|
}
|
|
36
|
-
info(message, context) {
|
|
37
|
-
this.log(LogLevel.INFO, message, context);
|
|
51
|
+
info(message, context, error) {
|
|
52
|
+
this.log(LogLevel.INFO, message, context, error);
|
|
38
53
|
}
|
|
39
|
-
warn(message, context) {
|
|
40
|
-
this.log(LogLevel.WARN, message, context);
|
|
54
|
+
warn(message, context, error) {
|
|
55
|
+
this.log(LogLevel.WARN, message, context, error);
|
|
41
56
|
}
|
|
42
|
-
error(message, context) {
|
|
43
|
-
this.log(LogLevel.ERROR, message, context);
|
|
57
|
+
error(message, context, error) {
|
|
58
|
+
this.log(LogLevel.ERROR, message, context, error);
|
|
44
59
|
}
|
|
45
|
-
fatal(message, context) {
|
|
46
|
-
this.log(LogLevel.FATAL, message, context);
|
|
60
|
+
fatal(message, context, error) {
|
|
61
|
+
this.log(LogLevel.FATAL, message, context, error);
|
|
47
62
|
}
|
|
48
63
|
child(name, context) {
|
|
49
64
|
const childName = `${this.name}.${name}`;
|
|
50
65
|
const childContext = { ...this.context, ...(context ?? {}) };
|
|
51
66
|
return new StructuredLogger({
|
|
52
67
|
name: childName,
|
|
53
|
-
level: this.
|
|
68
|
+
level: this.currentLevel,
|
|
54
69
|
context: childContext,
|
|
55
70
|
transport: this.transport,
|
|
71
|
+
correlate: this.correlate,
|
|
72
|
+
redact: this.redact,
|
|
56
73
|
});
|
|
57
74
|
}
|
|
58
75
|
isLevelEnabled(level) {
|
|
59
|
-
return shouldLog(this.
|
|
76
|
+
return shouldLog(this.currentLevel, level);
|
|
60
77
|
}
|
|
61
78
|
async flush() {
|
|
62
|
-
|
|
79
|
+
await this.transport.flush?.();
|
|
63
80
|
}
|
|
64
|
-
log(level, message, context) {
|
|
81
|
+
log(level, message, context, error) {
|
|
65
82
|
if (!this.isLevelEnabled(level))
|
|
66
83
|
return;
|
|
67
|
-
const
|
|
84
|
+
const merged = { ...this.context, ...(context ?? {}) };
|
|
85
|
+
const redacted = this.redact ? this.redact(merged) : merged;
|
|
86
|
+
const propagation = this.correlate ? getCurrentContext() : undefined;
|
|
68
87
|
const record = createLogRecord({
|
|
69
88
|
level,
|
|
70
89
|
message,
|
|
71
90
|
loggerName: this.name,
|
|
72
|
-
context: Object.keys(
|
|
91
|
+
context: Object.keys(redacted).length > 0 ? redacted : undefined,
|
|
92
|
+
error,
|
|
93
|
+
traceId: propagation?.traceId,
|
|
94
|
+
spanId: propagation?.spanId,
|
|
73
95
|
});
|
|
74
|
-
|
|
96
|
+
// A transport must never take the caller down with it. A failing sink is
|
|
97
|
+
// reported through the transport's own channel, not raised here.
|
|
98
|
+
try {
|
|
99
|
+
const written = this.transport.write(record);
|
|
100
|
+
if (written instanceof Promise)
|
|
101
|
+
written.catch(() => { });
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// Intentionally swallowed: logging is not allowed to throw.
|
|
105
|
+
}
|
|
75
106
|
}
|
|
76
107
|
}
|
|
77
108
|
/** Creates a structured logger. */
|