@safaricom-mxl/node-sdk 0.0.4 → 0.0.6
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 +47 -0
- package/dist/bin/opentelemetry-instrument.mjs.map +1 -1
- package/dist/evlog-CH_6gpmQ.d.mts +79 -0
- package/dist/evlog-CH_6gpmQ.d.mts.map +1 -0
- package/dist/evlog-DvsAz_rb.d.cts +79 -0
- package/dist/evlog-DvsAz_rb.d.cts.map +1 -0
- package/dist/{express-CLWLFQm8.d.mts → express-BeB-smIq.d.cts} +1 -1
- package/dist/{express-CLWLFQm8.d.mts.map → express-BeB-smIq.d.cts.map} +1 -1
- package/dist/{express-Cj1ZLCDj.d.cts → express-C-LJyIUK.d.mts} +1 -1
- package/dist/{express-Cj1ZLCDj.d.cts.map → express-C-LJyIUK.d.mts.map} +1 -1
- package/dist/{fastify-BVTjoDkf.d.cts → fastify-BZOZZ-r0.d.cts} +1 -1
- package/dist/{fastify-BVTjoDkf.d.cts.map → fastify-BZOZZ-r0.d.cts.map} +1 -1
- package/dist/{fastify-DBFqGr9t.d.mts → fastify-sycEaX9R.d.mts} +1 -1
- package/dist/{fastify-DBFqGr9t.d.mts.map → fastify-sycEaX9R.d.mts.map} +1 -1
- package/dist/gcp.cjs +1 -1
- package/dist/gcp.mjs +1 -1
- package/dist/gcp.mjs.map +1 -1
- package/dist/index-BE3hEgxP.d.cts +38 -0
- package/dist/index-BE3hEgxP.d.cts.map +1 -0
- package/dist/index-BUVGlo0B.d.mts +39 -0
- package/dist/index-BUVGlo0B.d.mts.map +1 -0
- package/dist/index.cjs +15 -2
- package/dist/index.d.cts +10 -9
- package/dist/index.d.mts +10 -9
- package/dist/index.mjs +10 -3
- package/dist/index.mjs.map +1 -1
- package/dist/{initSDK-DrtNZ8f7.mjs → initSDK-Cyp1Wde9.mjs} +8 -3
- package/dist/{initSDK-DrtNZ8f7.mjs.map → initSDK-Cyp1Wde9.mjs.map} +1 -1
- package/dist/{initSDK-CP9OZaQV.cjs → initSDK-cyZkd_w_.cjs} +12 -1
- package/dist/integrations/express.d.cts +1 -1
- package/dist/integrations/express.d.mts +1 -1
- package/dist/integrations/express.mjs.map +1 -1
- package/dist/integrations/fastify.d.cts +1 -1
- package/dist/integrations/fastify.d.mts +1 -1
- package/dist/integrations/fastify.mjs.map +1 -1
- package/dist/integrations/koa.d.cts +1 -1
- package/dist/integrations/koa.d.mts +1 -1
- package/dist/integrations/koa.mjs.map +1 -1
- package/dist/integrations/nest.d.cts +1 -1
- package/dist/integrations/nest.d.mts +1 -1
- package/dist/integrations/nest.mjs.map +1 -1
- package/dist/json-QBn3zdPA.mjs.map +1 -1
- package/dist/{koa-Biu2GTHr.d.mts → koa-Bajo6M9q.d.cts} +1 -1
- package/dist/{koa-Biu2GTHr.d.mts.map → koa-Bajo6M9q.d.cts.map} +1 -1
- package/dist/{koa-D-MCikIv.d.cts → koa-DstGyKUK.d.mts} +1 -1
- package/dist/{koa-D-MCikIv.d.cts.map → koa-DstGyKUK.d.mts.map} +1 -1
- package/dist/logger/evlog.cjs +200 -0
- package/dist/logger/evlog.d.cts +2 -0
- package/dist/logger/evlog.d.mts +2 -0
- package/dist/logger/evlog.mjs +196 -0
- package/dist/logger/evlog.mjs.map +1 -0
- package/dist/logger/nest.cjs +1 -1
- package/dist/logger/nest.d.cts +1 -1
- package/dist/logger/nest.d.mts +1 -1
- package/dist/logger/nest.mjs +1 -1
- package/dist/logger/nest.mjs.map +1 -1
- package/dist/logger/pino.cjs +1 -1
- package/dist/logger/pino.d.cts +1 -1
- package/dist/logger/pino.d.mts +1 -1
- package/dist/logger/pino.mjs +1 -1
- package/dist/logger/pino.mjs.map +1 -1
- package/dist/logger/winston.cjs +1 -1
- package/dist/logger/winston.d.cts +1 -1
- package/dist/logger/winston.d.mts +1 -1
- package/dist/logger/winston.mjs +1 -1
- package/dist/logger/winston.mjs.map +1 -1
- package/dist/{nest-8fGolGKU.d.cts → nest-B4NftW3t.d.cts} +2 -2
- package/dist/{nest-8fGolGKU.d.cts.map → nest-B4NftW3t.d.cts.map} +1 -1
- package/dist/{nest-DoaslSU9.d.mts → nest-BTWrtcoq.d.mts} +2 -2
- package/dist/{nest-DoaslSU9.d.mts.map → nest-BTWrtcoq.d.mts.map} +1 -1
- package/dist/nest-BgK5ExdL.d.cts +8 -0
- package/dist/nest-BgK5ExdL.d.cts.map +1 -0
- package/dist/nest-BxEonYFS.d.mts +8 -0
- package/dist/nest-BxEonYFS.d.mts.map +1 -0
- package/dist/{otelLogger-OaUZ4WM-.mjs → otelLogger-B0HIri4C.mjs} +11 -8
- package/dist/otelLogger-B0HIri4C.mjs.map +1 -0
- package/dist/{otelLogger-Dy0B0trY.cjs → otelLogger-CmKOazp1.cjs} +10 -7
- package/dist/{pino-D7auf2MT.d.cts → pino-BeU47K6T.d.cts} +2 -2
- package/dist/{pino-C6bjSUsz.d.mts.map → pino-BeU47K6T.d.cts.map} +1 -1
- package/dist/{pino-C6bjSUsz.d.mts → pino-RSK75gR8.d.mts} +2 -2
- package/dist/{pino-D7auf2MT.d.cts.map → pino-RSK75gR8.d.mts.map} +1 -1
- package/dist/recordException-DTpcLbsC.mjs.map +1 -1
- package/dist/tracing.cjs +2 -1
- package/dist/tracing.d.cts +2 -2
- package/dist/tracing.d.mts +2 -2
- package/dist/tracing.mjs +2 -2
- package/dist/{types-eRx3m74r.d.mts → types-B0hlS5Sc.d.mts} +1 -1
- package/dist/types-B0hlS5Sc.d.mts.map +1 -0
- package/dist/{types-Cyf1jR-y.d.cts → types-v-UbM69o.d.cts} +1 -1
- package/dist/types-v-UbM69o.d.cts.map +1 -0
- package/dist/{winston-BmrGTNPn.d.mts → winston-BY2kow_r.d.mts} +2 -2
- package/dist/{winston-BmrGTNPn.d.mts.map → winston-BY2kow_r.d.mts.map} +1 -1
- package/dist/{winston-CXKGLjdf.d.cts → winston-DZHe-bDF.d.cts} +2 -2
- package/dist/{winston-CXKGLjdf.d.cts.map → winston-DZHe-bDF.d.cts.map} +1 -1
- package/package.json +29 -15
- package/dist/index-BiEiY6la.d.cts +0 -58
- package/dist/index-BiEiY6la.d.cts.map +0 -1
- package/dist/index-C5mT0cHC.d.mts +0 -59
- package/dist/index-C5mT0cHC.d.mts.map +0 -1
- package/dist/nest-D7aV2zUX.d.mts +0 -8
- package/dist/nest-D7aV2zUX.d.mts.map +0 -1
- package/dist/nest-S5fGO5wf.d.cts +0 -8
- package/dist/nest-S5fGO5wf.d.cts.map +0 -1
- package/dist/otelLogger-OaUZ4WM-.mjs.map +0 -1
- package/dist/types-Cyf1jR-y.d.cts.map +0 -1
- package/dist/types-eRx3m74r.d.mts.map +0 -1
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("../chunk-CKQMccvm.cjs");
|
|
3
|
+
const require_initSDK = require("../initSDK-cyZkd_w_.cjs");
|
|
4
|
+
const require_otelLogger = require("../otelLogger-CmKOazp1.cjs");
|
|
5
|
+
let _opentelemetry_api = require("@opentelemetry/api");
|
|
6
|
+
let evlog = require("evlog");
|
|
7
|
+
//#region src/logger/evlog.ts
|
|
8
|
+
const LEVEL_SEVERITY = {
|
|
9
|
+
debug: {
|
|
10
|
+
number: 5,
|
|
11
|
+
text: "DEBUG"
|
|
12
|
+
},
|
|
13
|
+
info: {
|
|
14
|
+
number: 9,
|
|
15
|
+
text: "INFO"
|
|
16
|
+
},
|
|
17
|
+
warn: {
|
|
18
|
+
number: 13,
|
|
19
|
+
text: "WARN"
|
|
20
|
+
},
|
|
21
|
+
error: {
|
|
22
|
+
number: 17,
|
|
23
|
+
text: "ERROR"
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const FLATTEN_MAX_DEPTH = 10;
|
|
27
|
+
let fallbackOTelLogger;
|
|
28
|
+
function resolveOTelLogger(options) {
|
|
29
|
+
if (options?.otelLogger) return options.otelLogger;
|
|
30
|
+
const initialized = require_initSDK.getInitializedOTelLogger();
|
|
31
|
+
if (initialized) return initialized;
|
|
32
|
+
if (!fallbackOTelLogger) fallbackOTelLogger = new require_otelLogger.OTelLogger({
|
|
33
|
+
config: options?.config ?? require_initSDK.getActiveSDKConfig() ?? require_initSDK.resolveSDKConfig(),
|
|
34
|
+
resourceAttributes: options?.resourceAttributes
|
|
35
|
+
});
|
|
36
|
+
return fallbackOTelLogger;
|
|
37
|
+
}
|
|
38
|
+
function appendFlatten(value, prefix, out, depth) {
|
|
39
|
+
if (depth > FLATTEN_MAX_DEPTH) {
|
|
40
|
+
out[prefix] = typeof value === "string" ? value : JSON.stringify(value);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (value === void 0 || value === null) return;
|
|
44
|
+
const t = typeof value;
|
|
45
|
+
if (t === "string" || t === "number" || t === "boolean") {
|
|
46
|
+
out[prefix] = value;
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (Array.isArray(value)) {
|
|
50
|
+
out[prefix] = JSON.stringify(value);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (t === "object") for (const [k, v] of Object.entries(value)) appendFlatten(v, `${prefix}.${k}`, out, depth + 1);
|
|
54
|
+
}
|
|
55
|
+
function durationToMs(duration) {
|
|
56
|
+
if (duration == null) return;
|
|
57
|
+
if (typeof duration === "number" && Number.isFinite(duration)) return duration;
|
|
58
|
+
if (typeof duration === "string") {
|
|
59
|
+
const s = duration.trim();
|
|
60
|
+
const msMatch = s.match(/^([\d.]+)\s*ms$/i);
|
|
61
|
+
if (msMatch) return Math.round(Number.parseFloat(msMatch[1]));
|
|
62
|
+
const secMatch = s.match(/^([\d.]+)\s*s$/i);
|
|
63
|
+
if (secMatch) return Math.round(Number.parseFloat(secMatch[1]) * 1e3);
|
|
64
|
+
const n = Number.parseFloat(s);
|
|
65
|
+
if (!Number.isNaN(n)) return Math.round(n);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function buildEvlogBody(event) {
|
|
69
|
+
const rec = event;
|
|
70
|
+
const method = typeof rec.method === "string" ? rec.method : "EVENT";
|
|
71
|
+
const path = typeof rec.path === "string" ? rec.path : "";
|
|
72
|
+
const status = rec.status != null ? String(rec.status) : "";
|
|
73
|
+
const duration = rec.duration != null ? String(rec.duration) : "";
|
|
74
|
+
return [
|
|
75
|
+
method,
|
|
76
|
+
path,
|
|
77
|
+
status,
|
|
78
|
+
duration ? `in ${duration}` : ""
|
|
79
|
+
].filter(Boolean).join(" ");
|
|
80
|
+
}
|
|
81
|
+
function promoteAuditFields(audit, attrs) {
|
|
82
|
+
attrs["audit.action"] = audit.action;
|
|
83
|
+
attrs["audit.outcome"] = audit.outcome;
|
|
84
|
+
attrs["audit.actor.type"] = audit.actor.type;
|
|
85
|
+
attrs["audit.actor.id"] = audit.actor.id;
|
|
86
|
+
if (audit.actor.email) attrs["audit.actor.email"] = audit.actor.email;
|
|
87
|
+
if (audit.actor.displayName) attrs["audit.actor.displayName"] = audit.actor.displayName;
|
|
88
|
+
if (audit.target?.type) attrs["audit.target.type"] = audit.target.type;
|
|
89
|
+
if (audit.target?.id) attrs["audit.target.id"] = audit.target.id;
|
|
90
|
+
if (audit.reason) attrs["audit.reason"] = audit.reason;
|
|
91
|
+
if (audit.idempotencyKey) attrs["audit.idempotencyKey"] = audit.idempotencyKey;
|
|
92
|
+
const ctxTrace = audit.context?.traceId;
|
|
93
|
+
if (typeof ctxTrace === "string") attrs["audit.context.traceId"] = ctxTrace;
|
|
94
|
+
if (audit.signature) attrs["audit.signature"] = audit.signature;
|
|
95
|
+
if (audit.prevHash) attrs["audit.prevHash"] = audit.prevHash;
|
|
96
|
+
if (audit.hash) attrs["audit.hash"] = audit.hash;
|
|
97
|
+
}
|
|
98
|
+
function attachTraceCorrelation(event, attrs) {
|
|
99
|
+
const traceId = typeof event.traceId === "string" ? event.traceId : void 0;
|
|
100
|
+
const spanId = typeof event.spanId === "string" ? event.spanId : void 0;
|
|
101
|
+
const tc = event.traceContext;
|
|
102
|
+
const traceFlags = typeof tc?.traceFlags === "number" ? tc.traceFlags : 1;
|
|
103
|
+
if (traceId) attrs.trace_id = traceId;
|
|
104
|
+
if (spanId) attrs.span_id = spanId;
|
|
105
|
+
if (traceId && spanId) attrs.trace_flags = traceFlags;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Map an evlog {@link WideEvent} to OTLP log fields for {@link OTelLogger.postMessage}.
|
|
109
|
+
*/
|
|
110
|
+
function parseEvlogEvent(event, ctx, options) {
|
|
111
|
+
const auditMode = options?.auditMode ?? false;
|
|
112
|
+
const levelKey = typeof event.level === "string" ? event.level : "info";
|
|
113
|
+
const levelSeverity = LEVEL_SEVERITY[levelKey] ?? LEVEL_SEVERITY.info;
|
|
114
|
+
const attributes = {};
|
|
115
|
+
const rec = event;
|
|
116
|
+
for (const [key, value] of Object.entries(rec)) appendFlatten(value, `mxl.${key}`, attributes, 0);
|
|
117
|
+
attributes["mxl.kind"] = auditMode ? "audit-event" : "wide-event";
|
|
118
|
+
const requestId = ctx?.request?.requestId ?? (typeof rec.requestId === "string" ? rec.requestId : void 0);
|
|
119
|
+
if (requestId) attributes["mxl.request_id"] = requestId;
|
|
120
|
+
const durationMs = durationToMs(rec.duration);
|
|
121
|
+
if (durationMs != null) attributes["mxl.duration_ms"] = durationMs;
|
|
122
|
+
if (rec.status != null) attributes["mxl.status"] = rec.status;
|
|
123
|
+
attachTraceCorrelation(event, attributes);
|
|
124
|
+
let emitOpts;
|
|
125
|
+
if (auditMode) {
|
|
126
|
+
emitOpts = {
|
|
127
|
+
scope: options?.scope ?? "mxl.audit",
|
|
128
|
+
severityNumber: 17,
|
|
129
|
+
severityText: "AUDIT"
|
|
130
|
+
};
|
|
131
|
+
if (event.audit) promoteAuditFields(event.audit, attributes);
|
|
132
|
+
} else emitOpts = {
|
|
133
|
+
scope: options?.scope ?? "mxl",
|
|
134
|
+
severityNumber: levelSeverity.number,
|
|
135
|
+
severityText: levelSeverity.text
|
|
136
|
+
};
|
|
137
|
+
return {
|
|
138
|
+
levelLabel: levelKey,
|
|
139
|
+
body: buildEvlogBody(event),
|
|
140
|
+
attributes,
|
|
141
|
+
emitOpts
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
var OTelEvlogBridge = class {
|
|
145
|
+
options;
|
|
146
|
+
constructor(options) {
|
|
147
|
+
this.options = options;
|
|
148
|
+
}
|
|
149
|
+
emit(ctx) {
|
|
150
|
+
const otel = resolveOTelLogger(this.options);
|
|
151
|
+
const parsed = parseEvlogEvent(ctx.event, ctx, {
|
|
152
|
+
...this.options,
|
|
153
|
+
auditMode: this.options?.auditMode ?? false
|
|
154
|
+
});
|
|
155
|
+
otel.postMessage(parsed.levelLabel, parsed.body, parsed.attributes, parsed.emitOpts);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* mxl drain that forwards wide events through the MXL {@link OTelLogger}
|
|
160
|
+
* pipeline (same batching/export path as {@link initSDK} when initialized).
|
|
161
|
+
*/
|
|
162
|
+
function createEvlogDrain(options) {
|
|
163
|
+
const bridge = new OTelEvlogBridge(options);
|
|
164
|
+
return async (ctx) => {
|
|
165
|
+
bridge.emit(ctx);
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Enrich mxl wide events with trace id / span id from the active OpenTelemetry span.
|
|
170
|
+
*/
|
|
171
|
+
function createOtelTraceEnricher(opts = {}) {
|
|
172
|
+
return (ctx) => {
|
|
173
|
+
const sc = _opentelemetry_api.trace.getSpan(_opentelemetry_api.context.active())?.spanContext();
|
|
174
|
+
if (!sc || !(0, _opentelemetry_api.isSpanContextValid)(sc)) return;
|
|
175
|
+
if (opts.overwrite || ctx.event.traceId == null) ctx.event.traceId = sc.traceId;
|
|
176
|
+
if (opts.overwrite || ctx.event.spanId == null) ctx.event.spanId = sc.spanId;
|
|
177
|
+
ctx.event.traceContext = {
|
|
178
|
+
...ctx.event.traceContext,
|
|
179
|
+
traceId: sc.traceId,
|
|
180
|
+
spanId: sc.spanId,
|
|
181
|
+
traceFlags: sc.traceFlags
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Routes only audit-bearing wide events to OTLP under scope `mxl.audit`.
|
|
187
|
+
*/
|
|
188
|
+
function createAuditOtelDrain(options) {
|
|
189
|
+
return (0, evlog.auditOnly)(createEvlogDrain({
|
|
190
|
+
...options,
|
|
191
|
+
auditMode: true,
|
|
192
|
+
scope: options?.scope ?? "mxl.audit"
|
|
193
|
+
}), { await: true });
|
|
194
|
+
}
|
|
195
|
+
//#endregion
|
|
196
|
+
exports.OTelEvlogBridge = OTelEvlogBridge;
|
|
197
|
+
exports.createAuditOtelDrain = createAuditOtelDrain;
|
|
198
|
+
exports.createEvlogDrain = createEvlogDrain;
|
|
199
|
+
exports.createOtelTraceEnricher = createOtelTraceEnricher;
|
|
200
|
+
exports.parseEvlogEvent = parseEvlogEvent;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as createEvlogDrain, i as createAuditOtelDrain, n as OTelEvlogBridge, o as createOtelTraceEnricher, r as ParsedEvlogEmit, s as parseEvlogEvent, t as EvlogDrainOptions } from "../evlog-DvsAz_rb.cjs";
|
|
2
|
+
export { EvlogDrainOptions, OTelEvlogBridge, ParsedEvlogEmit, createAuditOtelDrain, createEvlogDrain, createOtelTraceEnricher, parseEvlogEvent };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as createEvlogDrain, i as createAuditOtelDrain, n as OTelEvlogBridge, o as createOtelTraceEnricher, r as ParsedEvlogEmit, s as parseEvlogEvent, t as EvlogDrainOptions } from "../evlog-CH_6gpmQ.mjs";
|
|
2
|
+
export { EvlogDrainOptions, OTelEvlogBridge, ParsedEvlogEmit, createAuditOtelDrain, createEvlogDrain, createOtelTraceEnricher, parseEvlogEvent };
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { a as getActiveSDKConfig, n as getInitializedOTelLogger, o as resolveSDKConfig } from "../initSDK-Cyp1Wde9.mjs";
|
|
2
|
+
import { t as OTelLogger } from "../otelLogger-B0HIri4C.mjs";
|
|
3
|
+
import { context, isSpanContextValid, trace } from "@opentelemetry/api";
|
|
4
|
+
import { auditOnly } from "evlog";
|
|
5
|
+
//#region src/logger/evlog.ts
|
|
6
|
+
const LEVEL_SEVERITY = {
|
|
7
|
+
debug: {
|
|
8
|
+
number: 5,
|
|
9
|
+
text: "DEBUG"
|
|
10
|
+
},
|
|
11
|
+
info: {
|
|
12
|
+
number: 9,
|
|
13
|
+
text: "INFO"
|
|
14
|
+
},
|
|
15
|
+
warn: {
|
|
16
|
+
number: 13,
|
|
17
|
+
text: "WARN"
|
|
18
|
+
},
|
|
19
|
+
error: {
|
|
20
|
+
number: 17,
|
|
21
|
+
text: "ERROR"
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const FLATTEN_MAX_DEPTH = 10;
|
|
25
|
+
let fallbackOTelLogger;
|
|
26
|
+
function resolveOTelLogger(options) {
|
|
27
|
+
if (options?.otelLogger) return options.otelLogger;
|
|
28
|
+
const initialized = getInitializedOTelLogger();
|
|
29
|
+
if (initialized) return initialized;
|
|
30
|
+
if (!fallbackOTelLogger) fallbackOTelLogger = new OTelLogger({
|
|
31
|
+
config: options?.config ?? getActiveSDKConfig() ?? resolveSDKConfig(),
|
|
32
|
+
resourceAttributes: options?.resourceAttributes
|
|
33
|
+
});
|
|
34
|
+
return fallbackOTelLogger;
|
|
35
|
+
}
|
|
36
|
+
function appendFlatten(value, prefix, out, depth) {
|
|
37
|
+
if (depth > FLATTEN_MAX_DEPTH) {
|
|
38
|
+
out[prefix] = typeof value === "string" ? value : JSON.stringify(value);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (value === void 0 || value === null) return;
|
|
42
|
+
const t = typeof value;
|
|
43
|
+
if (t === "string" || t === "number" || t === "boolean") {
|
|
44
|
+
out[prefix] = value;
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (Array.isArray(value)) {
|
|
48
|
+
out[prefix] = JSON.stringify(value);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (t === "object") for (const [k, v] of Object.entries(value)) appendFlatten(v, `${prefix}.${k}`, out, depth + 1);
|
|
52
|
+
}
|
|
53
|
+
function durationToMs(duration) {
|
|
54
|
+
if (duration == null) return;
|
|
55
|
+
if (typeof duration === "number" && Number.isFinite(duration)) return duration;
|
|
56
|
+
if (typeof duration === "string") {
|
|
57
|
+
const s = duration.trim();
|
|
58
|
+
const msMatch = s.match(/^([\d.]+)\s*ms$/i);
|
|
59
|
+
if (msMatch) return Math.round(Number.parseFloat(msMatch[1]));
|
|
60
|
+
const secMatch = s.match(/^([\d.]+)\s*s$/i);
|
|
61
|
+
if (secMatch) return Math.round(Number.parseFloat(secMatch[1]) * 1e3);
|
|
62
|
+
const n = Number.parseFloat(s);
|
|
63
|
+
if (!Number.isNaN(n)) return Math.round(n);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function buildEvlogBody(event) {
|
|
67
|
+
const rec = event;
|
|
68
|
+
const method = typeof rec.method === "string" ? rec.method : "EVENT";
|
|
69
|
+
const path = typeof rec.path === "string" ? rec.path : "";
|
|
70
|
+
const status = rec.status != null ? String(rec.status) : "";
|
|
71
|
+
const duration = rec.duration != null ? String(rec.duration) : "";
|
|
72
|
+
return [
|
|
73
|
+
method,
|
|
74
|
+
path,
|
|
75
|
+
status,
|
|
76
|
+
duration ? `in ${duration}` : ""
|
|
77
|
+
].filter(Boolean).join(" ");
|
|
78
|
+
}
|
|
79
|
+
function promoteAuditFields(audit, attrs) {
|
|
80
|
+
attrs["audit.action"] = audit.action;
|
|
81
|
+
attrs["audit.outcome"] = audit.outcome;
|
|
82
|
+
attrs["audit.actor.type"] = audit.actor.type;
|
|
83
|
+
attrs["audit.actor.id"] = audit.actor.id;
|
|
84
|
+
if (audit.actor.email) attrs["audit.actor.email"] = audit.actor.email;
|
|
85
|
+
if (audit.actor.displayName) attrs["audit.actor.displayName"] = audit.actor.displayName;
|
|
86
|
+
if (audit.target?.type) attrs["audit.target.type"] = audit.target.type;
|
|
87
|
+
if (audit.target?.id) attrs["audit.target.id"] = audit.target.id;
|
|
88
|
+
if (audit.reason) attrs["audit.reason"] = audit.reason;
|
|
89
|
+
if (audit.idempotencyKey) attrs["audit.idempotencyKey"] = audit.idempotencyKey;
|
|
90
|
+
const ctxTrace = audit.context?.traceId;
|
|
91
|
+
if (typeof ctxTrace === "string") attrs["audit.context.traceId"] = ctxTrace;
|
|
92
|
+
if (audit.signature) attrs["audit.signature"] = audit.signature;
|
|
93
|
+
if (audit.prevHash) attrs["audit.prevHash"] = audit.prevHash;
|
|
94
|
+
if (audit.hash) attrs["audit.hash"] = audit.hash;
|
|
95
|
+
}
|
|
96
|
+
function attachTraceCorrelation(event, attrs) {
|
|
97
|
+
const traceId = typeof event.traceId === "string" ? event.traceId : void 0;
|
|
98
|
+
const spanId = typeof event.spanId === "string" ? event.spanId : void 0;
|
|
99
|
+
const tc = event.traceContext;
|
|
100
|
+
const traceFlags = typeof tc?.traceFlags === "number" ? tc.traceFlags : 1;
|
|
101
|
+
if (traceId) attrs.trace_id = traceId;
|
|
102
|
+
if (spanId) attrs.span_id = spanId;
|
|
103
|
+
if (traceId && spanId) attrs.trace_flags = traceFlags;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Map an evlog {@link WideEvent} to OTLP log fields for {@link OTelLogger.postMessage}.
|
|
107
|
+
*/
|
|
108
|
+
function parseEvlogEvent(event, ctx, options) {
|
|
109
|
+
const auditMode = options?.auditMode ?? false;
|
|
110
|
+
const levelKey = typeof event.level === "string" ? event.level : "info";
|
|
111
|
+
const levelSeverity = LEVEL_SEVERITY[levelKey] ?? LEVEL_SEVERITY.info;
|
|
112
|
+
const attributes = {};
|
|
113
|
+
const rec = event;
|
|
114
|
+
for (const [key, value] of Object.entries(rec)) appendFlatten(value, `mxl.${key}`, attributes, 0);
|
|
115
|
+
attributes["mxl.kind"] = auditMode ? "audit-event" : "wide-event";
|
|
116
|
+
const requestId = ctx?.request?.requestId ?? (typeof rec.requestId === "string" ? rec.requestId : void 0);
|
|
117
|
+
if (requestId) attributes["mxl.request_id"] = requestId;
|
|
118
|
+
const durationMs = durationToMs(rec.duration);
|
|
119
|
+
if (durationMs != null) attributes["mxl.duration_ms"] = durationMs;
|
|
120
|
+
if (rec.status != null) attributes["mxl.status"] = rec.status;
|
|
121
|
+
attachTraceCorrelation(event, attributes);
|
|
122
|
+
let emitOpts;
|
|
123
|
+
if (auditMode) {
|
|
124
|
+
emitOpts = {
|
|
125
|
+
scope: options?.scope ?? "mxl.audit",
|
|
126
|
+
severityNumber: 17,
|
|
127
|
+
severityText: "AUDIT"
|
|
128
|
+
};
|
|
129
|
+
if (event.audit) promoteAuditFields(event.audit, attributes);
|
|
130
|
+
} else emitOpts = {
|
|
131
|
+
scope: options?.scope ?? "mxl",
|
|
132
|
+
severityNumber: levelSeverity.number,
|
|
133
|
+
severityText: levelSeverity.text
|
|
134
|
+
};
|
|
135
|
+
return {
|
|
136
|
+
levelLabel: levelKey,
|
|
137
|
+
body: buildEvlogBody(event),
|
|
138
|
+
attributes,
|
|
139
|
+
emitOpts
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
var OTelEvlogBridge = class {
|
|
143
|
+
options;
|
|
144
|
+
constructor(options) {
|
|
145
|
+
this.options = options;
|
|
146
|
+
}
|
|
147
|
+
emit(ctx) {
|
|
148
|
+
const otel = resolveOTelLogger(this.options);
|
|
149
|
+
const parsed = parseEvlogEvent(ctx.event, ctx, {
|
|
150
|
+
...this.options,
|
|
151
|
+
auditMode: this.options?.auditMode ?? false
|
|
152
|
+
});
|
|
153
|
+
otel.postMessage(parsed.levelLabel, parsed.body, parsed.attributes, parsed.emitOpts);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* mxl drain that forwards wide events through the MXL {@link OTelLogger}
|
|
158
|
+
* pipeline (same batching/export path as {@link initSDK} when initialized).
|
|
159
|
+
*/
|
|
160
|
+
function createEvlogDrain(options) {
|
|
161
|
+
const bridge = new OTelEvlogBridge(options);
|
|
162
|
+
return async (ctx) => {
|
|
163
|
+
bridge.emit(ctx);
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Enrich mxl wide events with trace id / span id from the active OpenTelemetry span.
|
|
168
|
+
*/
|
|
169
|
+
function createOtelTraceEnricher(opts = {}) {
|
|
170
|
+
return (ctx) => {
|
|
171
|
+
const sc = trace.getSpan(context.active())?.spanContext();
|
|
172
|
+
if (!sc || !isSpanContextValid(sc)) return;
|
|
173
|
+
if (opts.overwrite || ctx.event.traceId == null) ctx.event.traceId = sc.traceId;
|
|
174
|
+
if (opts.overwrite || ctx.event.spanId == null) ctx.event.spanId = sc.spanId;
|
|
175
|
+
ctx.event.traceContext = {
|
|
176
|
+
...ctx.event.traceContext,
|
|
177
|
+
traceId: sc.traceId,
|
|
178
|
+
spanId: sc.spanId,
|
|
179
|
+
traceFlags: sc.traceFlags
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Routes only audit-bearing wide events to OTLP under scope `mxl.audit`.
|
|
185
|
+
*/
|
|
186
|
+
function createAuditOtelDrain(options) {
|
|
187
|
+
return auditOnly(createEvlogDrain({
|
|
188
|
+
...options,
|
|
189
|
+
auditMode: true,
|
|
190
|
+
scope: options?.scope ?? "mxl.audit"
|
|
191
|
+
}), { await: true });
|
|
192
|
+
}
|
|
193
|
+
//#endregion
|
|
194
|
+
export { OTelEvlogBridge, createAuditOtelDrain, createEvlogDrain, createOtelTraceEnricher, parseEvlogEvent };
|
|
195
|
+
|
|
196
|
+
//# sourceMappingURL=evlog.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evlog.mjs","names":[],"sources":["../../src/logger/evlog.ts"],"sourcesContent":["import type { Attributes } from '@opentelemetry/api';\nimport {\n context,\n trace,\n isSpanContextValid,\n} from '@opentelemetry/api';\nimport type {\n AuditFields,\n DrainContext,\n EnrichContext,\n WideEvent,\n} from 'evlog';\nimport { auditOnly } from 'evlog';\nimport { OTelLogger, type OTelLogEmitOptions } from './otelLogger.ts';\nimport type { ResolvedSDKConfig } from '../sdk/types.ts';\nimport { resolveSDKConfig } from '../sdk/config.ts';\nimport { getActiveSDKConfig } from '../sdk/state.ts';\nimport { getInitializedOTelLogger } from '../sdk/initSDK.ts';\n\nconst LEVEL_SEVERITY: Record<\n string,\n { number: number; text: string }\n> = {\n debug: { number: 5, text: 'DEBUG' },\n info: { number: 9, text: 'INFO' },\n warn: { number: 13, text: 'WARN' },\n error: { number: 17, text: 'ERROR' },\n};\n\nconst FLATTEN_MAX_DEPTH = 10;\n\nexport type EvlogDrainOptions = {\n config?: ResolvedSDKConfig;\n resourceAttributes?: Attributes;\n otelLogger?: OTelLogger;\n /** OTLP instrumentation scope name. */\n scope?: string;\n /** Emit audit-shaped records (severity AUDIT, promoted audit.* attributes). */\n auditMode?: boolean;\n};\n\nexport type ParsedEvlogEmit = {\n levelLabel: string;\n body: string;\n attributes: Attributes;\n emitOpts: OTelLogEmitOptions;\n};\n\nlet fallbackOTelLogger: OTelLogger | undefined;\n\nfunction resolveOTelLogger(options?: EvlogDrainOptions): OTelLogger {\n if (options?.otelLogger) {\n return options.otelLogger;\n }\n const initialized = getInitializedOTelLogger();\n if (initialized) {\n return initialized;\n }\n if (!fallbackOTelLogger) {\n const config =\n options?.config ?? getActiveSDKConfig() ?? resolveSDKConfig();\n fallbackOTelLogger = new OTelLogger({\n config,\n resourceAttributes: options?.resourceAttributes,\n });\n }\n return fallbackOTelLogger;\n}\n\nfunction appendFlatten(\n value: unknown,\n prefix: string,\n out: Attributes,\n depth: number,\n): void {\n if (depth > FLATTEN_MAX_DEPTH) {\n out[prefix] =\n typeof value === 'string' ? value : JSON.stringify(value);\n return;\n }\n if (value === undefined || value === null) {\n return;\n }\n const t = typeof value;\n if (t === 'string' || t === 'number' || t === 'boolean') {\n out[prefix] = value as string | number | boolean;\n return;\n }\n if (Array.isArray(value)) {\n out[prefix] = JSON.stringify(value);\n return;\n }\n if (t === 'object') {\n for (const [k, v] of Object.entries(value as Record<string, unknown>)) {\n appendFlatten(v, `${prefix}.${k}`, out, depth + 1);\n }\n }\n}\n\nfunction durationToMs(duration: unknown): number | undefined {\n if (duration == null) {\n return undefined;\n }\n if (typeof duration === 'number' && Number.isFinite(duration)) {\n return duration;\n }\n if (typeof duration === 'string') {\n const s = duration.trim();\n const msMatch = s.match(/^([\\d.]+)\\s*ms$/i);\n if (msMatch) {\n return Math.round(Number.parseFloat(msMatch[1]!));\n }\n const secMatch = s.match(/^([\\d.]+)\\s*s$/i);\n if (secMatch) {\n return Math.round(Number.parseFloat(secMatch[1]!) * 1000);\n }\n const n = Number.parseFloat(s);\n if (!Number.isNaN(n)) {\n return Math.round(n);\n }\n }\n return undefined;\n}\n\nfunction buildEvlogBody(event: WideEvent): string {\n const rec = event as Record<string, unknown>;\n const method = typeof rec.method === 'string' ? rec.method : 'EVENT';\n const path = typeof rec.path === 'string' ? rec.path : '';\n const status = rec.status != null ? String(rec.status) : '';\n const duration = rec.duration != null ? String(rec.duration) : '';\n const durPart = duration ? `in ${duration}` : '';\n return [method, path, status, durPart].filter(Boolean).join(' ');\n}\n\nfunction promoteAuditFields(audit: AuditFields, attrs: Attributes): void {\n attrs['audit.action'] = audit.action;\n attrs['audit.outcome'] = audit.outcome;\n attrs['audit.actor.type'] = audit.actor.type;\n attrs['audit.actor.id'] = audit.actor.id;\n if (audit.actor.email) {\n attrs['audit.actor.email'] = audit.actor.email;\n }\n if (audit.actor.displayName) {\n attrs['audit.actor.displayName'] = audit.actor.displayName;\n }\n if (audit.target?.type) {\n attrs['audit.target.type'] = audit.target.type;\n }\n if (audit.target?.id) {\n attrs['audit.target.id'] = audit.target.id;\n }\n if (audit.reason) {\n attrs['audit.reason'] = audit.reason;\n }\n if (audit.idempotencyKey) {\n attrs['audit.idempotencyKey'] = audit.idempotencyKey;\n }\n const ctxTrace = audit.context?.traceId;\n if (typeof ctxTrace === 'string') {\n attrs['audit.context.traceId'] = ctxTrace;\n }\n if (audit.signature) {\n attrs['audit.signature'] = audit.signature;\n }\n if (audit.prevHash) {\n attrs['audit.prevHash'] = audit.prevHash;\n }\n if (audit.hash) {\n attrs['audit.hash'] = audit.hash;\n }\n}\n\nfunction attachTraceCorrelation(event: WideEvent, attrs: Attributes): void {\n const traceId =\n typeof event.traceId === 'string' ? event.traceId : undefined;\n const spanId =\n typeof event.spanId === 'string' ? event.spanId : undefined;\n const tc = event.traceContext as\n | { traceFlags?: number }\n | undefined;\n const traceFlags =\n typeof tc?.traceFlags === 'number' ? tc.traceFlags : 1;\n\n if (traceId) {\n attrs.trace_id = traceId;\n }\n if (spanId) {\n attrs.span_id = spanId;\n }\n if (traceId && spanId) {\n attrs.trace_flags = traceFlags;\n }\n}\n\n/**\n * Map an evlog {@link WideEvent} to OTLP log fields for {@link OTelLogger.postMessage}.\n */\nexport function parseEvlogEvent(\n event: WideEvent,\n ctx?: Pick<DrainContext, 'request' | 'headers'>,\n options?: EvlogDrainOptions & { auditMode?: boolean },\n): ParsedEvlogEmit {\n const auditMode = options?.auditMode ?? false;\n const levelKey =\n typeof event.level === 'string' ? event.level : 'info';\n const levelSeverity = LEVEL_SEVERITY[levelKey] ?? LEVEL_SEVERITY.info;\n\n const attributes: Attributes = {};\n const rec = event as Record<string, unknown>;\n\n for (const [key, value] of Object.entries(rec)) {\n appendFlatten(value, `mxl.${key}`, attributes, 0);\n }\n\n attributes['mxl.kind'] = auditMode ? 'audit-event' : 'wide-event';\n\n const requestId =\n ctx?.request?.requestId ??\n (typeof rec.requestId === 'string' ? rec.requestId : undefined);\n if (requestId) {\n attributes['mxl.request_id'] = requestId;\n }\n\n const durationMs = durationToMs(rec.duration);\n if (durationMs != null) {\n attributes['mxl.duration_ms'] = durationMs;\n }\n if (rec.status != null) {\n attributes['mxl.status'] = rec.status as Attributes[string];\n }\n\n attachTraceCorrelation(event, attributes);\n\n let emitOpts: OTelLogEmitOptions;\n\n if (auditMode) {\n emitOpts = {\n scope: options?.scope ?? 'mxl.audit',\n severityNumber: 17,\n severityText: 'AUDIT',\n };\n if (event.audit) {\n promoteAuditFields(event.audit, attributes);\n }\n } else {\n emitOpts = {\n scope: options?.scope ?? 'mxl',\n severityNumber: levelSeverity.number,\n severityText: levelSeverity.text,\n };\n }\n\n return {\n levelLabel: levelKey,\n body: buildEvlogBody(event),\n attributes,\n emitOpts,\n };\n}\n\nexport class OTelEvlogBridge {\n constructor(private readonly options?: EvlogDrainOptions) {}\n\n emit(ctx: DrainContext): void {\n const otel = resolveOTelLogger(this.options);\n const parsed = parseEvlogEvent(ctx.event, ctx, {\n ...this.options,\n auditMode: this.options?.auditMode ?? false,\n });\n otel.postMessage(\n parsed.levelLabel,\n parsed.body,\n parsed.attributes,\n parsed.emitOpts,\n );\n }\n}\n\n/**\n * mxl drain that forwards wide events through the MXL {@link OTelLogger}\n * pipeline (same batching/export path as {@link initSDK} when initialized).\n */\nexport function createEvlogDrain(options?: EvlogDrainOptions) {\n const bridge = new OTelEvlogBridge(options);\n return async (ctx: DrainContext): Promise<void> => {\n bridge.emit(ctx);\n };\n}\n\n/**\n * Enrich mxl wide events with trace id / span id from the active OpenTelemetry span.\n */\nexport function createOtelTraceEnricher(opts: { overwrite?: boolean } = {}) {\n return (ctx: EnrichContext): void => {\n const span = trace.getSpan(context.active());\n const sc = span?.spanContext();\n if (!sc || !isSpanContextValid(sc)) {\n return;\n }\n if (opts.overwrite || ctx.event.traceId == null) {\n ctx.event.traceId = sc.traceId;\n }\n if (opts.overwrite || ctx.event.spanId == null) {\n ctx.event.spanId = sc.spanId;\n }\n ctx.event.traceContext = {\n ...(ctx.event.traceContext as object | undefined),\n traceId: sc.traceId,\n spanId: sc.spanId,\n traceFlags: sc.traceFlags,\n };\n };\n}\n\n/**\n * Routes only audit-bearing wide events to OTLP under scope `mxl.audit`.\n */\nexport function createAuditOtelDrain(options?: EvlogDrainOptions) {\n return auditOnly(\n createEvlogDrain({\n ...options,\n auditMode: true,\n scope: options?.scope ?? 'mxl.audit',\n }),\n { await: true },\n );\n}\n"],"mappings":";;;;;AAmBA,MAAM,iBAGF;CACF,OAAO;EAAE,QAAQ;EAAG,MAAM;EAAS;CACnC,MAAM;EAAE,QAAQ;EAAG,MAAM;EAAQ;CACjC,MAAM;EAAE,QAAQ;EAAI,MAAM;EAAQ;CAClC,OAAO;EAAE,QAAQ;EAAI,MAAM;EAAS;CACrC;AAED,MAAM,oBAAoB;AAmB1B,IAAI;AAEJ,SAAS,kBAAkB,SAAyC;CAClE,IAAI,SAAS,YACX,OAAO,QAAQ;CAEjB,MAAM,cAAc,0BAA0B;CAC9C,IAAI,aACF,OAAO;CAET,IAAI,CAAC,oBAGH,qBAAqB,IAAI,WAAW;EAClC,QAFA,SAAS,UAAU,oBAAoB,IAAI,kBAAkB;EAG7D,oBAAoB,SAAS;EAC9B,CAAC;CAEJ,OAAO;;AAGT,SAAS,cACP,OACA,QACA,KACA,OACM;CACN,IAAI,QAAQ,mBAAmB;EAC7B,IAAI,UACF,OAAO,UAAU,WAAW,QAAQ,KAAK,UAAU,MAAM;EAC3D;;CAEF,IAAI,UAAU,KAAA,KAAa,UAAU,MACnC;CAEF,MAAM,IAAI,OAAO;CACjB,IAAI,MAAM,YAAY,MAAM,YAAY,MAAM,WAAW;EACvD,IAAI,UAAU;EACd;;CAEF,IAAI,MAAM,QAAQ,MAAM,EAAE;EACxB,IAAI,UAAU,KAAK,UAAU,MAAM;EACnC;;CAEF,IAAI,MAAM,UACR,KAAK,MAAM,CAAC,GAAG,MAAM,OAAO,QAAQ,MAAiC,EACnE,cAAc,GAAG,GAAG,OAAO,GAAG,KAAK,KAAK,QAAQ,EAAE;;AAKxD,SAAS,aAAa,UAAuC;CAC3D,IAAI,YAAY,MACd;CAEF,IAAI,OAAO,aAAa,YAAY,OAAO,SAAS,SAAS,EAC3D,OAAO;CAET,IAAI,OAAO,aAAa,UAAU;EAChC,MAAM,IAAI,SAAS,MAAM;EACzB,MAAM,UAAU,EAAE,MAAM,mBAAmB;EAC3C,IAAI,SACF,OAAO,KAAK,MAAM,OAAO,WAAW,QAAQ,GAAI,CAAC;EAEnD,MAAM,WAAW,EAAE,MAAM,kBAAkB;EAC3C,IAAI,UACF,OAAO,KAAK,MAAM,OAAO,WAAW,SAAS,GAAI,GAAG,IAAK;EAE3D,MAAM,IAAI,OAAO,WAAW,EAAE;EAC9B,IAAI,CAAC,OAAO,MAAM,EAAE,EAClB,OAAO,KAAK,MAAM,EAAE;;;AAM1B,SAAS,eAAe,OAA0B;CAChD,MAAM,MAAM;CACZ,MAAM,SAAS,OAAO,IAAI,WAAW,WAAW,IAAI,SAAS;CAC7D,MAAM,OAAO,OAAO,IAAI,SAAS,WAAW,IAAI,OAAO;CACvD,MAAM,SAAS,IAAI,UAAU,OAAO,OAAO,IAAI,OAAO,GAAG;CACzD,MAAM,WAAW,IAAI,YAAY,OAAO,OAAO,IAAI,SAAS,GAAG;CAE/D,OAAO;EAAC;EAAQ;EAAM;EADN,WAAW,MAAM,aAAa;EACR,CAAC,OAAO,QAAQ,CAAC,KAAK,IAAI;;AAGlE,SAAS,mBAAmB,OAAoB,OAAyB;CACvE,MAAM,kBAAkB,MAAM;CAC9B,MAAM,mBAAmB,MAAM;CAC/B,MAAM,sBAAsB,MAAM,MAAM;CACxC,MAAM,oBAAoB,MAAM,MAAM;CACtC,IAAI,MAAM,MAAM,OACd,MAAM,uBAAuB,MAAM,MAAM;CAE3C,IAAI,MAAM,MAAM,aACd,MAAM,6BAA6B,MAAM,MAAM;CAEjD,IAAI,MAAM,QAAQ,MAChB,MAAM,uBAAuB,MAAM,OAAO;CAE5C,IAAI,MAAM,QAAQ,IAChB,MAAM,qBAAqB,MAAM,OAAO;CAE1C,IAAI,MAAM,QACR,MAAM,kBAAkB,MAAM;CAEhC,IAAI,MAAM,gBACR,MAAM,0BAA0B,MAAM;CAExC,MAAM,WAAW,MAAM,SAAS;CAChC,IAAI,OAAO,aAAa,UACtB,MAAM,2BAA2B;CAEnC,IAAI,MAAM,WACR,MAAM,qBAAqB,MAAM;CAEnC,IAAI,MAAM,UACR,MAAM,oBAAoB,MAAM;CAElC,IAAI,MAAM,MACR,MAAM,gBAAgB,MAAM;;AAIhC,SAAS,uBAAuB,OAAkB,OAAyB;CACzE,MAAM,UACJ,OAAO,MAAM,YAAY,WAAW,MAAM,UAAU,KAAA;CACtD,MAAM,SACJ,OAAO,MAAM,WAAW,WAAW,MAAM,SAAS,KAAA;CACpD,MAAM,KAAK,MAAM;CAGjB,MAAM,aACJ,OAAO,IAAI,eAAe,WAAW,GAAG,aAAa;CAEvD,IAAI,SACF,MAAM,WAAW;CAEnB,IAAI,QACF,MAAM,UAAU;CAElB,IAAI,WAAW,QACb,MAAM,cAAc;;;;;AAOxB,SAAgB,gBACd,OACA,KACA,SACiB;CACjB,MAAM,YAAY,SAAS,aAAa;CACxC,MAAM,WACJ,OAAO,MAAM,UAAU,WAAW,MAAM,QAAQ;CAClD,MAAM,gBAAgB,eAAe,aAAa,eAAe;CAEjE,MAAM,aAAyB,EAAE;CACjC,MAAM,MAAM;CAEZ,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,IAAI,EAC5C,cAAc,OAAO,OAAO,OAAO,YAAY,EAAE;CAGnD,WAAW,cAAc,YAAY,gBAAgB;CAErD,MAAM,YACJ,KAAK,SAAS,cACb,OAAO,IAAI,cAAc,WAAW,IAAI,YAAY,KAAA;CACvD,IAAI,WACF,WAAW,oBAAoB;CAGjC,MAAM,aAAa,aAAa,IAAI,SAAS;CAC7C,IAAI,cAAc,MAChB,WAAW,qBAAqB;CAElC,IAAI,IAAI,UAAU,MAChB,WAAW,gBAAgB,IAAI;CAGjC,uBAAuB,OAAO,WAAW;CAEzC,IAAI;CAEJ,IAAI,WAAW;EACb,WAAW;GACT,OAAO,SAAS,SAAS;GACzB,gBAAgB;GAChB,cAAc;GACf;EACD,IAAI,MAAM,OACR,mBAAmB,MAAM,OAAO,WAAW;QAG7C,WAAW;EACT,OAAO,SAAS,SAAS;EACzB,gBAAgB,cAAc;EAC9B,cAAc,cAAc;EAC7B;CAGH,OAAO;EACL,YAAY;EACZ,MAAM,eAAe,MAAM;EAC3B;EACA;EACD;;AAGH,IAAa,kBAAb,MAA6B;CACE;CAA7B,YAAY,SAA8C;EAA7B,KAAA,UAAA;;CAE7B,KAAK,KAAyB;EAC5B,MAAM,OAAO,kBAAkB,KAAK,QAAQ;EAC5C,MAAM,SAAS,gBAAgB,IAAI,OAAO,KAAK;GAC7C,GAAG,KAAK;GACR,WAAW,KAAK,SAAS,aAAa;GACvC,CAAC;EACF,KAAK,YACH,OAAO,YACP,OAAO,MACP,OAAO,YACP,OAAO,SACR;;;;;;;AAQL,SAAgB,iBAAiB,SAA6B;CAC5D,MAAM,SAAS,IAAI,gBAAgB,QAAQ;CAC3C,OAAO,OAAO,QAAqC;EACjD,OAAO,KAAK,IAAI;;;;;;AAOpB,SAAgB,wBAAwB,OAAgC,EAAE,EAAE;CAC1E,QAAQ,QAA6B;EAEnC,MAAM,KADO,MAAM,QAAQ,QAAQ,QAAQ,CAC5B,EAAE,aAAa;EAC9B,IAAI,CAAC,MAAM,CAAC,mBAAmB,GAAG,EAChC;EAEF,IAAI,KAAK,aAAa,IAAI,MAAM,WAAW,MACzC,IAAI,MAAM,UAAU,GAAG;EAEzB,IAAI,KAAK,aAAa,IAAI,MAAM,UAAU,MACxC,IAAI,MAAM,SAAS,GAAG;EAExB,IAAI,MAAM,eAAe;GACvB,GAAI,IAAI,MAAM;GACd,SAAS,GAAG;GACZ,QAAQ,GAAG;GACX,YAAY,GAAG;GAChB;;;;;;AAOL,SAAgB,qBAAqB,SAA6B;CAChE,OAAO,UACL,iBAAiB;EACf,GAAG;EACH,WAAW;EACX,OAAO,SAAS,SAAS;EAC1B,CAAC,EACF,EAAE,OAAO,MAAM,CAChB"}
|
package/dist/logger/nest.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_otelLogger = require("../otelLogger-
|
|
2
|
+
const require_otelLogger = require("../otelLogger-CmKOazp1.cjs");
|
|
3
3
|
//#region src/logger/nest.ts
|
|
4
4
|
var OTelNestLogger = class {
|
|
5
5
|
logger;
|
package/dist/logger/nest.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as OTelNestLogger } from "../nest-
|
|
1
|
+
import { t as OTelNestLogger } from "../nest-B4NftW3t.cjs";
|
|
2
2
|
export { OTelNestLogger };
|
package/dist/logger/nest.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as OTelNestLogger } from "../nest-
|
|
1
|
+
import { t as OTelNestLogger } from "../nest-BTWrtcoq.mjs";
|
|
2
2
|
export { OTelNestLogger };
|
package/dist/logger/nest.mjs
CHANGED
package/dist/logger/nest.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nest.mjs","names":[],"sources":["../../src/logger/nest.ts"],"sourcesContent":["import { Attributes } from '@opentelemetry/api';\nimport { OTelLogger } from './otelLogger.ts';\nimport type { LoggerOptions } from './types.ts';\n\nexport class OTelNestLogger {\n private readonly logger: OTelLogger;\n\n constructor(options: LoggerOptions) {\n this.logger = new OTelLogger(options);\n }\n\n log(message: unknown, context?: string) {\n this.logger.postMessage('info', String(message), this.getMeta(context));\n }\n\n error(message: unknown, trace?: string, context?: string) {\n this.logger.postMessage('error', String(message), this.getMeta(context, trace));\n }\n\n warn(message: unknown, context?: string) {\n this.logger.postMessage('warn', String(message), this.getMeta(context));\n }\n\n debug(message: unknown, context?: string) {\n this.logger.postMessage('debug', String(message), this.getMeta(context));\n }\n\n verbose(message: unknown, context?: string) {\n this.logger.postMessage('trace', String(message), this.getMeta(context));\n }\n\n private getMeta(context?: string, trace?: string): Attributes {\n return {\n ...(context ? { context } : {}),\n ...(trace ? { trace } : {}),\n };\n }\n}\n"],"mappings":";;AAIA,IAAa,iBAAb,MAA4B;CAC1B;CAEA,YAAY,SAAwB;
|
|
1
|
+
{"version":3,"file":"nest.mjs","names":[],"sources":["../../src/logger/nest.ts"],"sourcesContent":["import { Attributes } from '@opentelemetry/api';\nimport { OTelLogger } from './otelLogger.ts';\nimport type { LoggerOptions } from './types.ts';\n\nexport class OTelNestLogger {\n private readonly logger: OTelLogger;\n\n constructor(options: LoggerOptions) {\n this.logger = new OTelLogger(options);\n }\n\n log(message: unknown, context?: string) {\n this.logger.postMessage('info', String(message), this.getMeta(context));\n }\n\n error(message: unknown, trace?: string, context?: string) {\n this.logger.postMessage('error', String(message), this.getMeta(context, trace));\n }\n\n warn(message: unknown, context?: string) {\n this.logger.postMessage('warn', String(message), this.getMeta(context));\n }\n\n debug(message: unknown, context?: string) {\n this.logger.postMessage('debug', String(message), this.getMeta(context));\n }\n\n verbose(message: unknown, context?: string) {\n this.logger.postMessage('trace', String(message), this.getMeta(context));\n }\n\n private getMeta(context?: string, trace?: string): Attributes {\n return {\n ...(context ? { context } : {}),\n ...(trace ? { trace } : {}),\n };\n }\n}\n"],"mappings":";;AAIA,IAAa,iBAAb,MAA4B;CAC1B;CAEA,YAAY,SAAwB;EAClC,KAAK,SAAS,IAAI,WAAW,QAAQ;;CAGvC,IAAI,SAAkB,SAAkB;EACtC,KAAK,OAAO,YAAY,QAAQ,OAAO,QAAQ,EAAE,KAAK,QAAQ,QAAQ,CAAC;;CAGzE,MAAM,SAAkB,OAAgB,SAAkB;EACxD,KAAK,OAAO,YAAY,SAAS,OAAO,QAAQ,EAAE,KAAK,QAAQ,SAAS,MAAM,CAAC;;CAGjF,KAAK,SAAkB,SAAkB;EACvC,KAAK,OAAO,YAAY,QAAQ,OAAO,QAAQ,EAAE,KAAK,QAAQ,QAAQ,CAAC;;CAGzE,MAAM,SAAkB,SAAkB;EACxC,KAAK,OAAO,YAAY,SAAS,OAAO,QAAQ,EAAE,KAAK,QAAQ,QAAQ,CAAC;;CAG1E,QAAQ,SAAkB,SAAkB;EAC1C,KAAK,OAAO,YAAY,SAAS,OAAO,QAAQ,EAAE,KAAK,QAAQ,QAAQ,CAAC;;CAG1E,QAAgB,SAAkB,OAA4B;EAC5D,OAAO;GACL,GAAI,UAAU,EAAE,SAAS,GAAG,EAAE;GAC9B,GAAI,QAAQ,EAAE,OAAO,GAAG,EAAE;GAC3B"}
|
package/dist/logger/pino.cjs
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
|
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
5
|
const require_chunk = require("../chunk-CKQMccvm.cjs");
|
|
6
|
-
const require_otelLogger = require("../otelLogger-
|
|
6
|
+
const require_otelLogger = require("../otelLogger-CmKOazp1.cjs");
|
|
7
7
|
const require_json = require("../json-DnZQlfyK.cjs");
|
|
8
8
|
let _opentelemetry_api = require("@opentelemetry/api");
|
|
9
9
|
let lodash_isstring = require("lodash.isstring");
|
package/dist/logger/pino.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as parsePinoLog, n as createPinoTransport, r as getPinoMixinFunction, t as HyperDXPinoTransportOptions } from "../pino-
|
|
1
|
+
import { i as parsePinoLog, n as createPinoTransport, r as getPinoMixinFunction, t as HyperDXPinoTransportOptions } from "../pino-BeU47K6T.cjs";
|
|
2
2
|
export { HyperDXPinoTransportOptions, createPinoTransport as default, getPinoMixinFunction, parsePinoLog };
|
package/dist/logger/pino.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as parsePinoLog, n as createPinoTransport, r as getPinoMixinFunction, t as HyperDXPinoTransportOptions } from "../pino-
|
|
1
|
+
import { i as parsePinoLog, n as createPinoTransport, r as getPinoMixinFunction, t as HyperDXPinoTransportOptions } from "../pino-RSK75gR8.mjs";
|
|
2
2
|
export { HyperDXPinoTransportOptions, createPinoTransport as default, getPinoMixinFunction, parsePinoLog };
|
package/dist/logger/pino.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as OTelLogger } from "../otelLogger-
|
|
1
|
+
import { t as OTelLogger } from "../otelLogger-B0HIri4C.mjs";
|
|
2
2
|
import { t as jsonToString } from "../json-QBn3zdPA.mjs";
|
|
3
3
|
import { context, isSpanContextValid, trace } from "@opentelemetry/api";
|
|
4
4
|
import isString from "lodash.isstring";
|
package/dist/logger/pino.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pino.mjs","names":[],"sources":["../../src/logger/pino.ts"],"sourcesContent":["import {\n Attributes,\n context,\n isSpanContextValid,\n trace,\n} from '@opentelemetry/api';\nimport isString from 'lodash.isstring';\nimport build from 'pino-abstract-transport';\nimport { jsonToString } from '../utils/json.ts';\nimport { OTelLogger } from './otelLogger.ts';\nimport type { LoggerOptions } from './types.ts';\n\ntype PinoLogLine = {\n level: number;\n msg?: string;\n message?: unknown;\n} & Attributes;\n\nconst PINO_LEVELS: Record<number, string> = {\n 10: 'trace',\n 20: 'debug',\n 30: 'info',\n 40: 'warn',\n 50: 'error',\n 60: 'fatal',\n};\n\nexport function parsePinoLog(log: PinoLogLine) {\n const { level, msg, message, ...meta } = log;\n const targetMessage = msg ?? message;\n const body =\n targetMessage == null\n ? jsonToString(log)\n : isString(targetMessage)\n ? targetMessage\n : jsonToString(targetMessage);\n\n return {\n level: PINO_LEVELS[level] ?? 'info',\n message: body,\n meta,\n };\n}\n\nconst MIXIN_KEYS = {\n traceId: 'trace_id',\n spanId: 'span_id',\n traceFlags: 'trace_flags',\n};\n\nexport function getPinoMixinFunction() {\n const span = trace.getSpan(context.active());\n if (!span) {\n return {};\n }\n const spanContext = span.spanContext();\n if (!isSpanContextValid(spanContext)) {\n return {};\n }\n return {\n [MIXIN_KEYS.traceId]: spanContext.traceId,\n [MIXIN_KEYS.spanId]: spanContext.spanId,\n [MIXIN_KEYS.traceFlags]: Number(spanContext.traceFlags),\n };\n}\n\nexport type HyperDXPinoTransportOptions = LoggerOptions & {\n getCustomMeta?: () => Attributes;\n};\n\nexport default async function createPinoTransport(\n options: HyperDXPinoTransportOptions,\n) {\n const logger = new OTelLogger({\n config: options.config,\n resourceAttributes: options.resourceAttributes,\n });\n\n return build(\n async (source) => {\n for await (const payload of source) {\n const parsed = parsePinoLog(payload as PinoLogLine);\n logger.postMessage(parsed.level, parsed.message, {\n ...(options.getCustomMeta?.() ?? {}),\n ...parsed.meta,\n });\n }\n },\n {\n async close() {\n await logger.shutdown();\n },\n },\n );\n}\n"],"mappings":";;;;;;AAkBA,MAAM,cAAsC;CAC1C,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACL;AAED,SAAgB,aAAa,KAAkB;CAC7C,MAAM,EAAE,OAAO,KAAK,SAAS,GAAG,SAAS;CACzC,MAAM,gBAAgB,OAAO;CAC7B,MAAM,OACJ,iBAAiB,OACb,aAAa,IAAI,GACjB,SAAS,cAAc,GACvB,gBACA,aAAa,cAAc;
|
|
1
|
+
{"version":3,"file":"pino.mjs","names":[],"sources":["../../src/logger/pino.ts"],"sourcesContent":["import {\n Attributes,\n context,\n isSpanContextValid,\n trace,\n} from '@opentelemetry/api';\nimport isString from 'lodash.isstring';\nimport build from 'pino-abstract-transport';\nimport { jsonToString } from '../utils/json.ts';\nimport { OTelLogger } from './otelLogger.ts';\nimport type { LoggerOptions } from './types.ts';\n\ntype PinoLogLine = {\n level: number;\n msg?: string;\n message?: unknown;\n} & Attributes;\n\nconst PINO_LEVELS: Record<number, string> = {\n 10: 'trace',\n 20: 'debug',\n 30: 'info',\n 40: 'warn',\n 50: 'error',\n 60: 'fatal',\n};\n\nexport function parsePinoLog(log: PinoLogLine) {\n const { level, msg, message, ...meta } = log;\n const targetMessage = msg ?? message;\n const body =\n targetMessage == null\n ? jsonToString(log)\n : isString(targetMessage)\n ? targetMessage\n : jsonToString(targetMessage);\n\n return {\n level: PINO_LEVELS[level] ?? 'info',\n message: body,\n meta,\n };\n}\n\nconst MIXIN_KEYS = {\n traceId: 'trace_id',\n spanId: 'span_id',\n traceFlags: 'trace_flags',\n};\n\nexport function getPinoMixinFunction() {\n const span = trace.getSpan(context.active());\n if (!span) {\n return {};\n }\n const spanContext = span.spanContext();\n if (!isSpanContextValid(spanContext)) {\n return {};\n }\n return {\n [MIXIN_KEYS.traceId]: spanContext.traceId,\n [MIXIN_KEYS.spanId]: spanContext.spanId,\n [MIXIN_KEYS.traceFlags]: Number(spanContext.traceFlags),\n };\n}\n\nexport type HyperDXPinoTransportOptions = LoggerOptions & {\n getCustomMeta?: () => Attributes;\n};\n\nexport default async function createPinoTransport(\n options: HyperDXPinoTransportOptions,\n) {\n const logger = new OTelLogger({\n config: options.config,\n resourceAttributes: options.resourceAttributes,\n });\n\n return build(\n async (source) => {\n for await (const payload of source) {\n const parsed = parsePinoLog(payload as PinoLogLine);\n logger.postMessage(parsed.level, parsed.message, {\n ...(options.getCustomMeta?.() ?? {}),\n ...parsed.meta,\n });\n }\n },\n {\n async close() {\n await logger.shutdown();\n },\n },\n );\n}\n"],"mappings":";;;;;;AAkBA,MAAM,cAAsC;CAC1C,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACL;AAED,SAAgB,aAAa,KAAkB;CAC7C,MAAM,EAAE,OAAO,KAAK,SAAS,GAAG,SAAS;CACzC,MAAM,gBAAgB,OAAO;CAC7B,MAAM,OACJ,iBAAiB,OACb,aAAa,IAAI,GACjB,SAAS,cAAc,GACvB,gBACA,aAAa,cAAc;CAEjC,OAAO;EACL,OAAO,YAAY,UAAU;EAC7B,SAAS;EACT;EACD;;AAGH,MAAM,aAAa;CACjB,SAAS;CACT,QAAQ;CACR,YAAY;CACb;AAED,SAAgB,uBAAuB;CACrC,MAAM,OAAO,MAAM,QAAQ,QAAQ,QAAQ,CAAC;CAC5C,IAAI,CAAC,MACH,OAAO,EAAE;CAEX,MAAM,cAAc,KAAK,aAAa;CACtC,IAAI,CAAC,mBAAmB,YAAY,EAClC,OAAO,EAAE;CAEX,OAAO;GACJ,WAAW,UAAU,YAAY;GACjC,WAAW,SAAS,YAAY;GAChC,WAAW,aAAa,OAAO,YAAY,WAAW;EACxD;;AAOH,eAA8B,oBAC5B,SACA;CACA,MAAM,SAAS,IAAI,WAAW;EAC5B,QAAQ,QAAQ;EAChB,oBAAoB,QAAQ;EAC7B,CAAC;CAEF,OAAO,MACL,OAAO,WAAW;EAChB,WAAW,MAAM,WAAW,QAAQ;GAClC,MAAM,SAAS,aAAa,QAAuB;GACnD,OAAO,YAAY,OAAO,OAAO,OAAO,SAAS;IAC/C,GAAI,QAAQ,iBAAiB,IAAI,EAAE;IACnC,GAAG,OAAO;IACX,CAAC;;IAGN,EACE,MAAM,QAAQ;EACZ,MAAM,OAAO,UAAU;IAE1B,CACF"}
|
package/dist/logger/winston.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_chunk = require("../chunk-CKQMccvm.cjs");
|
|
3
|
-
const require_otelLogger = require("../otelLogger-
|
|
3
|
+
const require_otelLogger = require("../otelLogger-CmKOazp1.cjs");
|
|
4
4
|
const require_json = require("../json-DnZQlfyK.cjs");
|
|
5
5
|
let lodash_isplainobject = require("lodash.isplainobject");
|
|
6
6
|
lodash_isplainobject = require_chunk.__toESM(lodash_isplainobject, 1);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as WinstonTransportOptions, r as parseWinstonLog, t as OTelWinstonTransport } from "../winston-
|
|
1
|
+
import { n as WinstonTransportOptions, r as parseWinstonLog, t as OTelWinstonTransport } from "../winston-DZHe-bDF.cjs";
|
|
2
2
|
export { OTelWinstonTransport, WinstonTransportOptions, parseWinstonLog };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as WinstonTransportOptions, r as parseWinstonLog, t as OTelWinstonTransport } from "../winston-
|
|
1
|
+
import { n as WinstonTransportOptions, r as parseWinstonLog, t as OTelWinstonTransport } from "../winston-BY2kow_r.mjs";
|
|
2
2
|
export { OTelWinstonTransport, WinstonTransportOptions, parseWinstonLog };
|
package/dist/logger/winston.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as OTelLogger } from "../otelLogger-
|
|
1
|
+
import { t as OTelLogger } from "../otelLogger-B0HIri4C.mjs";
|
|
2
2
|
import { t as jsonToString } from "../json-QBn3zdPA.mjs";
|
|
3
3
|
import isPlainObject from "lodash.isplainobject";
|
|
4
4
|
import isString from "lodash.isstring";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"winston.mjs","names":[],"sources":["../../src/logger/winston.ts"],"sourcesContent":["import { Attributes } from '@opentelemetry/api';\nimport isPlainObject from 'lodash.isplainobject';\nimport isString from 'lodash.isstring';\nimport Transport from 'winston-transport';\nimport { jsonToString } from '../utils/json.ts';\nimport { OTelLogger } from './otelLogger.ts';\nimport type { LoggerOptions } from './types.ts';\n\nexport function parseWinstonLog(\n log: {\n level: string;\n message: string | Attributes;\n } & Attributes,\n) {\n const { level, message, ...attributes } = log;\n let meta = attributes;\n const body = isString(message) ? message : jsonToString(message);\n if (isPlainObject(message)) {\n meta = { ...attributes, ...(message as Attributes) };\n }\n return { level, message: body, meta };\n}\n\nexport type WinstonTransportOptions = LoggerOptions & {\n maxLevel?: string;\n getCustomMeta?: () => Attributes;\n};\n\nexport class OTelWinstonTransport extends Transport {\n private readonly logger: OTelLogger;\n private readonly getCustomMeta?: () => Attributes;\n\n constructor(options: WinstonTransportOptions) {\n super({ level: options.maxLevel ?? 'info' });\n this.getCustomMeta = options.getCustomMeta;\n this.logger = new OTelLogger({\n config: options.config,\n resourceAttributes: options.resourceAttributes,\n });\n }\n\n log(\n info: {\n level: string;\n message: string | Attributes;\n } & Attributes,\n callback: () => void,\n ) {\n setImmediate(() => {\n this.emit('logged', info);\n });\n const parsed = parseWinstonLog(info);\n this.logger.postMessage(parsed.level, parsed.message, {\n ...(this.getCustomMeta?.() ?? {}),\n ...parsed.meta,\n });\n callback();\n }\n\n close() {\n void this.logger.shutdown().finally(() => {\n this.emit('finish');\n this.emit('close');\n });\n }\n}\n"],"mappings":";;;;;;AAQA,SAAgB,gBACd,KAIA;CACA,MAAM,EAAE,OAAO,SAAS,GAAG,eAAe;CAC1C,IAAI,OAAO;CACX,MAAM,OAAO,SAAS,QAAQ,GAAG,UAAU,aAAa,QAAQ;
|
|
1
|
+
{"version":3,"file":"winston.mjs","names":[],"sources":["../../src/logger/winston.ts"],"sourcesContent":["import { Attributes } from '@opentelemetry/api';\nimport isPlainObject from 'lodash.isplainobject';\nimport isString from 'lodash.isstring';\nimport Transport from 'winston-transport';\nimport { jsonToString } from '../utils/json.ts';\nimport { OTelLogger } from './otelLogger.ts';\nimport type { LoggerOptions } from './types.ts';\n\nexport function parseWinstonLog(\n log: {\n level: string;\n message: string | Attributes;\n } & Attributes,\n) {\n const { level, message, ...attributes } = log;\n let meta = attributes;\n const body = isString(message) ? message : jsonToString(message);\n if (isPlainObject(message)) {\n meta = { ...attributes, ...(message as Attributes) };\n }\n return { level, message: body, meta };\n}\n\nexport type WinstonTransportOptions = LoggerOptions & {\n maxLevel?: string;\n getCustomMeta?: () => Attributes;\n};\n\nexport class OTelWinstonTransport extends Transport {\n private readonly logger: OTelLogger;\n private readonly getCustomMeta?: () => Attributes;\n\n constructor(options: WinstonTransportOptions) {\n super({ level: options.maxLevel ?? 'info' });\n this.getCustomMeta = options.getCustomMeta;\n this.logger = new OTelLogger({\n config: options.config,\n resourceAttributes: options.resourceAttributes,\n });\n }\n\n log(\n info: {\n level: string;\n message: string | Attributes;\n } & Attributes,\n callback: () => void,\n ) {\n setImmediate(() => {\n this.emit('logged', info);\n });\n const parsed = parseWinstonLog(info);\n this.logger.postMessage(parsed.level, parsed.message, {\n ...(this.getCustomMeta?.() ?? {}),\n ...parsed.meta,\n });\n callback();\n }\n\n close() {\n void this.logger.shutdown().finally(() => {\n this.emit('finish');\n this.emit('close');\n });\n }\n}\n"],"mappings":";;;;;;AAQA,SAAgB,gBACd,KAIA;CACA,MAAM,EAAE,OAAO,SAAS,GAAG,eAAe;CAC1C,IAAI,OAAO;CACX,MAAM,OAAO,SAAS,QAAQ,GAAG,UAAU,aAAa,QAAQ;CAChE,IAAI,cAAc,QAAQ,EACxB,OAAO;EAAE,GAAG;EAAY,GAAI;EAAwB;CAEtD,OAAO;EAAE;EAAO,SAAS;EAAM;EAAM;;AAQvC,IAAa,uBAAb,cAA0C,UAAU;CAClD;CACA;CAEA,YAAY,SAAkC;EAC5C,MAAM,EAAE,OAAO,QAAQ,YAAY,QAAQ,CAAC;EAC5C,KAAK,gBAAgB,QAAQ;EAC7B,KAAK,SAAS,IAAI,WAAW;GAC3B,QAAQ,QAAQ;GAChB,oBAAoB,QAAQ;GAC7B,CAAC;;CAGJ,IACE,MAIA,UACA;EACA,mBAAmB;GACjB,KAAK,KAAK,UAAU,KAAK;IACzB;EACF,MAAM,SAAS,gBAAgB,KAAK;EACpC,KAAK,OAAO,YAAY,OAAO,OAAO,OAAO,SAAS;GACpD,GAAI,KAAK,iBAAiB,IAAI,EAAE;GAChC,GAAG,OAAO;GACX,CAAC;EACF,UAAU;;CAGZ,QAAQ;EACN,KAAU,OAAO,UAAU,CAAC,cAAc;GACxC,KAAK,KAAK,SAAS;GACnB,KAAK,KAAK,QAAQ;IAClB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as LoggerOptions } from "./types-
|
|
1
|
+
import { t as LoggerOptions } from "./types-v-UbM69o.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/logger/nest.d.ts
|
|
4
4
|
declare class OTelNestLogger {
|
|
@@ -13,4 +13,4 @@ declare class OTelNestLogger {
|
|
|
13
13
|
}
|
|
14
14
|
//#endregion
|
|
15
15
|
export { OTelNestLogger as t };
|
|
16
|
-
//# sourceMappingURL=nest-
|
|
16
|
+
//# sourceMappingURL=nest-B4NftW3t.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nest-
|
|
1
|
+
{"version":3,"file":"nest-B4NftW3t.d.cts","names":[],"sources":["../src/logger/nest.ts"],"mappings":";;;cAIa,cAAA;EAAA,iBACM,MAAA;cAEL,OAAA,EAAS,aAAA;EAIrB,GAAA,CAAI,OAAA,WAAkB,OAAA;EAItB,KAAA,CAAM,OAAA,WAAkB,KAAA,WAAgB,OAAA;EAIxC,IAAA,CAAK,OAAA,WAAkB,OAAA;EAIvB,KAAA,CAAM,OAAA,WAAkB,OAAA;EAIxB,OAAA,CAAQ,OAAA,WAAkB,OAAA;EAAA,QAIlB,OAAA;AAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as LoggerOptions } from "./types-
|
|
1
|
+
import { t as LoggerOptions } from "./types-B0hlS5Sc.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/logger/nest.d.ts
|
|
4
4
|
declare class OTelNestLogger {
|
|
@@ -13,4 +13,4 @@ declare class OTelNestLogger {
|
|
|
13
13
|
}
|
|
14
14
|
//#endregion
|
|
15
15
|
export { OTelNestLogger as t };
|
|
16
|
-
//# sourceMappingURL=nest-
|
|
16
|
+
//# sourceMappingURL=nest-BTWrtcoq.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nest-
|
|
1
|
+
{"version":3,"file":"nest-BTWrtcoq.d.mts","names":[],"sources":["../src/logger/nest.ts"],"mappings":";;;cAIa,cAAA;EAAA,iBACM,MAAA;cAEL,OAAA,EAAS,aAAA;EAIrB,GAAA,CAAI,OAAA,WAAkB,OAAA;EAItB,KAAA,CAAM,OAAA,WAAkB,KAAA,WAAgB,OAAA;EAIxC,IAAA,CAAK,OAAA,WAAkB,OAAA;EAIvB,KAAA,CAAM,OAAA,WAAkB,OAAA;EAIxB,OAAA,CAAQ,OAAA,WAAkB,OAAA;EAAA,QAIlB,OAAA;AAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { t as LoggerOptions } from "./types-v-UbM69o.cjs";
|
|
2
|
+
import { t as OTelNestLogger } from "./nest-B4NftW3t.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/integrations/nest.d.ts
|
|
5
|
+
declare function createNestLogger(options: LoggerOptions): OTelNestLogger;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { createNestLogger as t };
|
|
8
|
+
//# sourceMappingURL=nest-BgK5ExdL.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nest-BgK5ExdL.d.cts","names":[],"sources":["../src/integrations/nest.ts"],"mappings":";;;;iBAGgB,gBAAA,CAAiB,OAAA,EAAS,aAAA,GAAa,cAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { t as LoggerOptions } from "./types-B0hlS5Sc.mjs";
|
|
2
|
+
import { t as OTelNestLogger } from "./nest-BTWrtcoq.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/integrations/nest.d.ts
|
|
5
|
+
declare function createNestLogger(options: LoggerOptions): OTelNestLogger;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { createNestLogger as t };
|
|
8
|
+
//# sourceMappingURL=nest-BxEonYFS.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nest-BxEonYFS.d.mts","names":[],"sources":["../src/integrations/nest.ts"],"mappings":";;;;iBAGgB,gBAAA,CAAiB,OAAA,EAAS,aAAA,GAAa,cAAA"}
|