iii-sdk 0.14.0-next.2 → 0.16.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +185 -168
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +753 -85
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +753 -85
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +121 -138
- package/dist/index.mjs.map +1 -1
- package/dist/state.d.cts +1 -1
- package/dist/state.d.mts +1 -1
- package/dist/{stream-0aOn-1J0.d.cts → stream-CNxp3Hhu.d.cts} +1 -1
- package/dist/{stream-0aOn-1J0.d.cts.map → stream-CNxp3Hhu.d.cts.map} +1 -1
- package/dist/{stream-R8MrPAf1.d.mts → stream-CPQKQv-x.d.mts} +1 -1
- package/dist/{stream-R8MrPAf1.d.mts.map → stream-CPQKQv-x.d.mts.map} +1 -1
- package/dist/stream.d.cts +1 -1
- package/dist/stream.d.mts +1 -1
- package/package.json +6 -17
- package/vitest.config.ts +10 -1
- package/dist/telemetry-system-BGZS9Vit.cjs +0 -1586
- package/dist/telemetry-system-BGZS9Vit.cjs.map +0 -1
- package/dist/telemetry-system-DMHiN8V9.mjs +0 -1318
- package/dist/telemetry-system-DMHiN8V9.mjs.map +0 -1
- package/dist/telemetry.cjs +0 -39
- package/dist/telemetry.d.cts +0 -104
- package/dist/telemetry.d.cts.map +0 -1
- package/dist/telemetry.d.mts +0 -104
- package/dist/telemetry.d.mts.map +0 -1
- package/dist/telemetry.mjs +0 -3
- package/dist/utils-DhgysSJS.d.cts +0 -948
- package/dist/utils-DhgysSJS.d.cts.map +0 -1
- package/dist/utils-oTg3ZAbD.d.mts +0 -948
- package/dist/utils-oTg3ZAbD.d.mts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,12 +1,42 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
+
key = keys[i];
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: ((k) => from[k]).bind(null, key),
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
3
29
|
let node_stream = require("node:stream");
|
|
4
30
|
let ws = require("ws");
|
|
5
31
|
let _opentelemetry_api = require("@opentelemetry/api");
|
|
6
32
|
let node_module = require("node:module");
|
|
7
33
|
let node_os = require("node:os");
|
|
8
|
-
node_os =
|
|
9
|
-
let
|
|
34
|
+
node_os = __toESM(node_os);
|
|
35
|
+
let _iii_dev_observability = require("@iii-dev/observability");
|
|
36
|
+
let node_fs = require("node:fs");
|
|
37
|
+
node_fs = __toESM(node_fs);
|
|
38
|
+
let node_path = require("node:path");
|
|
39
|
+
node_path = __toESM(node_path);
|
|
10
40
|
|
|
11
41
|
//#region src/channels.ts
|
|
12
42
|
/**
|
|
@@ -214,6 +244,47 @@ function isErrorBody(value) {
|
|
|
214
244
|
return typeof v.code === "string" && typeof v.message === "string" && (v.stacktrace === void 0 || typeof v.stacktrace === "string");
|
|
215
245
|
}
|
|
216
246
|
|
|
247
|
+
//#endregion
|
|
248
|
+
//#region src/iii-constants.ts
|
|
249
|
+
/**
|
|
250
|
+
* Constants for the III module.
|
|
251
|
+
*/
|
|
252
|
+
/**
|
|
253
|
+
* Engine function paths for internal operations.
|
|
254
|
+
*
|
|
255
|
+
* Naming note: `LIST_TRIGGERS` / `INFO_TRIGGERS` cover trigger TYPES
|
|
256
|
+
* (templates). `LIST_REGISTERED_TRIGGERS` / `INFO_REGISTERED_TRIGGERS`
|
|
257
|
+
* cover trigger INSTANCES (subscriber rows). The old
|
|
258
|
+
* `engine::trigger-types::list` builtin has been removed and is now
|
|
259
|
+
* served by `engine::triggers::list`.
|
|
260
|
+
*/
|
|
261
|
+
const EngineFunctions = {
|
|
262
|
+
LIST_FUNCTIONS: "engine::functions::list",
|
|
263
|
+
INFO_FUNCTIONS: "engine::functions::info",
|
|
264
|
+
LIST_WORKERS: "engine::workers::list",
|
|
265
|
+
INFO_WORKERS: "engine::workers::info",
|
|
266
|
+
LIST_TRIGGERS: "engine::triggers::list",
|
|
267
|
+
INFO_TRIGGERS: "engine::triggers::info",
|
|
268
|
+
LIST_REGISTERED_TRIGGERS: "engine::registered-triggers::list",
|
|
269
|
+
INFO_REGISTERED_TRIGGERS: "engine::registered-triggers::info",
|
|
270
|
+
REGISTER_WORKER: "engine::workers::register"
|
|
271
|
+
};
|
|
272
|
+
/** Engine trigger types */
|
|
273
|
+
const EngineTriggers = {
|
|
274
|
+
FUNCTIONS_AVAILABLE: "engine::functions-available",
|
|
275
|
+
LOG: "log"
|
|
276
|
+
};
|
|
277
|
+
/** Default reconnection configuration */
|
|
278
|
+
const DEFAULT_BRIDGE_RECONNECTION_CONFIG = {
|
|
279
|
+
initialDelayMs: 1e3,
|
|
280
|
+
maxDelayMs: 3e4,
|
|
281
|
+
backoffMultiplier: 2,
|
|
282
|
+
jitterFactor: .3,
|
|
283
|
+
maxRetries: -1
|
|
284
|
+
};
|
|
285
|
+
/** Default invocation timeout in milliseconds */
|
|
286
|
+
const DEFAULT_INVOCATION_TIMEOUT_MS = 3e4;
|
|
287
|
+
|
|
217
288
|
//#endregion
|
|
218
289
|
//#region src/iii-types.ts
|
|
219
290
|
let MessageType = /* @__PURE__ */ function(MessageType) {
|
|
@@ -230,6 +301,81 @@ let MessageType = /* @__PURE__ */ function(MessageType) {
|
|
|
230
301
|
return MessageType;
|
|
231
302
|
}({});
|
|
232
303
|
|
|
304
|
+
//#endregion
|
|
305
|
+
//#region src/utils.ts
|
|
306
|
+
/**
|
|
307
|
+
* Returns a project identifier for telemetry, derived from the current working
|
|
308
|
+
* directory. Reads `package.json` `name` if present at `cwd`; otherwise falls
|
|
309
|
+
* back to the basename of `cwd`. Returns `undefined` only when both signals
|
|
310
|
+
* are unavailable (e.g. cwd is the filesystem root).
|
|
311
|
+
*
|
|
312
|
+
* No directory walking — only inspects `cwd` itself, so the SDK never reads
|
|
313
|
+
* files outside the user's explicit working directory.
|
|
314
|
+
*/
|
|
315
|
+
function detectProjectName(cwd = process.cwd()) {
|
|
316
|
+
try {
|
|
317
|
+
const manifest = node_path.join(cwd, "package.json");
|
|
318
|
+
if (node_fs.existsSync(manifest)) {
|
|
319
|
+
const parsed = JSON.parse(node_fs.readFileSync(manifest, "utf8"));
|
|
320
|
+
if (typeof parsed.name === "string") {
|
|
321
|
+
const trimmed = parsed.name.trim();
|
|
322
|
+
if (trimmed) return trimmed;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
} catch {}
|
|
326
|
+
return node_path.basename(cwd).trim() || void 0;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Helper that wraps an HTTP-style handler (with separate `req`/`res` arguments)
|
|
330
|
+
* into the function handler format expected by the SDK.
|
|
331
|
+
*
|
|
332
|
+
* @param callback - Async handler receiving an {@link HttpRequest} and {@link HttpResponse}.
|
|
333
|
+
* @returns A function handler compatible with {@link ISdk.registerFunction}.
|
|
334
|
+
*
|
|
335
|
+
* @example
|
|
336
|
+
* ```typescript
|
|
337
|
+
* import { http } from 'iii-sdk'
|
|
338
|
+
*
|
|
339
|
+
* iii.registerFunction(
|
|
340
|
+
* 'my-api',
|
|
341
|
+
* http(async (req, res) => {
|
|
342
|
+
* res.status(200)
|
|
343
|
+
* res.headers({ 'content-type': 'application/json' })
|
|
344
|
+
* res.stream.end(JSON.stringify({ hello: 'world' }))
|
|
345
|
+
* res.close()
|
|
346
|
+
* }),
|
|
347
|
+
* )
|
|
348
|
+
* ```
|
|
349
|
+
*/
|
|
350
|
+
const http = (callback) => {
|
|
351
|
+
return async (req) => {
|
|
352
|
+
const { response, ...request } = req;
|
|
353
|
+
return callback(request, {
|
|
354
|
+
status: (status_code) => response.sendMessage(JSON.stringify({
|
|
355
|
+
type: "set_status",
|
|
356
|
+
status_code
|
|
357
|
+
})),
|
|
358
|
+
headers: (headers) => response.sendMessage(JSON.stringify({
|
|
359
|
+
type: "set_headers",
|
|
360
|
+
headers
|
|
361
|
+
})),
|
|
362
|
+
stream: response.stream,
|
|
363
|
+
close: () => response.close()
|
|
364
|
+
});
|
|
365
|
+
};
|
|
366
|
+
};
|
|
367
|
+
/**
|
|
368
|
+
* Type guard that checks if a value is a {@link StreamChannelRef}.
|
|
369
|
+
*
|
|
370
|
+
* @param value - Value to check.
|
|
371
|
+
* @returns `true` if the value is a valid `StreamChannelRef`.
|
|
372
|
+
*/
|
|
373
|
+
const isChannelRef = (value) => {
|
|
374
|
+
if (typeof value !== "object" || value === null) return false;
|
|
375
|
+
const maybe = value;
|
|
376
|
+
return typeof maybe.channel_id === "string" && typeof maybe.access_key === "string" && (maybe.direction === "read" || maybe.direction === "write");
|
|
377
|
+
};
|
|
378
|
+
|
|
233
379
|
//#endregion
|
|
234
380
|
//#region src/iii.ts
|
|
235
381
|
const { version: SDK_VERSION } = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("../package.json");
|
|
@@ -334,11 +480,11 @@ var Sdk = class {
|
|
|
334
480
|
message: fullMessage,
|
|
335
481
|
handler: async (input, traceparent, baggage) => {
|
|
336
482
|
const tracePayloads = !(process.env.III_DISABLE_TRACE_PAYLOADS === "1" || process.env.III_DISABLE_TRACE_PAYLOADS?.toLowerCase() === "true");
|
|
337
|
-
const payloadMaxBytes =
|
|
483
|
+
const payloadMaxBytes = (0, _iii_dev_observability.resolveMaxBytesFromEnv)();
|
|
338
484
|
const runHandler = async () => {
|
|
339
485
|
if (tracePayloads) {
|
|
340
|
-
const { json, truncated } =
|
|
341
|
-
|
|
486
|
+
const { json, truncated } = (0, _iii_dev_observability.redactAndTruncate)(input, payloadMaxBytes);
|
|
487
|
+
(0, _iii_dev_observability.recordSpanEvent)("iii.invocation.input", {
|
|
342
488
|
"iii.payload.json": json,
|
|
343
489
|
"iii.payload.truncated": truncated
|
|
344
490
|
});
|
|
@@ -346,8 +492,8 @@ var Sdk = class {
|
|
|
346
492
|
try {
|
|
347
493
|
const result = await handler(input);
|
|
348
494
|
if (tracePayloads) {
|
|
349
|
-
const { json, truncated } =
|
|
350
|
-
|
|
495
|
+
const { json, truncated } = (0, _iii_dev_observability.redactAndTruncate)(result, payloadMaxBytes);
|
|
496
|
+
(0, _iii_dev_observability.recordSpanEvent)("iii.invocation.output", {
|
|
351
497
|
"iii.payload.json": json,
|
|
352
498
|
"iii.payload.truncated": truncated,
|
|
353
499
|
"iii.payload.ok": true
|
|
@@ -356,8 +502,8 @@ var Sdk = class {
|
|
|
356
502
|
return result;
|
|
357
503
|
} catch (err) {
|
|
358
504
|
if (tracePayloads) {
|
|
359
|
-
const { json, truncated } =
|
|
360
|
-
|
|
505
|
+
const { json, truncated } = (0, _iii_dev_observability.redactAndTruncate)({ error: err instanceof Error ? err.message : String(err) }, payloadMaxBytes);
|
|
506
|
+
(0, _iii_dev_observability.recordSpanEvent)("iii.invocation.output", {
|
|
361
507
|
"iii.payload.json": json,
|
|
362
508
|
"iii.payload.truncated": truncated,
|
|
363
509
|
"iii.payload.ok": false
|
|
@@ -366,9 +512,9 @@ var Sdk = class {
|
|
|
366
512
|
throw err;
|
|
367
513
|
}
|
|
368
514
|
};
|
|
369
|
-
if (
|
|
370
|
-
const parentContext =
|
|
371
|
-
return _opentelemetry_api.context.with(parentContext, () =>
|
|
515
|
+
if ((0, _iii_dev_observability.getTracer)()) {
|
|
516
|
+
const parentContext = (0, _iii_dev_observability.extractContext)(traceparent, baggage);
|
|
517
|
+
return _opentelemetry_api.context.with(parentContext, () => (0, _iii_dev_observability.withSpan)(`call ${functionId}`, { kind: _iii_dev_observability.SpanKind.SERVER }, async () => await runHandler()));
|
|
372
518
|
}
|
|
373
519
|
const traceId = crypto.randomUUID().replace(/-/g, "");
|
|
374
520
|
const spanId = crypto.randomUUID().replace(/-/g, "").slice(0, 16);
|
|
@@ -405,8 +551,8 @@ var Sdk = class {
|
|
|
405
551
|
const { function_id, payload, action, timeoutMs } = request;
|
|
406
552
|
const effectiveTimeout = timeoutMs ?? this.invocationTimeoutMs;
|
|
407
553
|
if (action?.type === "void") {
|
|
408
|
-
const traceparent =
|
|
409
|
-
const baggage =
|
|
554
|
+
const traceparent = (0, _iii_dev_observability.injectTraceparent)();
|
|
555
|
+
const baggage = (0, _iii_dev_observability.injectBaggage)();
|
|
410
556
|
this.sendMessage(MessageType.InvokeFunction, {
|
|
411
557
|
function_id,
|
|
412
558
|
data: payload,
|
|
@@ -417,8 +563,8 @@ var Sdk = class {
|
|
|
417
563
|
return;
|
|
418
564
|
}
|
|
419
565
|
const invocation_id = crypto.randomUUID();
|
|
420
|
-
const traceparent =
|
|
421
|
-
const baggage =
|
|
566
|
+
const traceparent = (0, _iii_dev_observability.injectTraceparent)();
|
|
567
|
+
const baggage = (0, _iii_dev_observability.injectBaggage)();
|
|
422
568
|
return new Promise((resolve, reject) => {
|
|
423
569
|
const timeout = setTimeout(() => {
|
|
424
570
|
if (this.invocations.get(invocation_id)) {
|
|
@@ -462,7 +608,7 @@ var Sdk = class {
|
|
|
462
608
|
this.shutdown = async () => {
|
|
463
609
|
this.isShuttingDown = true;
|
|
464
610
|
this.stopMetricsReporting();
|
|
465
|
-
await
|
|
611
|
+
await (0, _iii_dev_observability.shutdownOtel)();
|
|
466
612
|
this.clearReconnectTimeout();
|
|
467
613
|
for (const [_id, invocation] of this.invocations) {
|
|
468
614
|
if (invocation.timeout) clearTimeout(invocation.timeout);
|
|
@@ -483,10 +629,10 @@ var Sdk = class {
|
|
|
483
629
|
this.metricsReportingEnabled = options?.enableMetricsReporting ?? true;
|
|
484
630
|
this.invocationTimeoutMs = options?.invocationTimeoutMs ?? 3e4;
|
|
485
631
|
this.reconnectionConfig = {
|
|
486
|
-
...
|
|
632
|
+
...DEFAULT_BRIDGE_RECONNECTION_CONFIG,
|
|
487
633
|
...options?.reconnectionConfig
|
|
488
634
|
};
|
|
489
|
-
|
|
635
|
+
(0, _iii_dev_observability.initOtel)({
|
|
490
636
|
...options?.otel,
|
|
491
637
|
engineWsUrl: this.address
|
|
492
638
|
});
|
|
@@ -496,7 +642,7 @@ var Sdk = class {
|
|
|
496
642
|
const telemetryOpts = this.options?.telemetry;
|
|
497
643
|
const language = telemetryOpts?.language ?? Intl.DateTimeFormat().resolvedOptions().locale ?? process.env.LANG?.split(".")[0];
|
|
498
644
|
this.trigger({
|
|
499
|
-
function_id:
|
|
645
|
+
function_id: EngineFunctions.REGISTER_WORKER,
|
|
500
646
|
payload: {
|
|
501
647
|
runtime: "node",
|
|
502
648
|
version: SDK_VERSION,
|
|
@@ -506,7 +652,7 @@ var Sdk = class {
|
|
|
506
652
|
isolation: process.env.III_ISOLATION || null,
|
|
507
653
|
telemetry: {
|
|
508
654
|
language,
|
|
509
|
-
project_name: telemetryOpts?.project_name ??
|
|
655
|
+
project_name: telemetryOpts?.project_name ?? detectProjectName(),
|
|
510
656
|
framework: telemetryOpts?.framework?.trim() || "iii-node",
|
|
511
657
|
amplitude_api_key: telemetryOpts?.amplitude_api_key
|
|
512
658
|
}
|
|
@@ -557,18 +703,18 @@ var Sdk = class {
|
|
|
557
703
|
}
|
|
558
704
|
startMetricsReporting() {
|
|
559
705
|
if (!this.metricsReportingEnabled || !this.workerId) return;
|
|
560
|
-
const meter =
|
|
706
|
+
const meter = (0, _iii_dev_observability.getMeter)();
|
|
561
707
|
if (!meter) {
|
|
562
708
|
console.warn("[iii] Worker metrics disabled: OpenTelemetry not initialized. Call initOtel() with metricsEnabled: true before creating the iii.");
|
|
563
709
|
return;
|
|
564
710
|
}
|
|
565
|
-
|
|
711
|
+
(0, _iii_dev_observability.registerWorkerGauges)(meter, {
|
|
566
712
|
workerId: this.workerId,
|
|
567
713
|
workerName: this.workerName
|
|
568
714
|
});
|
|
569
715
|
}
|
|
570
716
|
stopMetricsReporting() {
|
|
571
|
-
|
|
717
|
+
(0, _iii_dev_observability.stopWorkerGauges)();
|
|
572
718
|
}
|
|
573
719
|
onSocketClose() {
|
|
574
720
|
this.ws?.removeAllListeners();
|
|
@@ -649,10 +795,10 @@ var Sdk = class {
|
|
|
649
795
|
else if (!skipIfClosed) this.messagesToSend.push(wireMessage);
|
|
650
796
|
}
|
|
651
797
|
logError(message, error) {
|
|
652
|
-
const otelLogger =
|
|
798
|
+
const otelLogger = (0, _iii_dev_observability.getLogger)();
|
|
653
799
|
const errorMessage = error instanceof Error ? error.message : String(error ?? "");
|
|
654
800
|
if (otelLogger) otelLogger.emit({
|
|
655
|
-
severityNumber:
|
|
801
|
+
severityNumber: _iii_dev_observability.SeverityNumber.ERROR,
|
|
656
802
|
body: `[iii] ${message}${errorMessage ? `: ${errorMessage}` : ""}`
|
|
657
803
|
});
|
|
658
804
|
else console.error(`[iii] ${message}`, error ?? "");
|
|
@@ -688,7 +834,7 @@ var Sdk = class {
|
|
|
688
834
|
});
|
|
689
835
|
}
|
|
690
836
|
resolveChannelValue(value) {
|
|
691
|
-
if (
|
|
837
|
+
if (isChannelRef(value)) return value.direction === "read" ? new ChannelReader(this.address, value) : new ChannelWriter(this.address, value);
|
|
692
838
|
if (Array.isArray(value)) return value.map((item) => this.resolveChannelValue(item));
|
|
693
839
|
if (value !== null && typeof value === "object") {
|
|
694
840
|
const out = {};
|
|
@@ -699,8 +845,8 @@ var Sdk = class {
|
|
|
699
845
|
}
|
|
700
846
|
async onInvokeFunction(invocation_id, function_id, input, traceparent, baggage) {
|
|
701
847
|
const fn = this.functions.get(function_id);
|
|
702
|
-
const getResponseTraceparent = () =>
|
|
703
|
-
const getResponseBaggage = () =>
|
|
848
|
+
const getResponseTraceparent = () => (0, _iii_dev_observability.injectTraceparent)() ?? traceparent;
|
|
849
|
+
const getResponseBaggage = () => (0, _iii_dev_observability.injectBaggage)() ?? baggage;
|
|
704
850
|
const resolvedInput = this.resolveChannelValue(input);
|
|
705
851
|
if (fn?.handler) {
|
|
706
852
|
if (!invocation_id) {
|
|
@@ -869,148 +1015,19 @@ const TriggerAction = {
|
|
|
869
1015
|
*/
|
|
870
1016
|
const registerWorker = (address, options) => new Sdk(address, options);
|
|
871
1017
|
|
|
872
|
-
//#endregion
|
|
873
|
-
//#region src/logger.ts
|
|
874
|
-
/**
|
|
875
|
-
* Structured logger that emits logs as OpenTelemetry LogRecords.
|
|
876
|
-
*
|
|
877
|
-
* Every log call automatically captures the active trace and span context,
|
|
878
|
-
* correlating your logs with distributed traces without any manual wiring.
|
|
879
|
-
* When OTel is not initialized, Logger gracefully falls back to `console.*`.
|
|
880
|
-
*
|
|
881
|
-
* Pass structured data as the second argument to any log method. Using an
|
|
882
|
-
* object of key-value pairs (instead of string interpolation) lets you
|
|
883
|
-
* filter, aggregate, and build dashboards in your observability backend.
|
|
884
|
-
*
|
|
885
|
-
* @example
|
|
886
|
-
* ```typescript
|
|
887
|
-
* import { Logger } from 'iii-sdk'
|
|
888
|
-
*
|
|
889
|
-
* const logger = new Logger()
|
|
890
|
-
*
|
|
891
|
-
* // Basic logging — trace context is injected automatically
|
|
892
|
-
* logger.info('Worker connected')
|
|
893
|
-
*
|
|
894
|
-
* // Structured context for dashboards and alerting
|
|
895
|
-
* logger.info('Order processed', { orderId: 'ord_123', amount: 49.99, currency: 'USD' })
|
|
896
|
-
* logger.warn('Retry attempt', { attempt: 3, maxRetries: 5, endpoint: '/api/charge' })
|
|
897
|
-
* logger.error('Payment failed', { orderId: 'ord_123', gateway: 'stripe', errorCode: 'card_declined' })
|
|
898
|
-
* ```
|
|
899
|
-
*/
|
|
900
|
-
var Logger = class {
|
|
901
|
-
get otelLogger() {
|
|
902
|
-
if (!this._otelLogger) this._otelLogger = require_telemetry_system.getLogger();
|
|
903
|
-
return this._otelLogger;
|
|
904
|
-
}
|
|
905
|
-
constructor(traceId, serviceName, spanId) {
|
|
906
|
-
this.traceId = traceId;
|
|
907
|
-
this.serviceName = serviceName;
|
|
908
|
-
this.spanId = spanId;
|
|
909
|
-
this._otelLogger = null;
|
|
910
|
-
}
|
|
911
|
-
emit(message, severity, data) {
|
|
912
|
-
const attributes = {};
|
|
913
|
-
const traceId = this.traceId ?? require_telemetry_system.currentTraceId();
|
|
914
|
-
const spanId = this.spanId ?? require_telemetry_system.currentSpanId();
|
|
915
|
-
if (traceId) attributes.trace_id = traceId;
|
|
916
|
-
if (spanId) attributes.span_id = spanId;
|
|
917
|
-
if (this.serviceName) attributes["service.name"] = this.serviceName;
|
|
918
|
-
if (data !== void 0) attributes["log.data"] = data;
|
|
919
|
-
if (this.otelLogger) this.otelLogger.emit({
|
|
920
|
-
severityNumber: severity,
|
|
921
|
-
body: message,
|
|
922
|
-
attributes: Object.keys(attributes).length > 0 ? attributes : void 0
|
|
923
|
-
});
|
|
924
|
-
else switch (severity) {
|
|
925
|
-
case _opentelemetry_api_logs.SeverityNumber.DEBUG:
|
|
926
|
-
console.debug(message, data);
|
|
927
|
-
break;
|
|
928
|
-
case _opentelemetry_api_logs.SeverityNumber.INFO:
|
|
929
|
-
console.info(message, data);
|
|
930
|
-
break;
|
|
931
|
-
case _opentelemetry_api_logs.SeverityNumber.WARN:
|
|
932
|
-
console.warn(message, data);
|
|
933
|
-
break;
|
|
934
|
-
case _opentelemetry_api_logs.SeverityNumber.ERROR:
|
|
935
|
-
console.error(message, data);
|
|
936
|
-
break;
|
|
937
|
-
default: console.log(message, data);
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
/**
|
|
941
|
-
* Log an info-level message.
|
|
942
|
-
*
|
|
943
|
-
* @param message - Human-readable log message.
|
|
944
|
-
* @param data - Structured context attached as OTel log attributes.
|
|
945
|
-
* Use key-value objects to enable filtering and aggregation in your
|
|
946
|
-
* observability backend (e.g. Grafana, Datadog, New Relic).
|
|
947
|
-
*
|
|
948
|
-
* @example
|
|
949
|
-
* ```typescript
|
|
950
|
-
* logger.info('Order processed', { orderId: 'ord_123', status: 'completed' })
|
|
951
|
-
* ```
|
|
952
|
-
*/
|
|
953
|
-
info(message, data) {
|
|
954
|
-
this.emit(message, _opentelemetry_api_logs.SeverityNumber.INFO, data);
|
|
955
|
-
}
|
|
956
|
-
/**
|
|
957
|
-
* Log a warning-level message.
|
|
958
|
-
*
|
|
959
|
-
* @param message - Human-readable log message.
|
|
960
|
-
* @param data - Structured context attached as OTel log attributes.
|
|
961
|
-
* Use key-value objects to enable filtering and aggregation in your
|
|
962
|
-
* observability backend (e.g. Grafana, Datadog, New Relic).
|
|
963
|
-
*
|
|
964
|
-
* @example
|
|
965
|
-
* ```typescript
|
|
966
|
-
* logger.warn('Retry attempt', { attempt: 3, maxRetries: 5, endpoint: '/api/charge' })
|
|
967
|
-
* ```
|
|
968
|
-
*/
|
|
969
|
-
warn(message, data) {
|
|
970
|
-
this.emit(message, _opentelemetry_api_logs.SeverityNumber.WARN, data);
|
|
971
|
-
}
|
|
972
|
-
/**
|
|
973
|
-
* Log an error-level message.
|
|
974
|
-
*
|
|
975
|
-
* @param message - Human-readable log message.
|
|
976
|
-
* @param data - Structured context attached as OTel log attributes.
|
|
977
|
-
* Use key-value objects to enable filtering and aggregation in your
|
|
978
|
-
* observability backend (e.g. Grafana, Datadog, New Relic).
|
|
979
|
-
*
|
|
980
|
-
* @example
|
|
981
|
-
* ```typescript
|
|
982
|
-
* logger.error('Payment failed', { orderId: 'ord_123', gateway: 'stripe', errorCode: 'card_declined' })
|
|
983
|
-
* ```
|
|
984
|
-
*/
|
|
985
|
-
error(message, data) {
|
|
986
|
-
this.emit(message, _opentelemetry_api_logs.SeverityNumber.ERROR, data);
|
|
987
|
-
}
|
|
988
|
-
/**
|
|
989
|
-
* Log a debug-level message.
|
|
990
|
-
*
|
|
991
|
-
* @param message - Human-readable log message.
|
|
992
|
-
* @param data - Structured context attached as OTel log attributes.
|
|
993
|
-
* Use key-value objects to enable filtering and aggregation in your
|
|
994
|
-
* observability backend (e.g. Grafana, Datadog, New Relic).
|
|
995
|
-
*
|
|
996
|
-
* @example
|
|
997
|
-
* ```typescript
|
|
998
|
-
* logger.debug('Cache lookup', { key: 'user:42', hit: false })
|
|
999
|
-
* ```
|
|
1000
|
-
*/
|
|
1001
|
-
debug(message, data) {
|
|
1002
|
-
this.emit(message, _opentelemetry_api_logs.SeverityNumber.DEBUG, data);
|
|
1003
|
-
}
|
|
1004
|
-
};
|
|
1005
|
-
|
|
1006
1018
|
//#endregion
|
|
1007
1019
|
exports.ChannelReader = ChannelReader;
|
|
1008
1020
|
exports.ChannelWriter = ChannelWriter;
|
|
1009
|
-
exports.EngineFunctions =
|
|
1010
|
-
exports.EngineTriggers =
|
|
1021
|
+
exports.EngineFunctions = EngineFunctions;
|
|
1022
|
+
exports.EngineTriggers = EngineTriggers;
|
|
1011
1023
|
exports.IIIInvocationError = IIIInvocationError;
|
|
1012
|
-
exports
|
|
1024
|
+
Object.defineProperty(exports, 'Logger', {
|
|
1025
|
+
enumerable: true,
|
|
1026
|
+
get: function () {
|
|
1027
|
+
return _iii_dev_observability.Logger;
|
|
1028
|
+
}
|
|
1029
|
+
});
|
|
1013
1030
|
exports.TriggerAction = TriggerAction;
|
|
1014
|
-
exports.http =
|
|
1031
|
+
exports.http = http;
|
|
1015
1032
|
exports.registerWorker = registerWorker;
|
|
1016
1033
|
//# sourceMappingURL=index.cjs.map
|