logixia 2.0.0 → 2.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 +172 -2597
- package/dist/async-context-2mbUKhcl.mjs +132 -0
- package/dist/async-context-2mbUKhcl.mjs.map +1 -0
- package/dist/async-context-DUFMDYAr.js +148 -0
- package/dist/async-context-DUFMDYAr.js.map +1 -0
- package/dist/{azure-monitor.transport-CrvfHd9C.js → azure-monitor.transport-Bu4S2I2q.js} +32 -20
- package/dist/azure-monitor.transport-Bu4S2I2q.js.map +1 -0
- package/dist/{azure-monitor.transport-Cn_3Usvu.d.ts → azure-monitor.transport-Bvf7Xegt.d.ts} +3 -6
- package/dist/azure-monitor.transport-Bvf7Xegt.d.ts.map +1 -0
- package/dist/{azure-monitor.transport-CHnjVRF-.mjs → azure-monitor.transport-C1RWAumT.mjs} +27 -15
- package/dist/azure-monitor.transport-C1RWAumT.mjs.map +1 -0
- package/dist/{azure-monitor.transport-D7Da4RAb.d.mts → azure-monitor.transport-CbSHOnNX.d.mts} +3 -6
- package/dist/azure-monitor.transport-CbSHOnNX.d.mts.map +1 -0
- package/dist/azure.d.mts +1 -2
- package/dist/azure.d.ts +1 -2
- package/dist/azure.js +3 -6
- package/dist/azure.mjs +1 -6
- package/dist/{batch-buffer-PGvSgbmd.mjs → batch-buffer-BvXLDPlV.mjs} +21 -7
- package/dist/batch-buffer-BvXLDPlV.mjs.map +1 -0
- package/dist/{batch-buffer-BY-mRWIK.js → batch-buffer-C7Am4Mw-.js} +53 -40
- package/dist/batch-buffer-C7Am4Mw-.js.map +1 -0
- package/dist/browser.d.mts +47 -27
- package/dist/browser.d.mts.map +1 -1
- package/dist/browser.d.ts +47 -27
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +464 -62
- package/dist/browser.js.map +1 -1
- package/dist/browser.mjs +465 -65
- package/dist/browser.mjs.map +1 -1
- package/dist/{builder-0gEzRopq.mjs → builder-DhNhvOkt.mjs} +307 -246
- package/dist/builder-DhNhvOkt.mjs.map +1 -0
- package/dist/{builder-D44QktIo.js → builder-yFvJrz7o.js} +435 -399
- package/dist/builder-yFvJrz7o.js.map +1 -0
- package/dist/cli/index.js +216 -125
- package/dist/cloudwatch.d.mts +1 -2
- package/dist/cloudwatch.d.ts +1 -2
- package/dist/cloudwatch.js +3 -7
- package/dist/cloudwatch.mjs +1 -7
- package/dist/{cloudwatch.transport-DsEq633o.d.ts → cloudwatch.transport-CQyT6U91.d.ts} +2 -6
- package/dist/cloudwatch.transport-CQyT6U91.d.ts.map +1 -0
- package/dist/{cloudwatch.transport-BO1ahxw-.js → cloudwatch.transport-Ch1Uae-0.js} +61 -36
- package/dist/cloudwatch.transport-Ch1Uae-0.js.map +1 -0
- package/dist/{cloudwatch.transport-UlyZFWMn.d.mts → cloudwatch.transport-CjVrI6S4.d.mts} +2 -6
- package/dist/cloudwatch.transport-CjVrI6S4.d.mts.map +1 -0
- package/dist/{cloudwatch.transport-DZ6ies7g.mjs → cloudwatch.transport-DZqF2xZO.mjs} +54 -28
- package/dist/cloudwatch.transport-DZqF2xZO.mjs.map +1 -0
- package/dist/{coerce.utils-Cu6IUTgX.mjs → coerce.utils-B_rEudCn.mjs} +3 -4
- package/dist/{coerce.utils-Cu6IUTgX.mjs.map → coerce.utils-B_rEudCn.mjs.map} +1 -1
- package/dist/{coerce.utils-B-LilukN.js → coerce.utils-C1C5sIX0.js} +8 -10
- package/dist/{coerce.utils-B-LilukN.js.map → coerce.utils-C1C5sIX0.js.map} +1 -1
- package/dist/correlation.d.mts +15 -69
- package/dist/correlation.d.mts.map +1 -1
- package/dist/correlation.d.ts +15 -69
- package/dist/correlation.d.ts.map +1 -1
- package/dist/correlation.js +69 -20
- package/dist/correlation.js.map +1 -1
- package/dist/correlation.mjs +67 -17
- package/dist/correlation.mjs.map +1 -1
- package/dist/{entry-fields-BvOLFlJ4.js → entry-fields-BSLkzw18.js} +16 -13
- package/dist/entry-fields-BSLkzw18.js.map +1 -0
- package/dist/{entry-fields-BJkuPnIg.mjs → entry-fields-J1OBi24o.mjs} +11 -7
- package/dist/entry-fields-J1OBi24o.mjs.map +1 -0
- package/dist/gcp.d.mts +1 -2
- package/dist/gcp.d.ts +1 -2
- package/dist/gcp.js +3 -7
- package/dist/gcp.mjs +1 -7
- package/dist/{gcp.transport-B7oc97sG.d.ts → gcp.transport-BCIvdFV-.d.ts} +5 -8
- package/dist/gcp.transport-BCIvdFV-.d.ts.map +1 -0
- package/dist/{gcp.transport-GrJurKo8.d.mts → gcp.transport-D9SdLPwP.d.mts} +5 -8
- package/dist/gcp.transport-D9SdLPwP.d.mts.map +1 -0
- package/dist/{gcp.transport-DBX5TPIy.mjs → gcp.transport-DVCmnA3b.mjs} +59 -16
- package/dist/gcp.transport-DVCmnA3b.mjs.map +1 -0
- package/dist/{gcp.transport-CHV8MGgz.js → gcp.transport-Dy2Lf8FI.js} +64 -22
- package/dist/gcp.transport-Dy2Lf8FI.js.map +1 -0
- package/dist/http-shapes-BnBkJcid.d.mts +32 -0
- package/dist/http-shapes-BnBkJcid.d.mts.map +1 -0
- package/dist/http-shapes-BnBkJcid.d.ts +32 -0
- package/dist/http-shapes-BnBkJcid.d.ts.map +1 -0
- package/dist/{index-3mw5gaCw.d.mts → index-BSTtFcQ6.d.mts} +142 -13
- package/dist/index-BSTtFcQ6.d.mts.map +1 -0
- package/dist/{index-DhIoploR.d.ts → index-CFDGkI8n.d.ts} +142 -13
- package/dist/index-CFDGkI8n.d.ts.map +1 -0
- package/dist/index.d.mts +114 -217
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +113 -216
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +182 -279
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +160 -256
- package/dist/index.mjs.map +1 -1
- package/dist/internal-log-Bg4V1cPg.mjs +170 -0
- package/dist/internal-log-Bg4V1cPg.mjs.map +1 -0
- package/dist/internal-log-By4Govmu.js +223 -0
- package/dist/internal-log-By4Govmu.js.map +1 -0
- package/dist/{logitron-logger-UVeN-mQm.d.ts → logitron-logger-D22Yb61K.d.mts} +121 -100
- package/dist/logitron-logger-D22Yb61K.d.mts.map +1 -0
- package/dist/{logitron-logger-BFDSO8Io.d.mts → logitron-logger-D_MYYrQt.d.ts} +121 -100
- package/dist/logitron-logger-D_MYYrQt.d.ts.map +1 -0
- package/dist/middleware.d.mts +13 -28
- package/dist/middleware.d.mts.map +1 -1
- package/dist/middleware.d.ts +13 -28
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +20 -81
- package/dist/middleware.js.map +1 -1
- package/dist/middleware.mjs +17 -79
- package/dist/middleware.mjs.map +1 -1
- package/dist/nest.d.mts +37 -48
- package/dist/nest.d.mts.map +1 -1
- package/dist/nest.d.ts +37 -48
- package/dist/nest.d.ts.map +1 -1
- package/dist/nest.js +124 -135
- package/dist/nest.js.map +1 -1
- package/dist/nest.mjs +69 -78
- package/dist/nest.mjs.map +1 -1
- package/dist/{transport.manager-BiuCAJd2.mjs → otel-Dt5riXuE.mjs} +275 -117
- package/dist/otel-Dt5riXuE.mjs.map +1 -0
- package/dist/{transport.manager-CXbKKdVE.js → otel-DyeH6DVR.js} +373 -178
- package/dist/otel-DyeH6DVR.js.map +1 -0
- package/dist/own-property-BWkibepN.js +40 -0
- package/dist/own-property-BWkibepN.js.map +1 -0
- package/dist/own-property-CjFw9qwZ.mjs +29 -0
- package/dist/own-property-CjFw9qwZ.mjs.map +1 -0
- package/dist/{trace.utils-CvXgaiQT.mjs → request-trace-BgNykH9M.mjs} +40 -9
- package/dist/request-trace-BgNykH9M.mjs.map +1 -0
- package/dist/{trace.utils-DpBOLDtq.js → request-trace-ByujsUZk.js} +117 -77
- package/dist/request-trace-ByujsUZk.js.map +1 -0
- package/dist/rolldown-runtime-D3PmRqjj.mjs +4 -0
- package/dist/{safe-stringify-DJ66tW5I.mjs → safe-stringify-B5p5ktFe.mjs} +39 -15
- package/dist/safe-stringify-B5p5ktFe.mjs.map +1 -0
- package/dist/{safe-stringify-DWo3aZp_.js → safe-stringify-J3sh-7YM.js} +59 -36
- package/dist/safe-stringify-J3sh-7YM.js.map +1 -0
- package/dist/{search-C4V0OMEn.js → search-CRjhHxe9.js} +319 -92
- package/dist/search-CRjhHxe9.js.map +1 -0
- package/dist/{search-CNh9uVwR.d.ts → search-DA3ft3X5.d.mts} +5 -22
- package/dist/search-DA3ft3X5.d.mts.map +1 -0
- package/dist/{search-BFbu_oVn.mjs → search-DAXKE-P9.mjs} +289 -62
- package/dist/search-DAXKE-P9.mjs.map +1 -0
- package/dist/{search-DXANsQ2n.d.mts → search-DEl3Pe47.d.ts} +5 -22
- package/dist/search-DEl3Pe47.d.ts.map +1 -0
- package/dist/search.d.mts +2 -4
- package/dist/search.d.ts +2 -4
- package/dist/search.js +3 -4
- package/dist/search.mjs +1 -4
- package/dist/secret-config-CmK2wVkr.js +272 -0
- package/dist/secret-config-CmK2wVkr.js.map +1 -0
- package/dist/secret-config-Dhb6pqTU.mjs +210 -0
- package/dist/secret-config-Dhb6pqTU.mjs.map +1 -0
- package/dist/{slack.transport-CXjQYOes.d.ts → slack.transport-BDyENuR0.d.mts} +56 -9
- package/dist/slack.transport-BDyENuR0.d.mts.map +1 -0
- package/dist/{slack.transport-Bzw7sucI.mjs → slack.transport-BTEwsREY.mjs} +263 -31
- package/dist/slack.transport-BTEwsREY.mjs.map +1 -0
- package/dist/{slack.transport-BZzoXDPn.d.mts → slack.transport-C6E0l4kw.d.ts} +56 -9
- package/dist/slack.transport-C6E0l4kw.d.ts.map +1 -0
- package/dist/{slack.transport-BfJRouB2.js → slack.transport-UbYvOdKx.js} +286 -42
- package/dist/slack.transport-UbYvOdKx.js.map +1 -0
- package/dist/testing.d.mts +13 -11
- package/dist/testing.d.mts.map +1 -1
- package/dist/testing.d.ts +13 -11
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +41 -7
- package/dist/testing.js.map +1 -1
- package/dist/testing.mjs +40 -6
- package/dist/testing.mjs.map +1 -1
- package/dist/{transport.types-CGoHpWQR.d.ts → transport.types-CzJq4IrF.d.mts} +14 -5
- package/dist/transport.types-CzJq4IrF.d.mts.map +1 -0
- package/dist/{transport.types-BMnurPcc.d.mts → transport.types-CzJq4IrF.d.ts} +14 -5
- package/dist/transport.types-CzJq4IrF.d.ts.map +1 -0
- package/dist/transports.d.mts +39 -41
- package/dist/transports.d.mts.map +1 -1
- package/dist/transports.d.ts +39 -41
- package/dist/transports.d.ts.map +1 -1
- package/dist/transports.js +19 -22
- package/dist/transports.mjs +7 -13
- package/dist/worker-entry.js +438 -107
- package/dist/worker.d.mts +1 -2
- package/dist/worker.d.ts +1 -2
- package/dist/worker.js +3 -4
- package/dist/worker.mjs +1 -4
- package/dist/{worker.transport-JvGPog3C.d.mts → worker.transport-B9mCQSM1.d.ts} +7 -6
- package/dist/worker.transport-B9mCQSM1.d.ts.map +1 -0
- package/dist/{worker.transport-CdzSZJmw.d.ts → worker.transport-Bl8lFRck.d.mts} +7 -6
- package/dist/worker.transport-Bl8lFRck.d.mts.map +1 -0
- package/dist/{worker.transport-lPxO2MVL.mjs → worker.transport-BmmOKb1-.mjs} +43 -10
- package/dist/worker.transport-BmmOKb1-.mjs.map +1 -0
- package/dist/{worker.transport-BdPxu3PN.js → worker.transport-DxxbqQCG.js} +48 -15
- package/dist/worker.transport-DxxbqQCG.js.map +1 -0
- package/package.json +51 -75
- package/dist/async-context-BzJrbfQs.mjs +0 -72
- package/dist/async-context-BzJrbfQs.mjs.map +0 -1
- package/dist/async-context-DyQQYq3I.js +0 -92
- package/dist/async-context-DyQQYq3I.js.map +0 -1
- package/dist/azure-monitor.transport-CHnjVRF-.mjs.map +0 -1
- package/dist/azure-monitor.transport-Cn_3Usvu.d.ts.map +0 -1
- package/dist/azure-monitor.transport-CrvfHd9C.js.map +0 -1
- package/dist/azure-monitor.transport-D7Da4RAb.d.mts.map +0 -1
- package/dist/batch-buffer-BY-mRWIK.js.map +0 -1
- package/dist/batch-buffer-PGvSgbmd.mjs.map +0 -1
- package/dist/builder-0gEzRopq.mjs.map +0 -1
- package/dist/builder-D44QktIo.js.map +0 -1
- package/dist/chunk-DLSkYcPk.mjs +0 -7
- package/dist/chunk-nOFOJqeH.js +0 -30
- package/dist/cloudwatch.transport-BO1ahxw-.js.map +0 -1
- package/dist/cloudwatch.transport-DZ6ies7g.mjs.map +0 -1
- package/dist/cloudwatch.transport-DsEq633o.d.ts.map +0 -1
- package/dist/cloudwatch.transport-UlyZFWMn.d.mts.map +0 -1
- package/dist/entry-fields-BJkuPnIg.mjs.map +0 -1
- package/dist/entry-fields-BvOLFlJ4.js.map +0 -1
- package/dist/gcp.transport-B7oc97sG.d.ts.map +0 -1
- package/dist/gcp.transport-CHV8MGgz.js.map +0 -1
- package/dist/gcp.transport-DBX5TPIy.mjs.map +0 -1
- package/dist/gcp.transport-GrJurKo8.d.mts.map +0 -1
- package/dist/index-3mw5gaCw.d.mts.map +0 -1
- package/dist/index-DhIoploR.d.ts.map +0 -1
- package/dist/internal-log-BUJYMZbE.js +0 -70
- package/dist/internal-log-BUJYMZbE.js.map +0 -1
- package/dist/internal-log-Cm8SOWSV.mjs +0 -52
- package/dist/internal-log-Cm8SOWSV.mjs.map +0 -1
- package/dist/logitron-logger-BFDSO8Io.d.mts.map +0 -1
- package/dist/logitron-logger-UVeN-mQm.d.ts.map +0 -1
- package/dist/safe-stringify-DJ66tW5I.mjs.map +0 -1
- package/dist/safe-stringify-DWo3aZp_.js.map +0 -1
- package/dist/search-BFbu_oVn.mjs.map +0 -1
- package/dist/search-C4V0OMEn.js.map +0 -1
- package/dist/search-CNh9uVwR.d.ts.map +0 -1
- package/dist/search-DXANsQ2n.d.mts.map +0 -1
- package/dist/slack.transport-BZzoXDPn.d.mts.map +0 -1
- package/dist/slack.transport-BfJRouB2.js.map +0 -1
- package/dist/slack.transport-Bzw7sucI.mjs.map +0 -1
- package/dist/slack.transport-CXjQYOes.d.ts.map +0 -1
- package/dist/trace.utils-CvXgaiQT.mjs.map +0 -1
- package/dist/trace.utils-DpBOLDtq.js.map +0 -1
- package/dist/transport.manager-BiuCAJd2.mjs.map +0 -1
- package/dist/transport.manager-CXbKKdVE.js.map +0 -1
- package/dist/transport.types-BMnurPcc.d.mts.map +0 -1
- package/dist/transport.types-CGoHpWQR.d.ts.map +0 -1
- package/dist/worker.transport-BdPxu3PN.js.map +0 -1
- package/dist/worker.transport-CdzSZJmw.d.ts.map +0 -1
- package/dist/worker.transport-JvGPog3C.d.mts.map +0 -1
- package/dist/worker.transport-lPxO2MVL.mjs.map +0 -1
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { t as assignOwn } from "./own-property-CjFw9qwZ.mjs";
|
|
2
|
+
import { n as resolveTraceHeaders, o as TraceContext, t as resolveRequestTraceId } from "./request-trace-BgNykH9M.mjs";
|
|
3
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4
|
+
// src/context/async-context.ts
|
|
5
|
+
/**
|
|
6
|
+
* LogixiaContext — Zero-boilerplate AsyncLocalStorage context propagation.
|
|
7
|
+
*
|
|
8
|
+
* Lets every `logger.info()` call inside a context automatically pick up stored
|
|
9
|
+
* fields (requestId, userId, tenantId, …) without passing them through every function.
|
|
10
|
+
*
|
|
11
|
+
* Works across `Promise.all`, `setTimeout`, and event emitters — anything that
|
|
12
|
+
* inherits the async execution context.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { LogixiaContext } from 'logixia';
|
|
17
|
+
*
|
|
18
|
+
* // Wrap a request handler:
|
|
19
|
+
* app.use((req, res, next) => {
|
|
20
|
+
* LogixiaContext.run({ requestId: req.id, userId: req.user?.id }, next);
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* // Anywhere deeper in the call tree:
|
|
24
|
+
* async function processOrder(orderId: string) {
|
|
25
|
+
* const ctx = LogixiaContext.get(); // { requestId, userId, orderId }
|
|
26
|
+
* logger.info('Processing order', { orderId, ...ctx });
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
const _storage = new AsyncLocalStorage();
|
|
31
|
+
const LogixiaContext = {
|
|
32
|
+
/**
|
|
33
|
+
* Run `callback` inside an async context that carries `store` fields.
|
|
34
|
+
* All loggers queried within `callback` (and its async descendants) will
|
|
35
|
+
* automatically see these fields.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* LogixiaContext.run({ requestId: 'abc', userId: '42' }, async () => {
|
|
40
|
+
* await processOrder(); // sees requestId + userId in every log
|
|
41
|
+
* });
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
run(store, callback) {
|
|
45
|
+
const parent = _storage.getStore() ?? {};
|
|
46
|
+
const scoped = () => _storage.run({
|
|
47
|
+
...parent,
|
|
48
|
+
...store
|
|
49
|
+
}, callback);
|
|
50
|
+
const traceId = store.traceId;
|
|
51
|
+
if (typeof traceId !== "string" || traceId === "") return scoped();
|
|
52
|
+
const trace = TraceContext.instance;
|
|
53
|
+
return trace.storage.run({
|
|
54
|
+
...trace.storage.getStore(),
|
|
55
|
+
[trace.contextKey]: traceId
|
|
56
|
+
}, scoped);
|
|
57
|
+
},
|
|
58
|
+
/**
|
|
59
|
+
* Return the context fields active in the current async scope.
|
|
60
|
+
* Returns `undefined` when called outside any `LogixiaContext.run()`.
|
|
61
|
+
*/
|
|
62
|
+
get() {
|
|
63
|
+
return _storage.getStore();
|
|
64
|
+
},
|
|
65
|
+
/**
|
|
66
|
+
* Merge `fields` into the **existing** context for the current scope.
|
|
67
|
+
* If called outside a `run()` context this is a no-op (logs a dev warning).
|
|
68
|
+
*/
|
|
69
|
+
set(fields) {
|
|
70
|
+
const store = _storage.getStore();
|
|
71
|
+
if (!store) return;
|
|
72
|
+
for (const key of Object.keys(fields)) assignOwn(store, key, fields[key]);
|
|
73
|
+
},
|
|
74
|
+
/**
|
|
75
|
+
* Retrieve the underlying `AsyncLocalStorage` instance.
|
|
76
|
+
* Useful for advanced use-cases like custom middleware.
|
|
77
|
+
*/
|
|
78
|
+
getStorage() {
|
|
79
|
+
return _storage;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
function buildScope(request, options, headers) {
|
|
83
|
+
return {
|
|
84
|
+
...options.enrich ? options.enrich(request) : {},
|
|
85
|
+
traceId: resolveRequestTraceId(request, headers)
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Create an Express/Connect-compatible middleware that wraps each request in
|
|
90
|
+
* a `LogixiaContext.run()` scope populated with common request fields.
|
|
91
|
+
*
|
|
92
|
+
* Trace ID: the first present header of `traceIdHeader` (default
|
|
93
|
+
* `DEFAULT_TRACE_HEADERS`, `traceparent` parsed), else `request.id`, else a
|
|
94
|
+
* generated UUID. It is available via `getCurrentTraceId()` and is the logger's
|
|
95
|
+
* top-level `traceId` inside the request. No response header is set unless
|
|
96
|
+
* `responseHeader` is given.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* import { createExpressContextMiddleware } from 'logixia';
|
|
101
|
+
* app.use(createExpressContextMiddleware({ responseHeader: 'x-trace-id' }));
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
function createExpressContextMiddleware(options = {}) {
|
|
105
|
+
const headers = resolveTraceHeaders(options.traceIdHeader);
|
|
106
|
+
return function logixiaContextMiddleware(req, res, next) {
|
|
107
|
+
var _res$setHeader;
|
|
108
|
+
const scope = buildScope(req, options, headers);
|
|
109
|
+
if (options.responseHeader) (_res$setHeader = res.setHeader) === null || _res$setHeader === void 0 || _res$setHeader.call(res, options.responseHeader, scope.traceId);
|
|
110
|
+
LogixiaContext.run(scope, next);
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Create a Fastify lifecycle hook that wraps each request in a context scope.
|
|
115
|
+
*
|
|
116
|
+
* Register with `fastify.addHook('onRequest', createFastifyContextHook())`.
|
|
117
|
+
* Resolves the trace ID exactly like {@link createExpressContextMiddleware} and
|
|
118
|
+
* shares it with `createFastifyPlugin()` from `logixia/middleware`. Fastify's
|
|
119
|
+
* default counter `request.id` (`req-1`, ...) is never used as a trace ID.
|
|
120
|
+
*/
|
|
121
|
+
function createFastifyContextHook(options = {}) {
|
|
122
|
+
const headers = resolveTraceHeaders(options.traceIdHeader);
|
|
123
|
+
return function logixiaFastifyHook(request, reply, done) {
|
|
124
|
+
var _reply$header;
|
|
125
|
+
const scope = buildScope(request, options, headers);
|
|
126
|
+
if (options.responseHeader) (_reply$header = reply.header) === null || _reply$header === void 0 || _reply$header.call(reply, options.responseHeader, scope.traceId);
|
|
127
|
+
LogixiaContext.run(scope, done);
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
export { createExpressContextMiddleware as n, createFastifyContextHook as r, LogixiaContext as t };
|
|
131
|
+
|
|
132
|
+
//# sourceMappingURL=async-context-2mbUKhcl.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-context-2mbUKhcl.mjs","names":[],"sources":["../src/context/async-context.ts"],"sourcesContent":["/**\n * LogixiaContext — Zero-boilerplate AsyncLocalStorage context propagation.\n *\n * Lets every `logger.info()` call inside a context automatically pick up stored\n * fields (requestId, userId, tenantId, …) without passing them through every function.\n *\n * Works across `Promise.all`, `setTimeout`, and event emitters — anything that\n * inherits the async execution context.\n *\n * @example\n * ```ts\n * import { LogixiaContext } from 'logixia';\n *\n * // Wrap a request handler:\n * app.use((req, res, next) => {\n * LogixiaContext.run({ requestId: req.id, userId: req.user?.id }, next);\n * });\n *\n * // Anywhere deeper in the call tree:\n * async function processOrder(orderId: string) {\n * const ctx = LogixiaContext.get(); // { requestId, userId, orderId }\n * logger.info('Processing order', { orderId, ...ctx });\n * }\n * ```\n */\n\nimport { AsyncLocalStorage } from 'node:async_hooks';\n\nimport { assignOwn } from '../utils/own-property';\nimport {\n type ContextRequestLike,\n resolveRequestTraceId,\n resolveTraceHeaders,\n type TraceHeaderOption,\n} from '../utils/request-trace';\nimport { TraceContext } from '../utils/trace.utils';\n\nexport interface LogContext {\n traceId?: string;\n spanId?: string;\n userId?: string;\n tenantId?: string;\n sessionId?: string;\n [key: string]: unknown;\n}\n\n// Module-level singleton so all loggers share the same ALS store.\nconst _storage = new AsyncLocalStorage<LogContext>();\n\nexport const LogixiaContext = {\n /**\n * Run `callback` inside an async context that carries `store` fields.\n * All loggers queried within `callback` (and its async descendants) will\n * automatically see these fields.\n *\n * @example\n * ```ts\n * LogixiaContext.run({ requestId: 'abc', userId: '42' }, async () => {\n * await processOrder(); // sees requestId + userId in every log\n * });\n * ```\n */\n run<T>(store: LogContext, callback: () => T): T {\n const parent = _storage.getStore() ?? {};\n const scoped = (): T => _storage.run({ ...parent, ...store }, callback);\n const traceId = store.traceId;\n if (typeof traceId !== 'string' || traceId === '') return scoped();\n // An explicit traceId also becomes the TraceContext ID, so getCurrentTraceId(),\n // the logger, outbound propagation and the OTel bridge all see the same value.\n const trace = TraceContext.instance;\n return trace.storage.run({ ...trace.storage.getStore(), [trace.contextKey]: traceId }, scoped);\n },\n\n /**\n * Return the context fields active in the current async scope.\n * Returns `undefined` when called outside any `LogixiaContext.run()`.\n */\n get(): LogContext | undefined {\n return _storage.getStore();\n },\n\n /**\n * Merge `fields` into the **existing** context for the current scope.\n * If called outside a `run()` context this is a no-op (logs a dev warning).\n */\n set(fields: Partial<LogContext>): void {\n const store = _storage.getStore();\n if (!store) {\n // Silently ignore — avoids crashing in code that may call setContext\n // before a request context is established (e.g. background jobs).\n return;\n }\n for (const key of Object.keys(fields)) {\n assignOwn(store, key, fields[key]);\n }\n },\n\n /**\n * Retrieve the underlying `AsyncLocalStorage` instance.\n * Useful for advanced use-cases like custom middleware.\n */\n getStorage(): AsyncLocalStorage<LogContext> {\n return _storage;\n },\n};\n\nexport type { ContextRequestLike };\n\ninterface ContextHelperOptions<Req extends ContextRequestLike> {\n /**\n * Extract additional fields from the request. A `traceId` returned here is ignored:\n * the resolved request trace ID always wins.\n */\n enrich?: (request: Req & Record<string, unknown>) => Partial<LogContext>;\n /**\n * Header name, or list of names tried in order, to read the trace ID from.\n * Default: `DEFAULT_TRACE_HEADERS` (traceparent is parsed to its 32-hex trace id).\n */\n traceIdHeader?: TraceHeaderOption;\n /**\n * Echo the resolved trace ID on the response under this header name.\n * Default: `false` (no response header is set).\n */\n responseHeader?: string | false;\n}\n\nfunction buildScope<Req extends ContextRequestLike>(\n request: Req,\n options: ContextHelperOptions<Req>,\n headers: readonly string[]\n): LogContext {\n const extra = options.enrich ? options.enrich(request as Req & Record<string, unknown>) : {};\n return { ...extra, traceId: resolveRequestTraceId(request, headers) };\n}\n\n/**\n * Create an Express/Connect-compatible middleware that wraps each request in\n * a `LogixiaContext.run()` scope populated with common request fields.\n *\n * Trace ID: the first present header of `traceIdHeader` (default\n * `DEFAULT_TRACE_HEADERS`, `traceparent` parsed), else `request.id`, else a\n * generated UUID. It is available via `getCurrentTraceId()` and is the logger's\n * top-level `traceId` inside the request. No response header is set unless\n * `responseHeader` is given.\n *\n * @example\n * ```ts\n * import { createExpressContextMiddleware } from 'logixia';\n * app.use(createExpressContextMiddleware({ responseHeader: 'x-trace-id' }));\n * ```\n */\nexport function createExpressContextMiddleware<Req extends ContextRequestLike = ContextRequestLike>(\n options: ContextHelperOptions<Req> = {}\n) {\n const headers = resolveTraceHeaders(options.traceIdHeader);\n\n return function logixiaContextMiddleware(\n req: Req,\n res: { setHeader?: (name: string, value: string) => unknown },\n next: () => void\n ): void {\n const scope = buildScope(req, options, headers);\n if (options.responseHeader) res.setHeader?.(options.responseHeader, scope.traceId as string);\n LogixiaContext.run(scope, next);\n };\n}\n\n/**\n * Create a Fastify lifecycle hook that wraps each request in a context scope.\n *\n * Register with `fastify.addHook('onRequest', createFastifyContextHook())`.\n * Resolves the trace ID exactly like {@link createExpressContextMiddleware} and\n * shares it with `createFastifyPlugin()` from `logixia/middleware`. Fastify's\n * default counter `request.id` (`req-1`, ...) is never used as a trace ID.\n */\nexport function createFastifyContextHook<Req extends ContextRequestLike = ContextRequestLike>(\n options: ContextHelperOptions<Req> = {}\n) {\n const headers = resolveTraceHeaders(options.traceIdHeader);\n\n return function logixiaFastifyHook(\n request: Req,\n reply: { header?: (name: string, value: string) => unknown },\n done: () => void\n ): void {\n const scope = buildScope(request, options, headers);\n if (options.responseHeader) reply.header?.(options.responseHeader, scope.traceId as string);\n LogixiaContext.run(scope, done);\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,MAAM,WAAW,IAAI,kBAA8B;AAEnD,MAAa,iBAAiB;;;;;;;;;;;;;CAa5B,IAAO,OAAmB,UAAsB;EAC9C,MAAM,SAAS,SAAS,SAAS,KAAK,CAAC;EACvC,MAAM,eAAkB,SAAS,IAAI;GAAE,GAAG;GAAQ,GAAG;EAAM,GAAG,QAAQ;EACtE,MAAM,UAAU,MAAM;EACtB,IAAI,OAAO,YAAY,YAAY,YAAY,IAAI,OAAO,OAAO;EAGjE,MAAM,QAAQ,aAAa;EAC3B,OAAO,MAAM,QAAQ,IAAI;GAAE,GAAG,MAAM,QAAQ,SAAS;IAAI,MAAM,aAAa;EAAQ,GAAG,MAAM;CAC/F;;;;;CAMA,MAA8B;EAC5B,OAAO,SAAS,SAAS;CAC3B;;;;;CAMA,IAAI,QAAmC;EACrC,MAAM,QAAQ,SAAS,SAAS;EAChC,IAAI,CAAC,OAGH;EAEF,KAAK,MAAM,OAAO,OAAO,KAAK,MAAM,GAClC,UAAU,OAAO,KAAK,OAAO,IAAI;CAErC;;;;;CAMA,aAA4C;EAC1C,OAAO;CACT;AACF;AAsBA,SAAS,WACP,SACA,SACA,SACY;CAEZ,OAAO;EAAE,GADK,QAAQ,SAAS,QAAQ,OAAO,OAAwC,IAAI,CAAC;EACxE,SAAS,sBAAsB,SAAS,OAAO;CAAE;AACtE;;;;;;;;;;;;;;;;;AAkBA,SAAgB,+BACd,UAAqC,CAAC,GACtC;CACA,MAAM,UAAU,oBAAoB,QAAQ,aAAa;CAEzD,OAAO,SAAS,yBACd,KACA,KACA,MACM;;EACN,MAAM,QAAQ,WAAW,KAAK,SAAS,OAAO;EAC9C,IAAI,QAAQ,gBAAgB,CAAA,iBAAA,IAAI,eAAA,QAAA,mBAAA,KAAA,KAAA,eAAA,KAAA,KAAY,QAAQ,gBAAgB,MAAM,OAAiB;EAC3F,eAAe,IAAI,OAAO,IAAI;CAChC;AACF;;;;;;;;;AAUA,SAAgB,yBACd,UAAqC,CAAC,GACtC;CACA,MAAM,UAAU,oBAAoB,QAAQ,aAAa;CAEzD,OAAO,SAAS,mBACd,SACA,OACA,MACM;;EACN,MAAM,QAAQ,WAAW,SAAS,SAAS,OAAO;EAClD,IAAI,QAAQ,gBAAgB,CAAA,gBAAA,MAAM,YAAA,QAAA,kBAAA,KAAA,KAAA,cAAA,KAAA,OAAS,QAAQ,gBAAgB,MAAM,OAAiB;EAC1F,eAAe,IAAI,OAAO,IAAI;CAChC;AACF"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
const require_own_property = require("./own-property-BWkibepN.js");
|
|
2
|
+
const require_request_trace = require("./request-trace-ByujsUZk.js");
|
|
3
|
+
// src/context/async-context.ts
|
|
4
|
+
/**
|
|
5
|
+
* LogixiaContext — Zero-boilerplate AsyncLocalStorage context propagation.
|
|
6
|
+
*
|
|
7
|
+
* Lets every `logger.info()` call inside a context automatically pick up stored
|
|
8
|
+
* fields (requestId, userId, tenantId, …) without passing them through every function.
|
|
9
|
+
*
|
|
10
|
+
* Works across `Promise.all`, `setTimeout`, and event emitters — anything that
|
|
11
|
+
* inherits the async execution context.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { LogixiaContext } from 'logixia';
|
|
16
|
+
*
|
|
17
|
+
* // Wrap a request handler:
|
|
18
|
+
* app.use((req, res, next) => {
|
|
19
|
+
* LogixiaContext.run({ requestId: req.id, userId: req.user?.id }, next);
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // Anywhere deeper in the call tree:
|
|
23
|
+
* async function processOrder(orderId: string) {
|
|
24
|
+
* const ctx = LogixiaContext.get(); // { requestId, userId, orderId }
|
|
25
|
+
* logger.info('Processing order', { orderId, ...ctx });
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
const _storage = new (require("node:async_hooks")).AsyncLocalStorage();
|
|
30
|
+
const LogixiaContext = {
|
|
31
|
+
/**
|
|
32
|
+
* Run `callback` inside an async context that carries `store` fields.
|
|
33
|
+
* All loggers queried within `callback` (and its async descendants) will
|
|
34
|
+
* automatically see these fields.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* LogixiaContext.run({ requestId: 'abc', userId: '42' }, async () => {
|
|
39
|
+
* await processOrder(); // sees requestId + userId in every log
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
run(store, callback) {
|
|
44
|
+
const parent = _storage.getStore() ?? {};
|
|
45
|
+
const scoped = () => _storage.run({
|
|
46
|
+
...parent,
|
|
47
|
+
...store
|
|
48
|
+
}, callback);
|
|
49
|
+
const traceId = store.traceId;
|
|
50
|
+
if (typeof traceId !== "string" || traceId === "") return scoped();
|
|
51
|
+
const trace = require_request_trace.TraceContext.instance;
|
|
52
|
+
return trace.storage.run({
|
|
53
|
+
...trace.storage.getStore(),
|
|
54
|
+
[trace.contextKey]: traceId
|
|
55
|
+
}, scoped);
|
|
56
|
+
},
|
|
57
|
+
/**
|
|
58
|
+
* Return the context fields active in the current async scope.
|
|
59
|
+
* Returns `undefined` when called outside any `LogixiaContext.run()`.
|
|
60
|
+
*/
|
|
61
|
+
get() {
|
|
62
|
+
return _storage.getStore();
|
|
63
|
+
},
|
|
64
|
+
/**
|
|
65
|
+
* Merge `fields` into the **existing** context for the current scope.
|
|
66
|
+
* If called outside a `run()` context this is a no-op (logs a dev warning).
|
|
67
|
+
*/
|
|
68
|
+
set(fields) {
|
|
69
|
+
const store = _storage.getStore();
|
|
70
|
+
if (!store) return;
|
|
71
|
+
for (const key of Object.keys(fields)) require_own_property.assignOwn(store, key, fields[key]);
|
|
72
|
+
},
|
|
73
|
+
/**
|
|
74
|
+
* Retrieve the underlying `AsyncLocalStorage` instance.
|
|
75
|
+
* Useful for advanced use-cases like custom middleware.
|
|
76
|
+
*/
|
|
77
|
+
getStorage() {
|
|
78
|
+
return _storage;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
function buildScope(request, options, headers) {
|
|
82
|
+
return {
|
|
83
|
+
...options.enrich ? options.enrich(request) : {},
|
|
84
|
+
traceId: require_request_trace.resolveRequestTraceId(request, headers)
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Create an Express/Connect-compatible middleware that wraps each request in
|
|
89
|
+
* a `LogixiaContext.run()` scope populated with common request fields.
|
|
90
|
+
*
|
|
91
|
+
* Trace ID: the first present header of `traceIdHeader` (default
|
|
92
|
+
* `DEFAULT_TRACE_HEADERS`, `traceparent` parsed), else `request.id`, else a
|
|
93
|
+
* generated UUID. It is available via `getCurrentTraceId()` and is the logger's
|
|
94
|
+
* top-level `traceId` inside the request. No response header is set unless
|
|
95
|
+
* `responseHeader` is given.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* import { createExpressContextMiddleware } from 'logixia';
|
|
100
|
+
* app.use(createExpressContextMiddleware({ responseHeader: 'x-trace-id' }));
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
function createExpressContextMiddleware(options = {}) {
|
|
104
|
+
const headers = require_request_trace.resolveTraceHeaders(options.traceIdHeader);
|
|
105
|
+
return function logixiaContextMiddleware(req, res, next) {
|
|
106
|
+
var _res$setHeader;
|
|
107
|
+
const scope = buildScope(req, options, headers);
|
|
108
|
+
if (options.responseHeader) (_res$setHeader = res.setHeader) === null || _res$setHeader === void 0 || _res$setHeader.call(res, options.responseHeader, scope.traceId);
|
|
109
|
+
LogixiaContext.run(scope, next);
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Create a Fastify lifecycle hook that wraps each request in a context scope.
|
|
114
|
+
*
|
|
115
|
+
* Register with `fastify.addHook('onRequest', createFastifyContextHook())`.
|
|
116
|
+
* Resolves the trace ID exactly like {@link createExpressContextMiddleware} and
|
|
117
|
+
* shares it with `createFastifyPlugin()` from `logixia/middleware`. Fastify's
|
|
118
|
+
* default counter `request.id` (`req-1`, ...) is never used as a trace ID.
|
|
119
|
+
*/
|
|
120
|
+
function createFastifyContextHook(options = {}) {
|
|
121
|
+
const headers = require_request_trace.resolveTraceHeaders(options.traceIdHeader);
|
|
122
|
+
return function logixiaFastifyHook(request, reply, done) {
|
|
123
|
+
var _reply$header;
|
|
124
|
+
const scope = buildScope(request, options, headers);
|
|
125
|
+
if (options.responseHeader) (_reply$header = reply.header) === null || _reply$header === void 0 || _reply$header.call(reply, options.responseHeader, scope.traceId);
|
|
126
|
+
LogixiaContext.run(scope, done);
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
Object.defineProperty(exports, "LogixiaContext", {
|
|
130
|
+
enumerable: true,
|
|
131
|
+
get: function() {
|
|
132
|
+
return LogixiaContext;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
Object.defineProperty(exports, "createExpressContextMiddleware", {
|
|
136
|
+
enumerable: true,
|
|
137
|
+
get: function() {
|
|
138
|
+
return createExpressContextMiddleware;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
Object.defineProperty(exports, "createFastifyContextHook", {
|
|
142
|
+
enumerable: true,
|
|
143
|
+
get: function() {
|
|
144
|
+
return createFastifyContextHook;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
//# sourceMappingURL=async-context-DUFMDYAr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-context-DUFMDYAr.js","names":["AsyncLocalStorage","TraceContext","resolveRequestTraceId","resolveTraceHeaders"],"sources":["../src/context/async-context.ts"],"sourcesContent":["/**\n * LogixiaContext — Zero-boilerplate AsyncLocalStorage context propagation.\n *\n * Lets every `logger.info()` call inside a context automatically pick up stored\n * fields (requestId, userId, tenantId, …) without passing them through every function.\n *\n * Works across `Promise.all`, `setTimeout`, and event emitters — anything that\n * inherits the async execution context.\n *\n * @example\n * ```ts\n * import { LogixiaContext } from 'logixia';\n *\n * // Wrap a request handler:\n * app.use((req, res, next) => {\n * LogixiaContext.run({ requestId: req.id, userId: req.user?.id }, next);\n * });\n *\n * // Anywhere deeper in the call tree:\n * async function processOrder(orderId: string) {\n * const ctx = LogixiaContext.get(); // { requestId, userId, orderId }\n * logger.info('Processing order', { orderId, ...ctx });\n * }\n * ```\n */\n\nimport { AsyncLocalStorage } from 'node:async_hooks';\n\nimport { assignOwn } from '../utils/own-property';\nimport {\n type ContextRequestLike,\n resolveRequestTraceId,\n resolveTraceHeaders,\n type TraceHeaderOption,\n} from '../utils/request-trace';\nimport { TraceContext } from '../utils/trace.utils';\n\nexport interface LogContext {\n traceId?: string;\n spanId?: string;\n userId?: string;\n tenantId?: string;\n sessionId?: string;\n [key: string]: unknown;\n}\n\n// Module-level singleton so all loggers share the same ALS store.\nconst _storage = new AsyncLocalStorage<LogContext>();\n\nexport const LogixiaContext = {\n /**\n * Run `callback` inside an async context that carries `store` fields.\n * All loggers queried within `callback` (and its async descendants) will\n * automatically see these fields.\n *\n * @example\n * ```ts\n * LogixiaContext.run({ requestId: 'abc', userId: '42' }, async () => {\n * await processOrder(); // sees requestId + userId in every log\n * });\n * ```\n */\n run<T>(store: LogContext, callback: () => T): T {\n const parent = _storage.getStore() ?? {};\n const scoped = (): T => _storage.run({ ...parent, ...store }, callback);\n const traceId = store.traceId;\n if (typeof traceId !== 'string' || traceId === '') return scoped();\n // An explicit traceId also becomes the TraceContext ID, so getCurrentTraceId(),\n // the logger, outbound propagation and the OTel bridge all see the same value.\n const trace = TraceContext.instance;\n return trace.storage.run({ ...trace.storage.getStore(), [trace.contextKey]: traceId }, scoped);\n },\n\n /**\n * Return the context fields active in the current async scope.\n * Returns `undefined` when called outside any `LogixiaContext.run()`.\n */\n get(): LogContext | undefined {\n return _storage.getStore();\n },\n\n /**\n * Merge `fields` into the **existing** context for the current scope.\n * If called outside a `run()` context this is a no-op (logs a dev warning).\n */\n set(fields: Partial<LogContext>): void {\n const store = _storage.getStore();\n if (!store) {\n // Silently ignore — avoids crashing in code that may call setContext\n // before a request context is established (e.g. background jobs).\n return;\n }\n for (const key of Object.keys(fields)) {\n assignOwn(store, key, fields[key]);\n }\n },\n\n /**\n * Retrieve the underlying `AsyncLocalStorage` instance.\n * Useful for advanced use-cases like custom middleware.\n */\n getStorage(): AsyncLocalStorage<LogContext> {\n return _storage;\n },\n};\n\nexport type { ContextRequestLike };\n\ninterface ContextHelperOptions<Req extends ContextRequestLike> {\n /**\n * Extract additional fields from the request. A `traceId` returned here is ignored:\n * the resolved request trace ID always wins.\n */\n enrich?: (request: Req & Record<string, unknown>) => Partial<LogContext>;\n /**\n * Header name, or list of names tried in order, to read the trace ID from.\n * Default: `DEFAULT_TRACE_HEADERS` (traceparent is parsed to its 32-hex trace id).\n */\n traceIdHeader?: TraceHeaderOption;\n /**\n * Echo the resolved trace ID on the response under this header name.\n * Default: `false` (no response header is set).\n */\n responseHeader?: string | false;\n}\n\nfunction buildScope<Req extends ContextRequestLike>(\n request: Req,\n options: ContextHelperOptions<Req>,\n headers: readonly string[]\n): LogContext {\n const extra = options.enrich ? options.enrich(request as Req & Record<string, unknown>) : {};\n return { ...extra, traceId: resolveRequestTraceId(request, headers) };\n}\n\n/**\n * Create an Express/Connect-compatible middleware that wraps each request in\n * a `LogixiaContext.run()` scope populated with common request fields.\n *\n * Trace ID: the first present header of `traceIdHeader` (default\n * `DEFAULT_TRACE_HEADERS`, `traceparent` parsed), else `request.id`, else a\n * generated UUID. It is available via `getCurrentTraceId()` and is the logger's\n * top-level `traceId` inside the request. No response header is set unless\n * `responseHeader` is given.\n *\n * @example\n * ```ts\n * import { createExpressContextMiddleware } from 'logixia';\n * app.use(createExpressContextMiddleware({ responseHeader: 'x-trace-id' }));\n * ```\n */\nexport function createExpressContextMiddleware<Req extends ContextRequestLike = ContextRequestLike>(\n options: ContextHelperOptions<Req> = {}\n) {\n const headers = resolveTraceHeaders(options.traceIdHeader);\n\n return function logixiaContextMiddleware(\n req: Req,\n res: { setHeader?: (name: string, value: string) => unknown },\n next: () => void\n ): void {\n const scope = buildScope(req, options, headers);\n if (options.responseHeader) res.setHeader?.(options.responseHeader, scope.traceId as string);\n LogixiaContext.run(scope, next);\n };\n}\n\n/**\n * Create a Fastify lifecycle hook that wraps each request in a context scope.\n *\n * Register with `fastify.addHook('onRequest', createFastifyContextHook())`.\n * Resolves the trace ID exactly like {@link createExpressContextMiddleware} and\n * shares it with `createFastifyPlugin()` from `logixia/middleware`. Fastify's\n * default counter `request.id` (`req-1`, ...) is never used as a trace ID.\n */\nexport function createFastifyContextHook<Req extends ContextRequestLike = ContextRequestLike>(\n options: ContextHelperOptions<Req> = {}\n) {\n const headers = resolveTraceHeaders(options.traceIdHeader);\n\n return function logixiaFastifyHook(\n request: Req,\n reply: { header?: (name: string, value: string) => unknown },\n done: () => void\n ): void {\n const scope = buildScope(request, options, headers);\n if (options.responseHeader) reply.header?.(options.responseHeader, scope.traceId as string);\n LogixiaContext.run(scope, done);\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,MAAM,WAAW,K,0BAAIA,EAAAA,CAAAA,kBAA8B;AAEnD,MAAa,iBAAiB;;;;;;;;;;;;;CAa5B,IAAO,OAAmB,UAAsB;EAC9C,MAAM,SAAS,SAAS,SAAS,KAAK,CAAC;EACvC,MAAM,eAAkB,SAAS,IAAI;GAAE,GAAG;GAAQ,GAAG;EAAM,GAAG,QAAQ;EACt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kBAAA,KAAA,KAAA,cAAA,KAAA,OAAS,QAAQ,gBAAgB,MAAM,OAAiB;EAC1F,eAAe,IAAI,OAAO,IAAI;CAChC;AACF"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
const require_secret_config = require("./secret-config-CmK2wVkr.js");
|
|
2
|
+
const require_internal_log = require("./internal-log-By4Govmu.js");
|
|
3
|
+
const require_safe_stringify = require("./safe-stringify-J3sh-7YM.js");
|
|
4
|
+
const require_batch_buffer = require("./batch-buffer-C7Am4Mw-.js");
|
|
5
|
+
// src/transports/azure-monitor.transport.ts
|
|
6
6
|
/**
|
|
7
7
|
* Azure AD tenant IDs are either a GUID or a verified domain (e.g. `contoso.onmicrosoft.com`).
|
|
8
8
|
* This pattern is deliberately permissive on structure but strict on character
|
|
@@ -32,6 +32,7 @@ var AzureMonitorTransport = class {
|
|
|
32
32
|
this.flushTimer = null;
|
|
33
33
|
this.accessToken = null;
|
|
34
34
|
this.tokenExpiry = 0;
|
|
35
|
+
require_secret_config.protectSecrets(this, ["clientSecret", "accessToken"]);
|
|
35
36
|
this.endpoint = config.endpoint.replace(/\/$/, "");
|
|
36
37
|
this.ruleId = config.ruleId;
|
|
37
38
|
this.streamName = config.streamName;
|
|
@@ -41,12 +42,13 @@ var AzureMonitorTransport = class {
|
|
|
41
42
|
this.batchSize = config.batchSize ?? 200;
|
|
42
43
|
this.flushInterval = config.flushIntervalMs ?? 5e3;
|
|
43
44
|
this.level = config.level;
|
|
44
|
-
this.requestTimeoutMs = config.requestTimeoutMs ??
|
|
45
|
+
this.requestTimeoutMs = config.requestTimeoutMs ?? 1e4;
|
|
45
46
|
this.buffer = new require_batch_buffer.BatchBuffer({
|
|
46
47
|
name: "AzureMonitorTransport",
|
|
47
48
|
batchSize: this.batchSize,
|
|
48
|
-
maxBufferSize: config.maxBufferSize ??
|
|
49
|
-
send: (entries) => this.sendEntries(entries)
|
|
49
|
+
maxBufferSize: config.maxBufferSize ?? 1e4,
|
|
50
|
+
send: (entries) => this.sendEntries(entries),
|
|
51
|
+
secrets: () => this.secretValues()
|
|
50
52
|
});
|
|
51
53
|
this.flushTimer = setInterval(() => {
|
|
52
54
|
this.flush().catch(() => {});
|
|
@@ -83,6 +85,14 @@ var AzureMonitorTransport = class {
|
|
|
83
85
|
Properties: require_safe_stringify.stringifyForLog(entry.data ?? {})
|
|
84
86
|
};
|
|
85
87
|
}
|
|
88
|
+
secretValues(token) {
|
|
89
|
+
return [
|
|
90
|
+
this.clientSecret,
|
|
91
|
+
this.accessToken ?? void 0,
|
|
92
|
+
token,
|
|
93
|
+
...require_secret_config.urlSecrets(this.endpoint)
|
|
94
|
+
];
|
|
95
|
+
}
|
|
86
96
|
async getAccessToken() {
|
|
87
97
|
if (this.accessToken && Date.now() < this.tokenExpiry) return this.accessToken;
|
|
88
98
|
if (!this.tenantId || !this.clientId || !this.clientSecret) {
|
|
@@ -107,7 +117,8 @@ var AzureMonitorTransport = class {
|
|
|
107
117
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
108
118
|
body,
|
|
109
119
|
timeoutMs: this.requestTimeoutMs,
|
|
110
|
-
label: "Azure token request"
|
|
120
|
+
label: "Azure token request",
|
|
121
|
+
secrets: () => this.secretValues()
|
|
111
122
|
});
|
|
112
123
|
const parsed = JSON.parse(res.body);
|
|
113
124
|
if (!parsed.access_token) return null;
|
|
@@ -122,12 +133,13 @@ var AzureMonitorTransport = class {
|
|
|
122
133
|
async sendEntries(entries) {
|
|
123
134
|
const token = await this.getAccessToken();
|
|
124
135
|
if (!token) throw new Error("AzureMonitorTransport: no access token available");
|
|
125
|
-
const
|
|
136
|
+
const records = entries.map((e) => this.toAzureRecord(e));
|
|
137
|
+
const body = require_safe_stringify.stringifyForLog(records);
|
|
126
138
|
let reqUrl;
|
|
127
139
|
try {
|
|
128
140
|
reqUrl = new URL(`dataCollectionRules/${encodeURIComponent(this.ruleId)}/streams/${encodeURIComponent(this.streamName)}?api-version=2023-01-01`, this.endpoint.endsWith("/") ? this.endpoint : `${this.endpoint}/`);
|
|
129
141
|
} catch (error) {
|
|
130
|
-
require_internal_log.internalError(`AzureMonitorTransport: invalid endpoint "${this.endpoint}"`, error);
|
|
142
|
+
require_internal_log.internalError(`AzureMonitorTransport: invalid endpoint "${require_secret_config.scrubSecrets(this.endpoint, require_secret_config.urlSecrets(this.endpoint))}"`, require_secret_config.scrubError(error, require_secret_config.urlSecrets(this.endpoint)));
|
|
131
143
|
return;
|
|
132
144
|
}
|
|
133
145
|
if (reqUrl.protocol !== "https:") {
|
|
@@ -142,16 +154,16 @@ var AzureMonitorTransport = class {
|
|
|
142
154
|
},
|
|
143
155
|
body,
|
|
144
156
|
timeoutMs: this.requestTimeoutMs,
|
|
145
|
-
label: "Azure Monitor API"
|
|
157
|
+
label: "Azure Monitor API",
|
|
158
|
+
secrets: () => this.secretValues(token)
|
|
146
159
|
});
|
|
147
160
|
}
|
|
148
161
|
};
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
return AzureMonitorTransport;
|
|
155
|
-
}
|
|
162
|
+
Object.defineProperty(exports, "AzureMonitorTransport", {
|
|
163
|
+
enumerable: true,
|
|
164
|
+
get: function() {
|
|
165
|
+
return AzureMonitorTransport;
|
|
166
|
+
}
|
|
156
167
|
});
|
|
157
|
-
|
|
168
|
+
|
|
169
|
+
//# sourceMappingURL=azure-monitor.transport-Bu4S2I2q.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"azure-monitor.transport-Bu4S2I2q.js","names":["BatchBuffer","stringifyForLog","urlSecrets","httpRequest","scrubSecrets","scrubError"],"sources":["../src/transports/azure-monitor.transport.ts"],"sourcesContent":["/**\n * logixia — Azure Monitor / Application Insights transport\n *\n * Sends log entries to Azure Monitor via the Data Collection Rules (DCR) API\n * using the Logs Ingestion API (the modern replacement for the legacy HTTP\n * Data Collector API).\n *\n * Maps logixia levels to Application Insights severity levels:\n * verbose → 0, debug → 1, info → 1, warn → 2, error → 3, critical → 4\n *\n * @example\n * ```ts\n * import { createLogger } from 'logixia';\n * import { AzureMonitorTransport } from 'logixia/azure';\n *\n * const logger = createLogger({\n * transports: {\n * custom: [\n * new AzureMonitorTransport({\n * // Logs Ingestion API endpoint (from your DCR)\n * endpoint: 'https://<dce>.ingest.monitor.azure.com',\n * ruleId: 'dcr-xxxxxxxxxxxxxxxx',\n * streamName: 'Custom-LogixiaLogs',\n * // Client credentials are required; managed identity is not supported.\n * tenantId: process.env.AZURE_TENANT_ID,\n * clientId: process.env.AZURE_CLIENT_ID,\n * clientSecret: process.env.AZURE_CLIENT_SECRET,\n * }),\n * ],\n * },\n * });\n * ```\n */\n\nimport type { IAsyncTransport, TransportLogEntry } from '../types/transport.types';\nimport { internalError, internalWarn } from '../utils/internal-log';\nimport { stringifyForLog } from '../utils/safe-stringify';\nimport {\n BatchBuffer,\n DEFAULT_MAX_BUFFER_SIZE,\n DEFAULT_REQUEST_TIMEOUT_MS,\n httpRequest,\n} from './batch-buffer';\nimport { protectSecrets, scrubError, scrubSecrets, urlSecrets } from './secret-config';\n\n/**\n * Azure AD tenant IDs are either a GUID or a verified domain (e.g. `contoso.onmicrosoft.com`).\n * This pattern is deliberately permissive on structure but strict on character\n * set — it rejects the breakout characters (`/`, `@`, `:`, `?`, `#`, whitespace)\n * that would let a hostile config smuggle a different host, path, or query into\n * the OAuth token URL.\n */\nconst AZURE_TENANT_RE = /^[a-z0-9][a-z0-9.-]{1,253}$/i;\n\nexport interface AzureMonitorTransportConfig {\n /** DCE (Data Collection Endpoint) URL, e.g. `https://<name>.ingest.monitor.azure.com`. */\n endpoint: string;\n /** Data Collection Rule immutable ID (from Azure portal). */\n ruleId: string;\n /** Stream name defined in the DCR, e.g. `'Custom-LogixiaLogs_CL'`. */\n streamName: string;\n /** Azure AD tenant ID for OAuth2 client-credentials flow. */\n tenantId?: string;\n /** Azure AD app (service principal) client ID. */\n clientId?: string;\n /** Azure AD app client secret. */\n clientSecret?: string;\n /** Number of entries to batch. @default 200 */\n batchSize?: number;\n /** Flush interval in ms. @default 5000 */\n flushIntervalMs?: number;\n /** Abort a request that has not finished after this many ms. @default 10000 */\n requestTimeoutMs?: number;\n /** Max buffered entries; the oldest are dropped past this. @default 10000 */\n maxBufferSize?: number;\n level?: string;\n}\n\nconst SEVERITY_MAP: Record<string, number> = {\n verbose: 0,\n trace: 0,\n debug: 1,\n info: 1,\n log: 1,\n warn: 2,\n warning: 2,\n error: 3,\n critical: 4,\n fatal: 4,\n};\n\n/**\n * Azure Monitor Logs Ingestion transport.\n */\nexport class AzureMonitorTransport implements IAsyncTransport {\n public readonly name = 'azure-monitor';\n public readonly batchSize: number;\n public readonly flushInterval: number;\n public readonly level: string | undefined;\n\n private readonly buffer: BatchBuffer<TransportLogEntry>;\n private readonly requestTimeoutMs: number;\n private flushTimer: NodeJS.Timeout | null = null;\n private accessToken: string | null = null;\n private tokenExpiry = 0;\n\n private readonly endpoint: string;\n private readonly ruleId: string;\n private readonly streamName: string;\n private readonly tenantId: string | undefined;\n private readonly clientId: string | undefined;\n private readonly clientSecret: string | undefined;\n\n constructor(config: AzureMonitorTransportConfig) {\n protectSecrets(this, ['clientSecret', 'accessToken']);\n this.endpoint = config.endpoint.replace(/\\/$/, '');\n this.ruleId = config.ruleId;\n this.streamName = config.streamName;\n this.tenantId = config.tenantId ?? process.env['AZURE_TENANT_ID'];\n this.clientId = config.clientId ?? process.env['AZURE_CLIENT_ID'];\n this.clientSecret = config.clientSecret ?? process.env['AZURE_CLIENT_SECRET'];\n this.batchSize = config.batchSize ?? 200;\n this.flushInterval = config.flushIntervalMs ?? 5000;\n this.level = config.level;\n this.requestTimeoutMs = config.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;\n this.buffer = new BatchBuffer<TransportLogEntry>({\n name: 'AzureMonitorTransport',\n batchSize: this.batchSize,\n maxBufferSize: config.maxBufferSize ?? DEFAULT_MAX_BUFFER_SIZE,\n send: (entries) => this.sendEntries(entries),\n secrets: () => this.secretValues(),\n });\n\n this.flushTimer = setInterval(() => {\n this.flush().catch(() => {});\n }, this.flushInterval);\n if (this.flushTimer.unref) this.flushTimer.unref();\n }\n\n write(entry: TransportLogEntry): void {\n this.buffer.push(entry);\n this.buffer.flushIfFull();\n }\n\n flush(): Promise<void> {\n return this.buffer.flush();\n }\n\n /**\n * Flush remaining entries and stop the interval timer on shutdown. Without\n * this the manager's close() skipped the transport (close was undefined) and\n * buffered entries were lost on deploy. Waits for any in-flight send first.\n */\n async close(): Promise<void> {\n if (this.flushTimer) {\n clearInterval(this.flushTimer);\n this.flushTimer = null;\n }\n await this.buffer.close();\n }\n\n private toAzureRecord(entry: TransportLogEntry): Record<string, unknown> {\n return {\n TimeGenerated: entry.timestamp ?? new Date().toISOString(),\n SeverityLevel: SEVERITY_MAP[entry.level.toLowerCase()] ?? 1,\n Message: entry.message,\n AppName: entry.appName,\n Context: entry.context ?? '',\n TraceId: entry.traceId ?? '',\n Properties: stringifyForLog(entry.data ?? {}),\n };\n }\n\n private secretValues(token?: string): (string | undefined)[] {\n return [this.clientSecret, this.accessToken ?? undefined, token, ...urlSecrets(this.endpoint)];\n }\n\n private async getAccessToken(): Promise<string | null> {\n if (this.accessToken && Date.now() < this.tokenExpiry) return this.accessToken;\n\n if (!this.tenantId || !this.clientId || !this.clientSecret) {\n internalWarn(\n 'AzureMonitorTransport: missing credentials — set tenantId, clientId, clientSecret'\n );\n return null;\n }\n\n const body = new URLSearchParams({\n grant_type: 'client_credentials',\n client_id: this.clientId,\n client_secret: this.clientSecret,\n scope: 'https://monitor.azure.com/.default',\n }).toString();\n\n const tenantId = this.tenantId;\n if (!AZURE_TENANT_RE.test(tenantId)) {\n internalWarn(\n `AzureMonitorTransport: refusing to request token — tenantId \"${tenantId}\" is not a valid GUID or domain`\n );\n return null;\n }\n\n const reqUrl = new URL(\n `https://login.microsoftonline.com/${encodeURIComponent(tenantId)}/oauth2/v2.0/token`\n );\n try {\n const res = await httpRequest({\n url: reqUrl,\n headers: { 'Content-Type': 'application/x-www-form-urlencoded' },\n body,\n timeoutMs: this.requestTimeoutMs,\n label: 'Azure token request',\n secrets: () => this.secretValues(),\n });\n const parsed = JSON.parse(res.body) as { access_token?: string; expires_in?: number };\n if (!parsed.access_token) return null;\n this.accessToken = parsed.access_token;\n this.tokenExpiry = Date.now() + (parsed.expires_in ?? 3600) * 1000 - 60_000;\n return this.accessToken;\n } catch (err) {\n internalError('AzureMonitorTransport token request failed', err);\n return null;\n }\n }\n\n private async sendEntries(entries: TransportLogEntry[]): Promise<void> {\n const token = await this.getAccessToken();\n if (!token) throw new Error('AzureMonitorTransport: no access token available');\n\n const records = entries.map((e) => this.toAzureRecord(e));\n const body = stringifyForLog(records);\n let reqUrl: URL;\n try {\n // Build from the user-configured DCE endpoint; encodeURIComponent-ing the\n // ruleId/streamName stops a hostile config from smuggling extra path\n // segments or query params into the request.\n reqUrl = new URL(\n `dataCollectionRules/${encodeURIComponent(this.ruleId)}/streams/${encodeURIComponent(this.streamName)}?api-version=2023-01-01`,\n this.endpoint.endsWith('/') ? this.endpoint : `${this.endpoint}/`\n );\n } catch (error) {\n internalError(\n `AzureMonitorTransport: invalid endpoint \"${scrubSecrets(this.endpoint, urlSecrets(this.endpoint))}\"`,\n scrubError(error, urlSecrets(this.endpoint))\n );\n return;\n }\n if (reqUrl.protocol !== 'https:') {\n internalError(`AzureMonitorTransport: endpoint must use https (got ${reqUrl.protocol})`);\n return;\n }\n\n await httpRequest({\n url: reqUrl,\n headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },\n body,\n timeoutMs: this.requestTimeoutMs,\n label: 'Azure Monitor API',\n secrets: () => this.secretValues(token),\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;AAoDA,MAAM,kBAAkB;AA0BxB,MAAM,eAAuC;CAC3C,SAAS;CACT,OAAO;CACP,OAAO;C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E,OAAO,KAAK;EACd,SAAS,KAAK;GACZ,qBAAA,cAAc,8CAA8C,GAAG;GAC/D,OAAO;EACT;CACF;CAEA,MAAc,YAAY,SAA6C;EACrE,MAAM,QAAQ,MAAM,KAAK,eAAe;EACxC,IAAI,CAAC,OAAO,MAAM,IAAI,MAAM,kDAAkD;EAE9E,MAAM,UAAU,QAAQ,KAAK,MAAM,KAAK,cAAc,CAAC,CAAC;EACxD,MAAM,OAAOF,uBAAAA,gBAAgB,OAAO;EACpC,IAAI;EACJ,IAAI;GAIF,SAAS,IAAI,IACX,uBAAuB,mBAAmB,KAAK,MAAM,EAAE,WAAW,mBAAmB,KAAK,UAAU,EAAE,0BACtG,KAAK,SAAS,SAAS,GAAG,IAAI,KAAK,WAAW,GAAG,KAAK,SAAS,EACjE;EACF,SAAS,OAAO;GACd,qBAAA,cACE,4CAA4CG,sBAAAA,aAAa,KAAK,UAAUF,sBAAAA,WAAW,KAAK,QAAQ,CAAC,EAAE,IACnGG,sBAAAA,WAAW,OAAOH,sBAAAA,WAAW,KAAK,QAAQ,CAAC,CAC7C;GACA;EACF;EACA,IAAI,OAAO,aAAa,UAAU;GAChC,qBAAA,cAAc,uDAAuD,OAAO,SAAS,EAAE;GACvF;EACF;EAEA,MAAMC,qBAAAA,YAAY;GAChB,KAAK;GACL,SAAS;IAAE,eAAe,UAAU;IAAS,gBAAgB;GAAmB;GAChF;GACA,WAAW,KAAK;GAChB,OAAO;GACP,eAAe,KAAK,aAAa,KAAK;EACxC,CAAC;CACH;AACF"}
|
package/dist/{azure-monitor.transport-Cn_3Usvu.d.ts → azure-monitor.transport-Bvf7Xegt.d.ts}
RENAMED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/transports/azure-monitor.transport.d.ts
|
|
4
|
-
|
|
1
|
+
import { _ as TransportLogEntry, l as IAsyncTransport } from "./transport.types-CzJq4IrF.js";
|
|
5
2
|
interface AzureMonitorTransportConfig {
|
|
6
3
|
/** DCE (Data Collection Endpoint) URL, e.g. `https://<name>.ingest.monitor.azure.com`. */
|
|
7
4
|
endpoint: string;
|
|
@@ -54,9 +51,9 @@ declare class AzureMonitorTransport implements IAsyncTransport {
|
|
|
54
51
|
*/
|
|
55
52
|
close(): Promise<void>;
|
|
56
53
|
private toAzureRecord;
|
|
54
|
+
private secretValues;
|
|
57
55
|
private getAccessToken;
|
|
58
56
|
private sendEntries;
|
|
59
57
|
}
|
|
60
|
-
//#endregion
|
|
61
58
|
export { AzureMonitorTransportConfig as n, AzureMonitorTransport as t };
|
|
62
|
-
//# sourceMappingURL=azure-monitor.transport-
|
|
59
|
+
//# sourceMappingURL=azure-monitor.transport-Bvf7Xegt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"azure-monitor.transport-Bvf7Xegt.d.ts","names":[],"sources":["../src/transports/azure-monitor.transport.ts"],"mappings":";UAsDiB;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;EACA;;;;;cAmBW,iCAAiC;WAC5B;WACA;WACA;WACA;mBAEC;mBACA;UACT;UACA;UACA;mBAES;mBACA;mBACA;mBACA;mBACA;mBACA;EAEL,YAAA,QAAQ;EA0BpB,MAAM,OAAO;EAKb,SAAS;;;;;;EASH,SAAS;UAQP;UAYA;UAIM;UAgDA"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { r as internalWarn, t as internalError } from "./internal-log-
|
|
2
|
-
import { i as
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { r as internalWarn, t as internalError } from "./internal-log-Bg4V1cPg.mjs";
|
|
2
|
+
import { i as scrubSecrets, n as protectSecrets, o as urlSecrets, r as scrubError } from "./secret-config-Dhb6pqTU.mjs";
|
|
3
|
+
import { i as stringifyForLog } from "./safe-stringify-B5p5ktFe.mjs";
|
|
4
|
+
import { a as httpRequest, t as BatchBuffer } from "./batch-buffer-BvXLDPlV.mjs";
|
|
5
|
+
// src/transports/azure-monitor.transport.ts
|
|
6
6
|
/**
|
|
7
7
|
* Azure AD tenant IDs are either a GUID or a verified domain (e.g. `contoso.onmicrosoft.com`).
|
|
8
8
|
* This pattern is deliberately permissive on structure but strict on character
|
|
@@ -32,6 +32,7 @@ var AzureMonitorTransport = class {
|
|
|
32
32
|
this.flushTimer = null;
|
|
33
33
|
this.accessToken = null;
|
|
34
34
|
this.tokenExpiry = 0;
|
|
35
|
+
protectSecrets(this, ["clientSecret", "accessToken"]);
|
|
35
36
|
this.endpoint = config.endpoint.replace(/\/$/, "");
|
|
36
37
|
this.ruleId = config.ruleId;
|
|
37
38
|
this.streamName = config.streamName;
|
|
@@ -41,12 +42,13 @@ var AzureMonitorTransport = class {
|
|
|
41
42
|
this.batchSize = config.batchSize ?? 200;
|
|
42
43
|
this.flushInterval = config.flushIntervalMs ?? 5e3;
|
|
43
44
|
this.level = config.level;
|
|
44
|
-
this.requestTimeoutMs = config.requestTimeoutMs ??
|
|
45
|
+
this.requestTimeoutMs = config.requestTimeoutMs ?? 1e4;
|
|
45
46
|
this.buffer = new BatchBuffer({
|
|
46
47
|
name: "AzureMonitorTransport",
|
|
47
48
|
batchSize: this.batchSize,
|
|
48
|
-
maxBufferSize: config.maxBufferSize ??
|
|
49
|
-
send: (entries) => this.sendEntries(entries)
|
|
49
|
+
maxBufferSize: config.maxBufferSize ?? 1e4,
|
|
50
|
+
send: (entries) => this.sendEntries(entries),
|
|
51
|
+
secrets: () => this.secretValues()
|
|
50
52
|
});
|
|
51
53
|
this.flushTimer = setInterval(() => {
|
|
52
54
|
this.flush().catch(() => {});
|
|
@@ -83,6 +85,14 @@ var AzureMonitorTransport = class {
|
|
|
83
85
|
Properties: stringifyForLog(entry.data ?? {})
|
|
84
86
|
};
|
|
85
87
|
}
|
|
88
|
+
secretValues(token) {
|
|
89
|
+
return [
|
|
90
|
+
this.clientSecret,
|
|
91
|
+
this.accessToken ?? void 0,
|
|
92
|
+
token,
|
|
93
|
+
...urlSecrets(this.endpoint)
|
|
94
|
+
];
|
|
95
|
+
}
|
|
86
96
|
async getAccessToken() {
|
|
87
97
|
if (this.accessToken && Date.now() < this.tokenExpiry) return this.accessToken;
|
|
88
98
|
if (!this.tenantId || !this.clientId || !this.clientSecret) {
|
|
@@ -107,7 +117,8 @@ var AzureMonitorTransport = class {
|
|
|
107
117
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
108
118
|
body,
|
|
109
119
|
timeoutMs: this.requestTimeoutMs,
|
|
110
|
-
label: "Azure token request"
|
|
120
|
+
label: "Azure token request",
|
|
121
|
+
secrets: () => this.secretValues()
|
|
111
122
|
});
|
|
112
123
|
const parsed = JSON.parse(res.body);
|
|
113
124
|
if (!parsed.access_token) return null;
|
|
@@ -122,12 +133,13 @@ var AzureMonitorTransport = class {
|
|
|
122
133
|
async sendEntries(entries) {
|
|
123
134
|
const token = await this.getAccessToken();
|
|
124
135
|
if (!token) throw new Error("AzureMonitorTransport: no access token available");
|
|
125
|
-
const
|
|
136
|
+
const records = entries.map((e) => this.toAzureRecord(e));
|
|
137
|
+
const body = stringifyForLog(records);
|
|
126
138
|
let reqUrl;
|
|
127
139
|
try {
|
|
128
140
|
reqUrl = new URL(`dataCollectionRules/${encodeURIComponent(this.ruleId)}/streams/${encodeURIComponent(this.streamName)}?api-version=2023-01-01`, this.endpoint.endsWith("/") ? this.endpoint : `${this.endpoint}/`);
|
|
129
141
|
} catch (error) {
|
|
130
|
-
internalError(`AzureMonitorTransport: invalid endpoint "${this.endpoint}"`, error);
|
|
142
|
+
internalError(`AzureMonitorTransport: invalid endpoint "${scrubSecrets(this.endpoint, urlSecrets(this.endpoint))}"`, scrubError(error, urlSecrets(this.endpoint)));
|
|
131
143
|
return;
|
|
132
144
|
}
|
|
133
145
|
if (reqUrl.protocol !== "https:") {
|
|
@@ -142,11 +154,11 @@ var AzureMonitorTransport = class {
|
|
|
142
154
|
},
|
|
143
155
|
body,
|
|
144
156
|
timeoutMs: this.requestTimeoutMs,
|
|
145
|
-
label: "Azure Monitor API"
|
|
157
|
+
label: "Azure Monitor API",
|
|
158
|
+
secrets: () => this.secretValues(token)
|
|
146
159
|
});
|
|
147
160
|
}
|
|
148
161
|
};
|
|
149
|
-
|
|
150
|
-
//#endregion
|
|
151
162
|
export { AzureMonitorTransport as t };
|
|
152
|
-
|
|
163
|
+
|
|
164
|
+
//# sourceMappingURL=azure-monitor.transport-C1RWAumT.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"azure-monitor.transport-C1RWAumT.mjs","names":[],"sources":["../src/transports/azure-monitor.transport.ts"],"sourcesContent":["/**\n * logixia — Azure Monitor / Application Insights transport\n *\n * Sends log entries to Azure Monitor via the Data Collection Rules (DCR) API\n * using the Logs Ingestion API (the modern replacement for the legacy HTTP\n * Data Collector API).\n *\n * Maps logixia levels to Application Insights severity levels:\n * verbose → 0, debug → 1, info → 1, warn → 2, error → 3, critical → 4\n *\n * @example\n * ```ts\n * import { createLogger } from 'logixia';\n * import { AzureMonitorTransport } from 'logixia/azure';\n *\n * const logger = createLogger({\n * transports: {\n * custom: [\n * new AzureMonitorTransport({\n * // Logs Ingestion API endpoint (from your DCR)\n * endpoint: 'https://<dce>.ingest.monitor.azure.com',\n * ruleId: 'dcr-xxxxxxxxxxxxxxxx',\n * streamName: 'Custom-LogixiaLogs',\n * // Client credentials are required; managed identity is not supported.\n * tenantId: process.env.AZURE_TENANT_ID,\n * clientId: process.env.AZURE_CLIENT_ID,\n * clientSecret: process.env.AZURE_CLIENT_SECRET,\n * }),\n * ],\n * },\n * });\n * ```\n */\n\nimport type { IAsyncTransport, TransportLogEntry } from '../types/transport.types';\nimport { internalError, internalWarn } from '../utils/internal-log';\nimport { stringifyForLog } from '../utils/safe-stringify';\nimport {\n BatchBuffer,\n DEFAULT_MAX_BUFFER_SIZE,\n DEFAULT_REQUEST_TIMEOUT_MS,\n httpRequest,\n} from './batch-buffer';\nimport { protectSecrets, scrubError, scrubSecrets, urlSecrets } from './secret-config';\n\n/**\n * Azure AD tenant IDs are either a GUID or a verified domain (e.g. `contoso.onmicrosoft.com`).\n * This pattern is deliberately permissive on structure but strict on character\n * set — it rejects the breakout characters (`/`, `@`, `:`, `?`, `#`, whitespace)\n * that would let a hostile config smuggle a different host, path, or query into\n * the OAuth token URL.\n */\nconst AZURE_TENANT_RE = /^[a-z0-9][a-z0-9.-]{1,253}$/i;\n\nexport interface AzureMonitorTransportConfig {\n /** DCE (Data Collection Endpoint) URL, e.g. `https://<name>.ingest.monitor.azure.com`. */\n endpoint: string;\n /** Data Collection Rule immutable ID (from Azure portal). */\n ruleId: string;\n /** Stream name defined in the DCR, e.g. `'Custom-LogixiaLogs_CL'`. */\n streamName: string;\n /** Azure AD tenant ID for OAuth2 client-credentials flow. */\n tenantId?: string;\n /** Azure AD app (service principal) client ID. */\n clientId?: string;\n /** Azure AD app client secret. */\n clientSecret?: string;\n /** Number of entries to batch. @default 200 */\n batchSize?: number;\n /** Flush interval in ms. @default 5000 */\n flushIntervalMs?: number;\n /** Abort a request that has not finished after this many ms. @default 10000 */\n requestTimeoutMs?: number;\n /** Max buffered entries; the oldest are dropped past this. @default 10000 */\n maxBufferSize?: number;\n level?: string;\n}\n\nconst SEVERITY_MAP: Record<string, number> = {\n verbose: 0,\n trace: 0,\n debug: 1,\n info: 1,\n log: 1,\n warn: 2,\n warning: 2,\n error: 3,\n critical: 4,\n fatal: 4,\n};\n\n/**\n * Azure Monitor Logs Ingestion transport.\n */\nexport class AzureMonitorTransport implements IAsyncTransport {\n public readonly name = 'azure-monitor';\n public readonly batchSize: number;\n public readonly flushInterval: number;\n public readonly level: string | undefined;\n\n private readonly buffer: BatchBuffer<TransportLogEntry>;\n private readonly requestTimeoutMs: number;\n private flushTimer: NodeJS.Timeout | null = null;\n private accessToken: string | null = null;\n private tokenExpiry = 0;\n\n private readonly endpoint: string;\n private readonly ruleId: string;\n private readonly streamName: string;\n private readonly tenantId: string | undefined;\n private readonly clientId: string | undefined;\n private readonly clientSecret: string | undefined;\n\n constructor(config: AzureMonitorTransportConfig) {\n protectSecrets(this, ['clientSecret', 'accessToken']);\n this.endpoint = config.endpoint.replace(/\\/$/, '');\n this.ruleId = config.ruleId;\n this.streamName = config.streamName;\n this.tenantId = config.tenantId ?? process.env['AZURE_TENANT_ID'];\n this.clientId = config.clientId ?? process.env['AZURE_CLIENT_ID'];\n this.clientSecret = config.clientSecret ?? process.env['AZURE_CLIENT_SECRET'];\n this.batchSize = config.batchSize ?? 200;\n this.flushInterval = config.flushIntervalMs ?? 5000;\n this.level = config.level;\n this.requestTimeoutMs = config.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;\n this.buffer = new BatchBuffer<TransportLogEntry>({\n name: 'AzureMonitorTransport',\n batchSize: this.batchSize,\n maxBufferSize: config.maxBufferSize ?? DEFAULT_MAX_BUFFER_SIZE,\n send: (entries) => this.sendEntries(entries),\n secrets: () => this.secretValues(),\n });\n\n this.flushTimer = setInterval(() => {\n this.flush().catch(() => {});\n }, this.flushInterval);\n if (this.flushTimer.unref) this.flushTimer.unref();\n }\n\n write(entry: TransportLogEntry): void {\n this.buffer.push(entry);\n this.buffer.flushIfFull();\n }\n\n flush(): Promise<void> {\n return this.buffer.flush();\n }\n\n /**\n * Flush remaining entries and stop the interval timer on shutdown. Without\n * this the manager's close() skipped the transport (close was undefined) and\n * buffered entries were lost on deploy. Waits for any in-flight send first.\n */\n async close(): Promise<void> {\n if (this.flushTimer) {\n clearInterval(this.flushTimer);\n this.flushTimer = null;\n }\n await this.buffer.close();\n }\n\n private toAzureRecord(entry: TransportLogEntry): Record<string, unknown> {\n return {\n TimeGenerated: entry.timestamp ?? new Date().toISOString(),\n SeverityLevel: SEVERITY_MAP[entry.level.toLowerCase()] ?? 1,\n Message: entry.message,\n AppName: entry.appName,\n Context: entry.context ?? '',\n TraceId: entry.traceId ?? '',\n Properties: stringifyForLog(entry.data ?? {}),\n };\n }\n\n private secretValues(token?: string): (string | undefined)[] {\n return [this.clientSecret, this.accessToken ?? undefined, token, ...urlSecrets(this.endpoint)];\n }\n\n private async getAccessToken(): Promise<string | null> {\n if (this.accessToken && Date.now() < this.tokenExpiry) return this.accessToken;\n\n if (!this.tenantId || !this.clientId || !this.clientSecret) {\n internalWarn(\n 'AzureMonitorTransport: missing credentials — set tenantId, clientId, clientSecret'\n );\n return null;\n }\n\n const body = new URLSearchParams({\n grant_type: 'client_credentials',\n client_id: this.clientId,\n client_secret: this.clientSecret,\n scope: 'https://monitor.azure.com/.default',\n }).toString();\n\n const tenantId = this.tenantId;\n if (!AZURE_TENANT_RE.test(tenantId)) {\n internalWarn(\n `AzureMonitorTransport: refusing to request token — tenantId \"${tenantId}\" is not a valid GUID or domain`\n );\n return null;\n }\n\n const reqUrl = new URL(\n `https://login.microsoftonline.com/${encodeURIComponent(tenantId)}/oauth2/v2.0/token`\n );\n try {\n const res = await httpRequest({\n url: reqUrl,\n headers: { 'Content-Type': 'application/x-www-form-urlencoded' },\n body,\n timeoutMs: this.requestTimeoutMs,\n label: 'Azure token request',\n secrets: () => this.secretValues(),\n });\n const parsed = JSON.parse(res.body) as { access_token?: string; expires_in?: number };\n if (!parsed.access_token) return null;\n this.accessToken = parsed.access_token;\n this.tokenExpiry = Date.now() + (parsed.expires_in ?? 3600) * 1000 - 60_000;\n return this.accessToken;\n } catch (err) {\n internalError('AzureMonitorTransport token request failed', err);\n return null;\n }\n }\n\n private async sendEntries(entries: TransportLogEntry[]): Promise<void> {\n const token = await this.getAccessToken();\n if (!token) throw new Error('AzureMonitorTransport: no access token available');\n\n const records = entries.map((e) => this.toAzureRecord(e));\n const body = stringifyForLog(records);\n let reqUrl: URL;\n try {\n // Build from the user-configured DCE endpoint; encodeURIComponent-ing the\n // ruleId/streamName stops a hostile config from smuggling extra path\n // segments or query params into the request.\n reqUrl = new URL(\n `dataCollectionRules/${encodeURIComponent(this.ruleId)}/streams/${encodeURIComponent(this.streamName)}?api-version=2023-01-01`,\n this.endpoint.endsWith('/') ? this.endpoint : `${this.endpoint}/`\n );\n } catch (error) {\n internalError(\n `AzureMonitorTransport: invalid endpoint \"${scrubSecrets(this.endpoint, urlSecrets(this.endpoint))}\"`,\n scrubError(error, urlSecrets(this.endpoint))\n );\n return;\n }\n if (reqUrl.protocol !== 'https:') {\n internalError(`AzureMonitorTransport: endpoint must use https (got ${reqUrl.protocol})`);\n return;\n }\n\n await httpRequest({\n url: reqUrl,\n headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },\n body,\n timeoutMs: this.requestTimeoutMs,\n label: 'Azure Monitor API',\n secrets: () => this.secretValues(token),\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;AAoDA,MAAM,kBAAkB;AA0BxB,MAAM,eAAuC;CAC3C,SAAS;CACT,OAAO;CACP,OAAO;CACP,MAAM;CACN,KAAK;CACL,MAAM;CACN,SAAS;CACT,OAAO;CACP,UAAU;CACV,OAAO;AACT;;;;AAKA,IAAa,wBAAb,MAA8D;CAmB5D,YAAY,QAAqC;EAlB1B,KAAA,OAAA;EAOqB,KAAA,aAAA;EACP,KAAA,cAAA;EACf,KAAA,cAAA;EAUpB,eAAe,MAAM,CAAC,gBAAgB,aAAa,CAAC;EACpD,KAAK,WAAW,OAAO,SAAS,QAAQ,OAAO,EAAE;EACjD,KAAK,SAAS,OAAO;EACrB,KAAK,aAAa,OAAO;EACzB,KAAK,WAAW,OAAO,YAAY,QAAQ,IAAI;EAC/C,KAAK,WAAW,OAAO,YAAY,QAAQ,IAAI;EAC/C,KAAK,eAAe,OAAO,gBAAgB,QAAQ,IAAI;EACvD,KAAK,YAAY,OAAO,aAAa;EACrC,KAAK,gBAAgB,OAAO,mBAAmB;EAC/C,KAAK,QAAQ,OAAO;EACpB,KAAK,mBAAmB,OAAO,oBAAA;EAC/B,KAAK,SAAS,IAAI,YAA+B;GAC/C,MAAM;GACN,WAAW,KAAK;GAChB,eAAe,OAAO,iBAAA;GACtB,OAAO,Y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gB;GAAmB;GAChF;GACA,WAAW,KAAK;GAChB,OAAO;GACP,eAAe,KAAK,aAAa,KAAK;EACxC,CAAC;CACH;AACF"}
|
package/dist/{azure-monitor.transport-D7Da4RAb.d.mts → azure-monitor.transport-CbSHOnNX.d.mts}
RENAMED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/transports/azure-monitor.transport.d.ts
|
|
4
|
-
|
|
1
|
+
import { _ as TransportLogEntry, l as IAsyncTransport } from "./transport.types-CzJq4IrF.mjs";
|
|
5
2
|
interface AzureMonitorTransportConfig {
|
|
6
3
|
/** DCE (Data Collection Endpoint) URL, e.g. `https://<name>.ingest.monitor.azure.com`. */
|
|
7
4
|
endpoint: string;
|
|
@@ -54,9 +51,9 @@ declare class AzureMonitorTransport implements IAsyncTransport {
|
|
|
54
51
|
*/
|
|
55
52
|
close(): Promise<void>;
|
|
56
53
|
private toAzureRecord;
|
|
54
|
+
private secretValues;
|
|
57
55
|
private getAccessToken;
|
|
58
56
|
private sendEntries;
|
|
59
57
|
}
|
|
60
|
-
//#endregion
|
|
61
58
|
export { AzureMonitorTransportConfig as n, AzureMonitorTransport as t };
|
|
62
|
-
//# sourceMappingURL=azure-monitor.transport-
|
|
59
|
+
//# sourceMappingURL=azure-monitor.transport-CbSHOnNX.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"azure-monitor.transport-CbSHOnNX.d.mts","names":[],"sources":["../src/transports/azure-monitor.transport.ts"],"mappings":";UAsDiB;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;EACA;;;;;cAmBW,iCAAiC;WAC5B;WACA;WACA;WACA;mBAEC;mBACA;UACT;UACA;UACA;mBAES;mBACA;mBACA;mBACA;mBACA;mBACA;EAEL,YAAA,QAAQ;EA0BpB,MAAM,OAAO;EAKb,SAAS;;;;;;EASH,SAAS;UAQP;UAYA;UAIM;UAgDA"}
|
package/dist/azure.d.mts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import "./transport
|
|
2
|
-
import { n as AzureMonitorTransportConfig, t as AzureMonitorTransport } from "./azure-monitor.transport-D7Da4RAb.mjs";
|
|
1
|
+
import { n as AzureMonitorTransportConfig, t as AzureMonitorTransport } from "./azure-monitor.transport-CbSHOnNX.mjs";
|
|
3
2
|
export { AzureMonitorTransport, AzureMonitorTransportConfig };
|
package/dist/azure.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import "./transport
|
|
2
|
-
import { n as AzureMonitorTransportConfig, t as AzureMonitorTransport } from "./azure-monitor.transport-Cn_3Usvu.js";
|
|
1
|
+
import { n as AzureMonitorTransportConfig, t as AzureMonitorTransport } from "./azure-monitor.transport-Bvf7Xegt.js";
|
|
3
2
|
export { AzureMonitorTransport, AzureMonitorTransportConfig };
|