@iii-dev/observability 0.19.4-alpha.2 → 0.19.4-alpha.4

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/dist/index.d.cts CHANGED
@@ -1,244 +1 @@
1
- import { A as injectTraceparent, C as currentTraceId, D as getAllBaggage, E as extractTraceparent, M as setBaggageEntry, N as OtelConfig, O as getBaggageEntry, P as ReconnectionConfig, S as currentSpanId, T as extractContext, _ as recordSpanEvent, a as flushOtel, b as BaggageSpanProcessor, d as withSpan, f as REDACTED_PLACEHOLDER, g as currentSpanIsRecording, h as resolveMaxBytesFromEnv, i as Span, j as removeBaggageEntry, k as injectBaggage, l as initOtel, m as redactAndTruncate, n as Meter, o as getLogger, p as redact, r as SeverityNumber, t as Logger$1, u as shutdownOtel, v as setCurrentSpanAttribute, w as extractBaggage, x as DEFAULT_ALLOWLIST, y as setCurrentSpanError } from "./index-Cb4IHzbB.cjs";
2
- import { Meter as Meter$1, Tracer } from "@opentelemetry/api";
3
-
4
- //#region src/logger.d.ts
5
- /**
6
- * Structured logger that emits logs as OpenTelemetry LogRecords.
7
- *
8
- * Every log call automatically captures the active trace and span context,
9
- * correlating your logs with distributed traces without any manual wiring.
10
- * When OTel is not initialized, Logger gracefully falls back to `console.*`.
11
- *
12
- * Pass structured data as the second argument to any log method. Using an
13
- * object of key-value pairs (instead of string interpolation) lets you
14
- * filter, aggregate, and build dashboards in your observability backend.
15
- *
16
- * @example
17
- * ```typescript
18
- * import { Logger } from 'iii-sdk'
19
- *
20
- * const logger = new Logger()
21
- *
22
- * // Basic logging — trace context is injected automatically
23
- * logger.info('Worker connected')
24
- *
25
- * // Structured context for dashboards and alerting
26
- * logger.info('Order processed', { orderId: 'ord_123', amount: 49.99, currency: 'USD' })
27
- * logger.warn('Retry attempt', { attempt: 3, maxRetries: 5, endpoint: '/api/charge' })
28
- * logger.error('Payment failed', { orderId: 'ord_123', gateway: 'stripe', errorCode: 'card_declined' })
29
- * ```
30
- */
31
- declare class Logger {
32
- private readonly traceId?;
33
- private readonly serviceName?;
34
- private readonly spanId?;
35
- private _otelLogger;
36
- private get otelLogger();
37
- constructor(traceId?: string | undefined, serviceName?: string | undefined, spanId?: string | undefined);
38
- private emit;
39
- /**
40
- * Log an info-level message.
41
- *
42
- * @param message - Human-readable log message.
43
- * @param data - Structured context attached as OTel log attributes.
44
- * Use key-value objects to enable filtering and aggregation in your
45
- * observability backend (e.g. Grafana, Datadog, New Relic).
46
- *
47
- * @example
48
- * ```typescript
49
- * logger.info('Order processed', { orderId: 'ord_123', status: 'completed' })
50
- * ```
51
- */
52
- info(message: string, data?: unknown): void;
53
- /**
54
- * Log a warning-level message.
55
- *
56
- * @param message - Human-readable log message.
57
- * @param data - Structured context attached as OTel log attributes.
58
- * Use key-value objects to enable filtering and aggregation in your
59
- * observability backend (e.g. Grafana, Datadog, New Relic).
60
- *
61
- * @example
62
- * ```typescript
63
- * logger.warn('Retry attempt', { attempt: 3, maxRetries: 5, endpoint: '/api/charge' })
64
- * ```
65
- */
66
- warn(message: string, data?: unknown): void;
67
- /**
68
- * Log an error-level message.
69
- *
70
- * @param message - Human-readable log message.
71
- * @param data - Structured context attached as OTel log attributes.
72
- * Use key-value objects to enable filtering and aggregation in your
73
- * observability backend (e.g. Grafana, Datadog, New Relic).
74
- *
75
- * @example
76
- * ```typescript
77
- * logger.error('Payment failed', { orderId: 'ord_123', gateway: 'stripe', errorCode: 'card_declined' })
78
- * ```
79
- */
80
- error(message: string, data?: unknown): void;
81
- /**
82
- * Log a debug-level message.
83
- *
84
- * @param message - Human-readable log message.
85
- * @param data - Structured context attached as OTel log attributes.
86
- * Use key-value objects to enable filtering and aggregation in your
87
- * observability backend (e.g. Grafana, Datadog, New Relic).
88
- *
89
- * @example
90
- * ```typescript
91
- * logger.debug('Cache lookup', { key: 'user:42', hit: false })
92
- * ```
93
- */
94
- debug(message: string, data?: unknown): void;
95
- }
96
- //#endregion
97
- //#region src/http-instrumentation.d.ts
98
- interface TracedFetchInit extends RequestInit {
99
- tracer?: Tracer;
100
- }
101
- /**
102
- * Execute a fetch request inside an OTel CLIENT span.
103
- *
104
- * Mirrors the Rust execute_traced_request shape: injects W3C traceparent into
105
- * outgoing headers, records HTTP semantic-convention attributes, and sets
106
- * ERROR span status for HTTP responses with status >= 400 or network errors.
107
- */
108
- declare function executeTracedRequest(input: RequestInfo | URL, init?: TracedFetchInit): Promise<Response>;
109
- //#endregion
110
- //#region src/telemetry-system/fetch-instrumentation.d.ts
111
- /**
112
- * Patch globalThis.fetch to create OTel CLIENT spans for every HTTP request.
113
- */
114
- declare function patchGlobalFetch(tracer: Tracer): void;
115
- /**
116
- * Restore globalThis.fetch to its original implementation.
117
- */
118
- declare function unpatchGlobalFetch(): void;
119
- //#endregion
120
- //#region src/otel-worker-gauges.d.ts
121
- interface WorkerGaugesOptions {
122
- workerId: string;
123
- workerName?: string;
124
- }
125
- declare function registerWorkerGauges(meter: Meter$1, options: WorkerGaugesOptions): void;
126
- declare function stopWorkerGauges(): void;
127
- //#endregion
128
- //#region src/worker-metrics.d.ts
129
- /**
130
- * Worker metrics collection for the III Node SDK.
131
- *
132
- * Collects CPU, memory, and event loop metrics for worker health monitoring.
133
- * Uses the Node.js built-in `monitorEventLoopDelay` API for accurate
134
- * event loop lag measurements.
135
- */
136
- /**
137
- * Worker metrics data structure used internally for OTEL metric collection.
138
- */
139
- type WorkerMetrics = {
140
- memory_heap_used?: number;
141
- memory_heap_total?: number;
142
- memory_rss?: number;
143
- memory_external?: number;
144
- cpu_user_micros?: number;
145
- cpu_system_micros?: number;
146
- cpu_percent?: number;
147
- event_loop_lag_ms?: number;
148
- uptime_seconds?: number;
149
- timestamp_ms: number;
150
- runtime: string;
151
- };
152
- /**
153
- * Configuration options for the WorkerMetricsCollector.
154
- */
155
- interface WorkerMetricsCollectorOptions {
156
- /**
157
- * Event loop delay histogram resolution in milliseconds.
158
- * Lower values provide more accurate measurements but use more resources.
159
- * @default 20
160
- */
161
- eventLoopResolutionMs?: number;
162
- }
163
- /**
164
- * Collects worker resource metrics including CPU, memory, and event loop lag.
165
- *
166
- * Uses the Node.js `monitorEventLoopDelay` API for high-precision event loop
167
- * delay measurements instead of manual `setImmediate` timing.
168
- *
169
- * @example
170
- * ```typescript
171
- * const collector = new WorkerMetricsCollector()
172
- *
173
- * // Collect metrics periodically
174
- * setInterval(() => {
175
- * const metrics = collector.collect()
176
- * console.log('CPU:', metrics.cpu_percent, '%')
177
- * console.log('Event Loop Lag:', metrics.event_loop_lag_ms, 'ms')
178
- * }, 5000)
179
- *
180
- * // Clean up when done
181
- * collector.stopMonitoring()
182
- * ```
183
- */
184
- declare class WorkerMetricsCollector {
185
- private readonly startTime;
186
- private lastCpuUsage;
187
- private lastCpuTime;
188
- private eventLoopHistogram;
189
- /**
190
- * Creates a new WorkerMetricsCollector instance.
191
- *
192
- * @param options - Configuration options
193
- */
194
- constructor(options?: WorkerMetricsCollectorOptions);
195
- /**
196
- * Starts the event loop delay histogram monitoring.
197
- *
198
- * @param resolutionMs - Histogram resolution in milliseconds
199
- */
200
- private startEventLoopMonitoring;
201
- /**
202
- * Stops the event loop monitoring and releases resources.
203
- * Should be called when the collector is no longer needed.
204
- */
205
- stopMonitoring(): void;
206
- /**
207
- * Collects current worker metrics.
208
- *
209
- * This method calculates CPU usage since the last collection,
210
- * reads memory usage, and gets event loop delay statistics.
211
- * The event loop histogram is reset after each collection for
212
- * accurate per-interval measurements.
213
- *
214
- * @returns Current worker metrics snapshot
215
- */
216
- collect(): WorkerMetrics;
217
- }
218
- //#endregion
219
- //#region src/types.d.ts
220
- /** OTEL Log Event from the engine */
221
- type OtelLogEvent = {
222
- /** Timestamp in Unix nanoseconds */timestamp_unix_nano: number; /** Observed timestamp in Unix nanoseconds */
223
- observed_timestamp_unix_nano: number; /** OTEL severity number (1-24): TRACE=1-4, DEBUG=5-8, INFO=9-12, WARN=13-16, ERROR=17-20, FATAL=21-24 */
224
- severity_number: number; /** Severity text (e.g., "INFO", "WARN", "ERROR") */
225
- severity_text: string; /** Log message body */
226
- body: string; /** Structured attributes */
227
- attributes: Record<string, unknown>; /** Trace ID for correlation (if available) */
228
- trace_id?: string; /** Span ID for correlation (if available) */
229
- span_id?: string; /** Resource attributes from the emitting service */
230
- resource: Record<string, string>; /** Service name that emitted the log */
231
- service_name: string; /** Instrumentation scope name (if available) */
232
- instrumentation_scope_name?: string; /** Instrumentation scope version (if available) */
233
- instrumentation_scope_version?: string;
234
- };
235
- //#endregion
236
- //#region src/utils.d.ts
237
- /**
238
- * Safely stringify a value, handling circular references, BigInt, and other edge cases.
239
- * Returns "[unserializable]" if serialization fails for any reason.
240
- */
241
- declare function safeStringify(value: unknown): string;
242
- //#endregion
243
- export { BaggageSpanProcessor, DEFAULT_ALLOWLIST, Logger, type Meter, type OtelConfig, type OtelLogEvent, type Logger$1 as OtelLogger, REDACTED_PLACEHOLDER, type ReconnectionConfig, SeverityNumber, type Span, type TracedFetchInit, type WorkerGaugesOptions, type WorkerMetrics, WorkerMetricsCollector, type WorkerMetricsCollectorOptions, currentSpanId, currentSpanIsRecording, currentTraceId, executeTracedRequest, extractBaggage, extractContext, extractTraceparent, flushOtel, getAllBaggage, getBaggageEntry, getLogger, initOtel, injectBaggage, injectTraceparent, patchGlobalFetch, recordSpanEvent, redact, redactAndTruncate, registerWorkerGauges, removeBaggageEntry, resolveMaxBytesFromEnv, safeStringify, setBaggageEntry, setCurrentSpanAttribute, setCurrentSpanError, shutdownOtel, stopWorkerGauges, unpatchGlobalFetch, withSpan };
244
- //# sourceMappingURL=index.d.cts.map
1
+ export * from "@iii-dev/helpers/observability";
package/dist/index.d.mts CHANGED
@@ -1,244 +1 @@
1
- import { A as injectTraceparent, C as currentTraceId, D as getAllBaggage, E as extractTraceparent, M as setBaggageEntry, N as OtelConfig, O as getBaggageEntry, P as ReconnectionConfig, S as currentSpanId, T as extractContext, _ as recordSpanEvent, a as flushOtel, b as BaggageSpanProcessor, d as withSpan, f as REDACTED_PLACEHOLDER, g as currentSpanIsRecording, h as resolveMaxBytesFromEnv, i as Span, j as removeBaggageEntry, k as injectBaggage, l as initOtel, m as redactAndTruncate, n as Meter, o as getLogger, p as redact, r as SeverityNumber, t as Logger$1, u as shutdownOtel, v as setCurrentSpanAttribute, w as extractBaggage, x as DEFAULT_ALLOWLIST, y as setCurrentSpanError } from "./index-opxepmJp.mjs";
2
- import { Meter as Meter$1, Tracer } from "@opentelemetry/api";
3
-
4
- //#region src/logger.d.ts
5
- /**
6
- * Structured logger that emits logs as OpenTelemetry LogRecords.
7
- *
8
- * Every log call automatically captures the active trace and span context,
9
- * correlating your logs with distributed traces without any manual wiring.
10
- * When OTel is not initialized, Logger gracefully falls back to `console.*`.
11
- *
12
- * Pass structured data as the second argument to any log method. Using an
13
- * object of key-value pairs (instead of string interpolation) lets you
14
- * filter, aggregate, and build dashboards in your observability backend.
15
- *
16
- * @example
17
- * ```typescript
18
- * import { Logger } from 'iii-sdk'
19
- *
20
- * const logger = new Logger()
21
- *
22
- * // Basic logging — trace context is injected automatically
23
- * logger.info('Worker connected')
24
- *
25
- * // Structured context for dashboards and alerting
26
- * logger.info('Order processed', { orderId: 'ord_123', amount: 49.99, currency: 'USD' })
27
- * logger.warn('Retry attempt', { attempt: 3, maxRetries: 5, endpoint: '/api/charge' })
28
- * logger.error('Payment failed', { orderId: 'ord_123', gateway: 'stripe', errorCode: 'card_declined' })
29
- * ```
30
- */
31
- declare class Logger {
32
- private readonly traceId?;
33
- private readonly serviceName?;
34
- private readonly spanId?;
35
- private _otelLogger;
36
- private get otelLogger();
37
- constructor(traceId?: string | undefined, serviceName?: string | undefined, spanId?: string | undefined);
38
- private emit;
39
- /**
40
- * Log an info-level message.
41
- *
42
- * @param message - Human-readable log message.
43
- * @param data - Structured context attached as OTel log attributes.
44
- * Use key-value objects to enable filtering and aggregation in your
45
- * observability backend (e.g. Grafana, Datadog, New Relic).
46
- *
47
- * @example
48
- * ```typescript
49
- * logger.info('Order processed', { orderId: 'ord_123', status: 'completed' })
50
- * ```
51
- */
52
- info(message: string, data?: unknown): void;
53
- /**
54
- * Log a warning-level message.
55
- *
56
- * @param message - Human-readable log message.
57
- * @param data - Structured context attached as OTel log attributes.
58
- * Use key-value objects to enable filtering and aggregation in your
59
- * observability backend (e.g. Grafana, Datadog, New Relic).
60
- *
61
- * @example
62
- * ```typescript
63
- * logger.warn('Retry attempt', { attempt: 3, maxRetries: 5, endpoint: '/api/charge' })
64
- * ```
65
- */
66
- warn(message: string, data?: unknown): void;
67
- /**
68
- * Log an error-level message.
69
- *
70
- * @param message - Human-readable log message.
71
- * @param data - Structured context attached as OTel log attributes.
72
- * Use key-value objects to enable filtering and aggregation in your
73
- * observability backend (e.g. Grafana, Datadog, New Relic).
74
- *
75
- * @example
76
- * ```typescript
77
- * logger.error('Payment failed', { orderId: 'ord_123', gateway: 'stripe', errorCode: 'card_declined' })
78
- * ```
79
- */
80
- error(message: string, data?: unknown): void;
81
- /**
82
- * Log a debug-level message.
83
- *
84
- * @param message - Human-readable log message.
85
- * @param data - Structured context attached as OTel log attributes.
86
- * Use key-value objects to enable filtering and aggregation in your
87
- * observability backend (e.g. Grafana, Datadog, New Relic).
88
- *
89
- * @example
90
- * ```typescript
91
- * logger.debug('Cache lookup', { key: 'user:42', hit: false })
92
- * ```
93
- */
94
- debug(message: string, data?: unknown): void;
95
- }
96
- //#endregion
97
- //#region src/http-instrumentation.d.ts
98
- interface TracedFetchInit extends RequestInit {
99
- tracer?: Tracer;
100
- }
101
- /**
102
- * Execute a fetch request inside an OTel CLIENT span.
103
- *
104
- * Mirrors the Rust execute_traced_request shape: injects W3C traceparent into
105
- * outgoing headers, records HTTP semantic-convention attributes, and sets
106
- * ERROR span status for HTTP responses with status >= 400 or network errors.
107
- */
108
- declare function executeTracedRequest(input: RequestInfo | URL, init?: TracedFetchInit): Promise<Response>;
109
- //#endregion
110
- //#region src/telemetry-system/fetch-instrumentation.d.ts
111
- /**
112
- * Patch globalThis.fetch to create OTel CLIENT spans for every HTTP request.
113
- */
114
- declare function patchGlobalFetch(tracer: Tracer): void;
115
- /**
116
- * Restore globalThis.fetch to its original implementation.
117
- */
118
- declare function unpatchGlobalFetch(): void;
119
- //#endregion
120
- //#region src/otel-worker-gauges.d.ts
121
- interface WorkerGaugesOptions {
122
- workerId: string;
123
- workerName?: string;
124
- }
125
- declare function registerWorkerGauges(meter: Meter$1, options: WorkerGaugesOptions): void;
126
- declare function stopWorkerGauges(): void;
127
- //#endregion
128
- //#region src/worker-metrics.d.ts
129
- /**
130
- * Worker metrics collection for the III Node SDK.
131
- *
132
- * Collects CPU, memory, and event loop metrics for worker health monitoring.
133
- * Uses the Node.js built-in `monitorEventLoopDelay` API for accurate
134
- * event loop lag measurements.
135
- */
136
- /**
137
- * Worker metrics data structure used internally for OTEL metric collection.
138
- */
139
- type WorkerMetrics = {
140
- memory_heap_used?: number;
141
- memory_heap_total?: number;
142
- memory_rss?: number;
143
- memory_external?: number;
144
- cpu_user_micros?: number;
145
- cpu_system_micros?: number;
146
- cpu_percent?: number;
147
- event_loop_lag_ms?: number;
148
- uptime_seconds?: number;
149
- timestamp_ms: number;
150
- runtime: string;
151
- };
152
- /**
153
- * Configuration options for the WorkerMetricsCollector.
154
- */
155
- interface WorkerMetricsCollectorOptions {
156
- /**
157
- * Event loop delay histogram resolution in milliseconds.
158
- * Lower values provide more accurate measurements but use more resources.
159
- * @default 20
160
- */
161
- eventLoopResolutionMs?: number;
162
- }
163
- /**
164
- * Collects worker resource metrics including CPU, memory, and event loop lag.
165
- *
166
- * Uses the Node.js `monitorEventLoopDelay` API for high-precision event loop
167
- * delay measurements instead of manual `setImmediate` timing.
168
- *
169
- * @example
170
- * ```typescript
171
- * const collector = new WorkerMetricsCollector()
172
- *
173
- * // Collect metrics periodically
174
- * setInterval(() => {
175
- * const metrics = collector.collect()
176
- * console.log('CPU:', metrics.cpu_percent, '%')
177
- * console.log('Event Loop Lag:', metrics.event_loop_lag_ms, 'ms')
178
- * }, 5000)
179
- *
180
- * // Clean up when done
181
- * collector.stopMonitoring()
182
- * ```
183
- */
184
- declare class WorkerMetricsCollector {
185
- private readonly startTime;
186
- private lastCpuUsage;
187
- private lastCpuTime;
188
- private eventLoopHistogram;
189
- /**
190
- * Creates a new WorkerMetricsCollector instance.
191
- *
192
- * @param options - Configuration options
193
- */
194
- constructor(options?: WorkerMetricsCollectorOptions);
195
- /**
196
- * Starts the event loop delay histogram monitoring.
197
- *
198
- * @param resolutionMs - Histogram resolution in milliseconds
199
- */
200
- private startEventLoopMonitoring;
201
- /**
202
- * Stops the event loop monitoring and releases resources.
203
- * Should be called when the collector is no longer needed.
204
- */
205
- stopMonitoring(): void;
206
- /**
207
- * Collects current worker metrics.
208
- *
209
- * This method calculates CPU usage since the last collection,
210
- * reads memory usage, and gets event loop delay statistics.
211
- * The event loop histogram is reset after each collection for
212
- * accurate per-interval measurements.
213
- *
214
- * @returns Current worker metrics snapshot
215
- */
216
- collect(): WorkerMetrics;
217
- }
218
- //#endregion
219
- //#region src/types.d.ts
220
- /** OTEL Log Event from the engine */
221
- type OtelLogEvent = {
222
- /** Timestamp in Unix nanoseconds */timestamp_unix_nano: number; /** Observed timestamp in Unix nanoseconds */
223
- observed_timestamp_unix_nano: number; /** OTEL severity number (1-24): TRACE=1-4, DEBUG=5-8, INFO=9-12, WARN=13-16, ERROR=17-20, FATAL=21-24 */
224
- severity_number: number; /** Severity text (e.g., "INFO", "WARN", "ERROR") */
225
- severity_text: string; /** Log message body */
226
- body: string; /** Structured attributes */
227
- attributes: Record<string, unknown>; /** Trace ID for correlation (if available) */
228
- trace_id?: string; /** Span ID for correlation (if available) */
229
- span_id?: string; /** Resource attributes from the emitting service */
230
- resource: Record<string, string>; /** Service name that emitted the log */
231
- service_name: string; /** Instrumentation scope name (if available) */
232
- instrumentation_scope_name?: string; /** Instrumentation scope version (if available) */
233
- instrumentation_scope_version?: string;
234
- };
235
- //#endregion
236
- //#region src/utils.d.ts
237
- /**
238
- * Safely stringify a value, handling circular references, BigInt, and other edge cases.
239
- * Returns "[unserializable]" if serialization fails for any reason.
240
- */
241
- declare function safeStringify(value: unknown): string;
242
- //#endregion
243
- export { BaggageSpanProcessor, DEFAULT_ALLOWLIST, Logger, type Meter, type OtelConfig, type OtelLogEvent, type Logger$1 as OtelLogger, REDACTED_PLACEHOLDER, type ReconnectionConfig, SeverityNumber, type Span, type TracedFetchInit, type WorkerGaugesOptions, type WorkerMetrics, WorkerMetricsCollector, type WorkerMetricsCollectorOptions, currentSpanId, currentSpanIsRecording, currentTraceId, executeTracedRequest, extractBaggage, extractContext, extractTraceparent, flushOtel, getAllBaggage, getBaggageEntry, getLogger, initOtel, injectBaggage, injectTraceparent, patchGlobalFetch, recordSpanEvent, redact, redactAndTruncate, registerWorkerGauges, removeBaggageEntry, resolveMaxBytesFromEnv, safeStringify, setBaggageEntry, setCurrentSpanAttribute, setCurrentSpanError, shutdownOtel, stopWorkerGauges, unpatchGlobalFetch, withSpan };
244
- //# sourceMappingURL=index.d.mts.map
1
+ export * from "@iii-dev/helpers/observability";