apitally 0.22.0 → 0.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/sentry.cjs +4 -1
- package/dist/common/sentry.cjs.map +1 -1
- package/dist/common/sentry.js +4 -1
- package/dist/common/sentry.js.map +1 -1
- package/dist/loggers/nestjs.cjs +4 -1
- package/dist/loggers/nestjs.cjs.map +1 -1
- package/dist/loggers/nestjs.js +4 -1
- package/dist/loggers/nestjs.js.map +1 -1
- package/dist/loggers/pino.cjs +4 -1
- package/dist/loggers/pino.cjs.map +1 -1
- package/dist/loggers/pino.js +4 -1
- package/dist/loggers/pino.js.map +1 -1
- package/dist/loggers/winston.cjs +5 -1
- package/dist/loggers/winston.cjs.map +1 -1
- package/dist/loggers/winston.js +5 -1
- package/dist/loggers/winston.js.map +1 -1
- package/package.json +6 -2
package/dist/common/sentry.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/common/sentry.ts"],"sourcesContent":["import type * as Sentry from \"@sentry/node\";\n\nlet sentry: typeof Sentry | undefined;\n\n// Initialize Sentry when the module is loaded\n(async () => {\n try {\n sentry = await import(\"@sentry/node\");\n } catch (e) {\n // Sentry SDK is not installed, ignore\n }\n})();\n\n/**\n * Returns the last Sentry event ID if available\n */\nexport function getSentryEventId(): string | undefined {\n if (sentry && sentry.lastEventId) {\n return sentry.lastEventId();\n }\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;;;;;AAAA,IAAIA;CAGH,YAAA;AACC,MAAI;AACFA,aAAS,MAAM
|
|
1
|
+
{"version":3,"sources":["../../src/common/sentry.ts"],"sourcesContent":["import type * as Sentry from \"@sentry/node\";\n\nlet sentry: typeof Sentry | undefined;\n\n// Initialize Sentry when the module is loaded\n(async () => {\n try {\n sentry = await import(/* webpackIgnore: true */ \"@sentry/node\");\n } catch (e) {\n // Sentry SDK is not installed, ignore\n }\n})();\n\n/**\n * Returns the last Sentry event ID if available\n */\nexport function getSentryEventId(): string | undefined {\n if (sentry && sentry.lastEventId) {\n return sentry.lastEventId();\n }\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;;;;;AAAA,IAAIA;CAGH,YAAA;AACC,MAAI;AACFA,aAAS,MAAM;;MAAiC;IAAA;EAClD,SAASC,GAAG;EAEZ;AACF,GAAA;AAKO,SAASC,mBAAAA;AACd,MAAIF,UAAUA,OAAOG,aAAa;AAChC,WAAOH,OAAOG,YAAW;EAC3B;AACA,SAAOC;AACT;AALgBF;","names":["sentry","e","getSentryEventId","lastEventId","undefined"]}
|
package/dist/common/sentry.js
CHANGED
|
@@ -3,7 +3,10 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
3
3
|
let sentry;
|
|
4
4
|
(async () => {
|
|
5
5
|
try {
|
|
6
|
-
sentry = await import(
|
|
6
|
+
sentry = await import(
|
|
7
|
+
/* webpackIgnore: true */
|
|
8
|
+
"@sentry/node"
|
|
9
|
+
);
|
|
7
10
|
} catch (e) {
|
|
8
11
|
}
|
|
9
12
|
})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/common/sentry.ts"],"sourcesContent":["import type * as Sentry from \"@sentry/node\";\n\nlet sentry: typeof Sentry | undefined;\n\n// Initialize Sentry when the module is loaded\n(async () => {\n try {\n sentry = await import(\"@sentry/node\");\n } catch (e) {\n // Sentry SDK is not installed, ignore\n }\n})();\n\n/**\n * Returns the last Sentry event ID if available\n */\nexport function getSentryEventId(): string | undefined {\n if (sentry && sentry.lastEventId) {\n return sentry.lastEventId();\n }\n return undefined;\n}\n"],"mappings":";;AAEA,IAAIA;CAGH,YAAA;AACC,MAAI;AACFA,aAAS,MAAM
|
|
1
|
+
{"version":3,"sources":["../../src/common/sentry.ts"],"sourcesContent":["import type * as Sentry from \"@sentry/node\";\n\nlet sentry: typeof Sentry | undefined;\n\n// Initialize Sentry when the module is loaded\n(async () => {\n try {\n sentry = await import(/* webpackIgnore: true */ \"@sentry/node\");\n } catch (e) {\n // Sentry SDK is not installed, ignore\n }\n})();\n\n/**\n * Returns the last Sentry event ID if available\n */\nexport function getSentryEventId(): string | undefined {\n if (sentry && sentry.lastEventId) {\n return sentry.lastEventId();\n }\n return undefined;\n}\n"],"mappings":";;AAEA,IAAIA;CAGH,YAAA;AACC,MAAI;AACFA,aAAS,MAAM;;MAAiC;IAAA;EAClD,SAASC,GAAG;EAEZ;AACF,GAAA;AAKO,SAASC,mBAAAA;AACd,MAAIF,UAAUA,OAAOG,aAAa;AAChC,WAAOH,OAAOG,YAAW;EAC3B;AACA,SAAOC;AACT;AALgBF;","names":["sentry","e","getSentryEventId","lastEventId","undefined"]}
|
package/dist/loggers/nestjs.cjs
CHANGED
|
@@ -42,7 +42,10 @@ async function patchNestLogger(logsContext) {
|
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
44
|
try {
|
|
45
|
-
const { Logger } = await import(
|
|
45
|
+
const { Logger } = await import(
|
|
46
|
+
/* webpackIgnore: true */
|
|
47
|
+
"@nestjs/common"
|
|
48
|
+
);
|
|
46
49
|
const logMethods = [
|
|
47
50
|
"log",
|
|
48
51
|
"error",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/loggers/nestjs.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\n\nimport type { LogRecord } from \"../common/requestLogger.js\";\nimport { formatMessage } from \"./utils.js\";\n\ntype LogLevel = \"log\" | \"error\" | \"warn\" | \"debug\" | \"verbose\" | \"fatal\";\n\nconst MAX_BUFFER_SIZE = 1000;\n\nlet isPatched = false;\nlet globalLogsContext: AsyncLocalStorage<LogRecord[]>;\n\nexport async function patchNestLogger(\n logsContext: AsyncLocalStorage<LogRecord[]>,\n) {\n globalLogsContext = logsContext;\n\n if (isPatched) {\n return;\n }\n\n try {\n const { Logger } = await import(\"@nestjs/common\");\n const logMethods: LogLevel[] = [\n \"log\",\n \"error\",\n \"warn\",\n \"debug\",\n \"verbose\",\n \"fatal\",\n ];\n\n // Patch static methods\n logMethods.forEach((method) => {\n const originalMethod = Logger[method];\n Logger[method] = function (message: any, ...args: any[]) {\n captureLog(method, [message, ...args]);\n return originalMethod.apply(Logger, [message, ...args]);\n };\n });\n\n // Patch prototype methods to affect all instances (new and existing)\n logMethods.forEach((method) => {\n const originalMethod = Logger.prototype[method];\n Logger.prototype[method] = function (message: any, ...args: any[]) {\n captureLog(method, [message, ...args], this.context);\n return originalMethod.apply(this, [message, ...args]);\n };\n });\n\n isPatched = true;\n } catch {\n // @nestjs/common is not installed, silently ignore\n }\n}\n\nfunction captureLog(level: LogLevel, args: any[], context?: string) {\n const logs = globalLogsContext?.getStore();\n if (logs && logs.length < MAX_BUFFER_SIZE) {\n logs.push({\n timestamp: Date.now() / 1000,\n logger: context,\n level,\n message: formatMessage(args[0], ...args.slice(1)),\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;;;;AAAA,mBAA8B;AAI9B,MAAMA,kBAAkB;AAExB,IAAIC,YAAY;AAChB,IAAIC;AAEJ,eAAsBC,gBACpBC,aAA2C;AAE3CF,sBAAoBE;AAEpB,MAAIH,WAAW;AACb;EACF;AAEA,MAAI;AACF,UAAM,EAAEI,OAAM,IAAK,MAAM
|
|
1
|
+
{"version":3,"sources":["../../src/loggers/nestjs.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\n\nimport type { LogRecord } from \"../common/requestLogger.js\";\nimport { formatMessage } from \"./utils.js\";\n\ntype LogLevel = \"log\" | \"error\" | \"warn\" | \"debug\" | \"verbose\" | \"fatal\";\n\nconst MAX_BUFFER_SIZE = 1000;\n\nlet isPatched = false;\nlet globalLogsContext: AsyncLocalStorage<LogRecord[]>;\n\nexport async function patchNestLogger(\n logsContext: AsyncLocalStorage<LogRecord[]>,\n) {\n globalLogsContext = logsContext;\n\n if (isPatched) {\n return;\n }\n\n try {\n const { Logger } = await import(/* webpackIgnore: true */ \"@nestjs/common\");\n const logMethods: LogLevel[] = [\n \"log\",\n \"error\",\n \"warn\",\n \"debug\",\n \"verbose\",\n \"fatal\",\n ];\n\n // Patch static methods\n logMethods.forEach((method) => {\n const originalMethod = Logger[method];\n Logger[method] = function (message: any, ...args: any[]) {\n captureLog(method, [message, ...args]);\n return originalMethod.apply(Logger, [message, ...args]);\n };\n });\n\n // Patch prototype methods to affect all instances (new and existing)\n logMethods.forEach((method) => {\n const originalMethod = Logger.prototype[method];\n Logger.prototype[method] = function (message: any, ...args: any[]) {\n captureLog(method, [message, ...args], this.context);\n return originalMethod.apply(this, [message, ...args]);\n };\n });\n\n isPatched = true;\n } catch {\n // @nestjs/common is not installed, silently ignore\n }\n}\n\nfunction captureLog(level: LogLevel, args: any[], context?: string) {\n const logs = globalLogsContext?.getStore();\n if (logs && logs.length < MAX_BUFFER_SIZE) {\n logs.push({\n timestamp: Date.now() / 1000,\n logger: context,\n level,\n message: formatMessage(args[0], ...args.slice(1)),\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;;;;AAAA,mBAA8B;AAI9B,MAAMA,kBAAkB;AAExB,IAAIC,YAAY;AAChB,IAAIC;AAEJ,eAAsBC,gBACpBC,aAA2C;AAE3CF,sBAAoBE;AAEpB,MAAIH,WAAW;AACb;EACF;AAEA,MAAI;AACF,UAAM,EAAEI,OAAM,IAAK,MAAM;;MAAiC;IAAA;AAC1D,UAAMC,aAAyB;MAC7B;MACA;MACA;MACA;MACA;MACA;;AAIFA,eAAWC,QAAQ,CAACC,WAAAA;AAClB,YAAMC,iBAAiBJ,OAAOG,MAAAA;AAC9BH,aAAOG,MAAAA,IAAU,SAAUE,YAAiBC,MAAW;AACrDC,mBAAWJ,QAAQ;UAACE;aAAYC;SAAK;AACrC,eAAOF,eAAeI,MAAMR,QAAQ;UAACK;aAAYC;SAAK;MACxD;IACF,CAAA;AAGAL,eAAWC,QAAQ,CAACC,WAAAA;AAClB,YAAMC,iBAAiBJ,OAAOS,UAAUN,MAAAA;AACxCH,aAAOS,UAAUN,MAAAA,IAAU,SAAUE,YAAiBC,MAAW;AAC/DC,mBAAWJ,QAAQ;UAACE;aAAYC;WAAO,KAAKI,OAAO;AACnD,eAAON,eAAeI,MAAM,MAAM;UAACH;aAAYC;SAAK;MACtD;IACF,CAAA;AAEAV,gBAAY;EACd,QAAQ;EAER;AACF;AA1CsBE;AA4CtB,SAASS,WAAWI,OAAiBL,MAAaI,SAAgB;AAChE,QAAME,OAAOf,uDAAmBgB;AAChC,MAAID,QAAQA,KAAKE,SAASnB,iBAAiB;AACzCiB,SAAKG,KAAK;MACRC,WAAWC,KAAKC,IAAG,IAAK;MACxBC,QAAQT;MACRC;MACAN,aAASe,4BAAcd,KAAK,CAAA,GAAE,GAAKA,KAAKe,MAAM,CAAA,CAAA;IAChD,CAAA;EACF;AACF;AAVSd;","names":["MAX_BUFFER_SIZE","isPatched","globalLogsContext","patchNestLogger","logsContext","Logger","logMethods","forEach","method","originalMethod","message","args","captureLog","apply","prototype","context","level","logs","getStore","length","push","timestamp","Date","now","logger","formatMessage","slice"]}
|
package/dist/loggers/nestjs.js
CHANGED
|
@@ -10,7 +10,10 @@ async function patchNestLogger(logsContext) {
|
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
12
|
try {
|
|
13
|
-
const { Logger } = await import(
|
|
13
|
+
const { Logger } = await import(
|
|
14
|
+
/* webpackIgnore: true */
|
|
15
|
+
"@nestjs/common"
|
|
16
|
+
);
|
|
14
17
|
const logMethods = [
|
|
15
18
|
"log",
|
|
16
19
|
"error",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/loggers/nestjs.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\n\nimport type { LogRecord } from \"../common/requestLogger.js\";\nimport { formatMessage } from \"./utils.js\";\n\ntype LogLevel = \"log\" | \"error\" | \"warn\" | \"debug\" | \"verbose\" | \"fatal\";\n\nconst MAX_BUFFER_SIZE = 1000;\n\nlet isPatched = false;\nlet globalLogsContext: AsyncLocalStorage<LogRecord[]>;\n\nexport async function patchNestLogger(\n logsContext: AsyncLocalStorage<LogRecord[]>,\n) {\n globalLogsContext = logsContext;\n\n if (isPatched) {\n return;\n }\n\n try {\n const { Logger } = await import(\"@nestjs/common\");\n const logMethods: LogLevel[] = [\n \"log\",\n \"error\",\n \"warn\",\n \"debug\",\n \"verbose\",\n \"fatal\",\n ];\n\n // Patch static methods\n logMethods.forEach((method) => {\n const originalMethod = Logger[method];\n Logger[method] = function (message: any, ...args: any[]) {\n captureLog(method, [message, ...args]);\n return originalMethod.apply(Logger, [message, ...args]);\n };\n });\n\n // Patch prototype methods to affect all instances (new and existing)\n logMethods.forEach((method) => {\n const originalMethod = Logger.prototype[method];\n Logger.prototype[method] = function (message: any, ...args: any[]) {\n captureLog(method, [message, ...args], this.context);\n return originalMethod.apply(this, [message, ...args]);\n };\n });\n\n isPatched = true;\n } catch {\n // @nestjs/common is not installed, silently ignore\n }\n}\n\nfunction captureLog(level: LogLevel, args: any[], context?: string) {\n const logs = globalLogsContext?.getStore();\n if (logs && logs.length < MAX_BUFFER_SIZE) {\n logs.push({\n timestamp: Date.now() / 1000,\n logger: context,\n level,\n message: formatMessage(args[0], ...args.slice(1)),\n });\n }\n}\n"],"mappings":";;AAGA,SAASA,qBAAqB;AAI9B,MAAMC,kBAAkB;AAExB,IAAIC,YAAY;AAChB,IAAIC;AAEJ,eAAsBC,gBACpBC,aAA2C;AAE3CF,sBAAoBE;AAEpB,MAAIH,WAAW;AACb;EACF;AAEA,MAAI;AACF,UAAM,EAAEI,OAAM,IAAK,MAAM
|
|
1
|
+
{"version":3,"sources":["../../src/loggers/nestjs.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\n\nimport type { LogRecord } from \"../common/requestLogger.js\";\nimport { formatMessage } from \"./utils.js\";\n\ntype LogLevel = \"log\" | \"error\" | \"warn\" | \"debug\" | \"verbose\" | \"fatal\";\n\nconst MAX_BUFFER_SIZE = 1000;\n\nlet isPatched = false;\nlet globalLogsContext: AsyncLocalStorage<LogRecord[]>;\n\nexport async function patchNestLogger(\n logsContext: AsyncLocalStorage<LogRecord[]>,\n) {\n globalLogsContext = logsContext;\n\n if (isPatched) {\n return;\n }\n\n try {\n const { Logger } = await import(/* webpackIgnore: true */ \"@nestjs/common\");\n const logMethods: LogLevel[] = [\n \"log\",\n \"error\",\n \"warn\",\n \"debug\",\n \"verbose\",\n \"fatal\",\n ];\n\n // Patch static methods\n logMethods.forEach((method) => {\n const originalMethod = Logger[method];\n Logger[method] = function (message: any, ...args: any[]) {\n captureLog(method, [message, ...args]);\n return originalMethod.apply(Logger, [message, ...args]);\n };\n });\n\n // Patch prototype methods to affect all instances (new and existing)\n logMethods.forEach((method) => {\n const originalMethod = Logger.prototype[method];\n Logger.prototype[method] = function (message: any, ...args: any[]) {\n captureLog(method, [message, ...args], this.context);\n return originalMethod.apply(this, [message, ...args]);\n };\n });\n\n isPatched = true;\n } catch {\n // @nestjs/common is not installed, silently ignore\n }\n}\n\nfunction captureLog(level: LogLevel, args: any[], context?: string) {\n const logs = globalLogsContext?.getStore();\n if (logs && logs.length < MAX_BUFFER_SIZE) {\n logs.push({\n timestamp: Date.now() / 1000,\n logger: context,\n level,\n message: formatMessage(args[0], ...args.slice(1)),\n });\n }\n}\n"],"mappings":";;AAGA,SAASA,qBAAqB;AAI9B,MAAMC,kBAAkB;AAExB,IAAIC,YAAY;AAChB,IAAIC;AAEJ,eAAsBC,gBACpBC,aAA2C;AAE3CF,sBAAoBE;AAEpB,MAAIH,WAAW;AACb;EACF;AAEA,MAAI;AACF,UAAM,EAAEI,OAAM,IAAK,MAAM;;MAAiC;IAAA;AAC1D,UAAMC,aAAyB;MAC7B;MACA;MACA;MACA;MACA;MACA;;AAIFA,eAAWC,QAAQ,CAACC,WAAAA;AAClB,YAAMC,iBAAiBJ,OAAOG,MAAAA;AAC9BH,aAAOG,MAAAA,IAAU,SAAUE,YAAiBC,MAAW;AACrDC,mBAAWJ,QAAQ;UAACE;aAAYC;SAAK;AACrC,eAAOF,eAAeI,MAAMR,QAAQ;UAACK;aAAYC;SAAK;MACxD;IACF,CAAA;AAGAL,eAAWC,QAAQ,CAACC,WAAAA;AAClB,YAAMC,iBAAiBJ,OAAOS,UAAUN,MAAAA;AACxCH,aAAOS,UAAUN,MAAAA,IAAU,SAAUE,YAAiBC,MAAW;AAC/DC,mBAAWJ,QAAQ;UAACE;aAAYC;WAAO,KAAKI,OAAO;AACnD,eAAON,eAAeI,MAAM,MAAM;UAACH;aAAYC;SAAK;MACtD;IACF,CAAA;AAEAV,gBAAY;EACd,QAAQ;EAER;AACF;AA1CsBE;AA4CtB,SAASS,WAAWI,OAAiBL,MAAaI,SAAgB;AAChE,QAAME,OAAOf,uDAAmBgB;AAChC,MAAID,QAAQA,KAAKE,SAASnB,iBAAiB;AACzCiB,SAAKG,KAAK;MACRC,WAAWC,KAAKC,IAAG,IAAK;MACxBC,QAAQT;MACRC;MACAN,SAASX,cAAcY,KAAK,CAAA,GAAE,GAAKA,KAAKc,MAAM,CAAA,CAAA;IAChD,CAAA;EACF;AACF;AAVSb;","names":["formatMessage","MAX_BUFFER_SIZE","isPatched","globalLogsContext","patchNestLogger","logsContext","Logger","logMethods","forEach","method","originalMethod","message","args","captureLog","apply","prototype","context","level","logs","getStore","length","push","timestamp","Date","now","logger","slice"]}
|
package/dist/loggers/pino.cjs
CHANGED
|
@@ -60,7 +60,10 @@ async function patchPinoLogger(logger, logsContext) {
|
|
|
60
60
|
}
|
|
61
61
|
const originalStream = logger[originalStreamSym];
|
|
62
62
|
if (originalStream) {
|
|
63
|
-
const pino = await import(
|
|
63
|
+
const pino = await import(
|
|
64
|
+
/* webpackIgnore: true */
|
|
65
|
+
"pino"
|
|
66
|
+
);
|
|
64
67
|
const captureStream = new ApitallyLogCaptureStream(logsContext, logger[messageKeySym]);
|
|
65
68
|
logger[streamSym] = pino.default.multistream([
|
|
66
69
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/loggers/pino.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\n\nimport type { LogRecord } from \"../common/requestLogger.js\";\nimport { formatMessage, removeKeys } from \"./utils.js\";\n\nconst MAX_BUFFER_SIZE = 1000;\n\nconst originalStreamSym = Symbol.for(\"apitally.originalStream\");\nconst logLevelMap: Record<number, string> = {\n 10: \"trace\",\n 20: \"debug\",\n 30: \"info\",\n 40: \"warn\",\n 50: \"error\",\n 60: \"fatal\",\n};\n\nexport async function patchPinoLogger(\n logger: any,\n logsContext: AsyncLocalStorage<LogRecord[]>,\n) {\n try {\n // Find stream and message key symbols on the logger and its prototype\n const symbols = [\n ...Object.getOwnPropertySymbols(logger),\n ...Object.getOwnPropertySymbols(Object.getPrototypeOf(logger)),\n ];\n const streamSym = symbols.find(\n (sym) => sym.toString() === \"Symbol(pino.stream)\",\n );\n const messageKeySym = symbols.find(\n (sym) => sym.toString() === \"Symbol(pino.messageKey)\",\n );\n if (!streamSym || !messageKeySym) {\n // not a pino logger\n return false;\n }\n\n if (!(originalStreamSym in logger)) {\n logger[originalStreamSym] = logger[streamSym];\n }\n\n const originalStream = logger[originalStreamSym];\n if (originalStream) {\n const pino = await import(\"pino\");\n const captureStream = new ApitallyLogCaptureStream(\n logsContext,\n logger[messageKeySym],\n );\n logger[streamSym] = pino.default.multistream(\n [\n { level: 0, stream: originalStream },\n { level: 0, stream: captureStream },\n ],\n {\n levels: logger.levels,\n },\n );\n }\n return true;\n } catch {\n // ignore errors\n return false;\n }\n}\n\nfunction filterLogs(obj: any, messageKey: string) {\n return obj[messageKey] !== \"request completed\";\n}\n\nclass ApitallyLogCaptureStream {\n private logsContext: AsyncLocalStorage<LogRecord[]>;\n private messageKey: string;\n\n constructor(logsContext: AsyncLocalStorage<LogRecord[]>, messageKey: string) {\n this.logsContext = logsContext;\n this.messageKey = messageKey;\n }\n\n write(msg: string): void {\n const logs = this.logsContext.getStore();\n if (!logs || !msg || logs.length >= MAX_BUFFER_SIZE) {\n return;\n }\n\n let obj: any;\n try {\n obj = JSON.parse(msg);\n } catch (e) {\n return;\n }\n if (\n obj === null ||\n typeof obj !== \"object\" ||\n !filterLogs(obj, this.messageKey)\n ) {\n return;\n }\n\n try {\n let message = obj[this.messageKey];\n const ignoreKeys = [\n \"hostname\",\n \"level\",\n this.messageKey,\n \"pid\",\n \"time\",\n \"reqId\",\n \"req\",\n \"res\",\n ];\n if (!message && \"data\" in obj && \"tags\" in obj) {\n // hapi-pino uses data and tags instead of the message key\n message = obj.data;\n ignoreKeys.push(\"data\");\n ignoreKeys.push(\"tags\");\n }\n const rest = removeKeys(obj, ignoreKeys);\n const formattedMessage = formatMessage(message, rest);\n if (formattedMessage) {\n logs.push({\n timestamp: this.convertTime(obj.time),\n level: logLevelMap[obj.level] || \"info\",\n message: formattedMessage,\n });\n }\n } catch (e) {\n // ignore\n }\n }\n\n private convertTime(time: any): number {\n if (typeof time === \"number\" && !isNaN(time)) {\n return time / 1000; // Convert milliseconds to seconds\n }\n return Date.now() / 1000; // Fallback to current time\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;;;;AAAA,mBAA0C;AAA1C;AAEA,MAAMA,kBAAkB;AAExB,MAAMC,oBAAoBC,OAAOC,IAAI,yBAAA;AACrC,MAAMC,cAAsC;EAC1C,IAAI;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;AACN;AAEA,eAAsBC,gBACpBC,QACAC,aAA2C;AAE3C,MAAI;AAEF,UAAMC,UAAU;SACXC,OAAOC,sBAAsBJ,MAAAA;SAC7BG,OAAOC,sBAAsBD,OAAOE,eAAeL,MAAAA,CAAAA;;AAExD,UAAMM,YAAYJ,QAAQK,KACxB,CAACC,QAAQA,IAAIC,SAAQ,MAAO,qBAAA;AAE9B,UAAMC,gBAAgBR,QAAQK,KAC5B,CAACC,QAAQA,IAAIC,SAAQ,MAAO,yBAAA;AAE9B,QAAI,CAACH,aAAa,CAACI,eAAe;AAEhC,aAAO;IACT;AAEA,QAAI,EAAEf,qBAAqBK,SAAS;AAClCA,aAAOL,iBAAAA,IAAqBK,OAAOM,SAAAA;IACrC;AAEA,UAAMK,iBAAiBX,OAAOL,iBAAAA;AAC9B,QAAIgB,gBAAgB;AAClB,YAAMC,OAAO,MAAM
|
|
1
|
+
{"version":3,"sources":["../../src/loggers/pino.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\n\nimport type { LogRecord } from \"../common/requestLogger.js\";\nimport { formatMessage, removeKeys } from \"./utils.js\";\n\nconst MAX_BUFFER_SIZE = 1000;\n\nconst originalStreamSym = Symbol.for(\"apitally.originalStream\");\nconst logLevelMap: Record<number, string> = {\n 10: \"trace\",\n 20: \"debug\",\n 30: \"info\",\n 40: \"warn\",\n 50: \"error\",\n 60: \"fatal\",\n};\n\nexport async function patchPinoLogger(\n logger: any,\n logsContext: AsyncLocalStorage<LogRecord[]>,\n) {\n try {\n // Find stream and message key symbols on the logger and its prototype\n const symbols = [\n ...Object.getOwnPropertySymbols(logger),\n ...Object.getOwnPropertySymbols(Object.getPrototypeOf(logger)),\n ];\n const streamSym = symbols.find(\n (sym) => sym.toString() === \"Symbol(pino.stream)\",\n );\n const messageKeySym = symbols.find(\n (sym) => sym.toString() === \"Symbol(pino.messageKey)\",\n );\n if (!streamSym || !messageKeySym) {\n // not a pino logger\n return false;\n }\n\n if (!(originalStreamSym in logger)) {\n logger[originalStreamSym] = logger[streamSym];\n }\n\n const originalStream = logger[originalStreamSym];\n if (originalStream) {\n const pino = await import(/* webpackIgnore: true */ \"pino\");\n const captureStream = new ApitallyLogCaptureStream(\n logsContext,\n logger[messageKeySym],\n );\n logger[streamSym] = pino.default.multistream(\n [\n { level: 0, stream: originalStream },\n { level: 0, stream: captureStream },\n ],\n {\n levels: logger.levels,\n },\n );\n }\n return true;\n } catch {\n // ignore errors\n return false;\n }\n}\n\nfunction filterLogs(obj: any, messageKey: string) {\n return obj[messageKey] !== \"request completed\";\n}\n\nclass ApitallyLogCaptureStream {\n private logsContext: AsyncLocalStorage<LogRecord[]>;\n private messageKey: string;\n\n constructor(logsContext: AsyncLocalStorage<LogRecord[]>, messageKey: string) {\n this.logsContext = logsContext;\n this.messageKey = messageKey;\n }\n\n write(msg: string): void {\n const logs = this.logsContext.getStore();\n if (!logs || !msg || logs.length >= MAX_BUFFER_SIZE) {\n return;\n }\n\n let obj: any;\n try {\n obj = JSON.parse(msg);\n } catch (e) {\n return;\n }\n if (\n obj === null ||\n typeof obj !== \"object\" ||\n !filterLogs(obj, this.messageKey)\n ) {\n return;\n }\n\n try {\n let message = obj[this.messageKey];\n const ignoreKeys = [\n \"hostname\",\n \"level\",\n this.messageKey,\n \"pid\",\n \"time\",\n \"reqId\",\n \"req\",\n \"res\",\n ];\n if (!message && \"data\" in obj && \"tags\" in obj) {\n // hapi-pino uses data and tags instead of the message key\n message = obj.data;\n ignoreKeys.push(\"data\");\n ignoreKeys.push(\"tags\");\n }\n const rest = removeKeys(obj, ignoreKeys);\n const formattedMessage = formatMessage(message, rest);\n if (formattedMessage) {\n logs.push({\n timestamp: this.convertTime(obj.time),\n level: logLevelMap[obj.level] || \"info\",\n message: formattedMessage,\n });\n }\n } catch (e) {\n // ignore\n }\n }\n\n private convertTime(time: any): number {\n if (typeof time === \"number\" && !isNaN(time)) {\n return time / 1000; // Convert milliseconds to seconds\n }\n return Date.now() / 1000; // Fallback to current time\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;;;;AAAA,mBAA0C;AAA1C;AAEA,MAAMA,kBAAkB;AAExB,MAAMC,oBAAoBC,OAAOC,IAAI,yBAAA;AACrC,MAAMC,cAAsC;EAC1C,IAAI;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;AACN;AAEA,eAAsBC,gBACpBC,QACAC,aAA2C;AAE3C,MAAI;AAEF,UAAMC,UAAU;SACXC,OAAOC,sBAAsBJ,MAAAA;SAC7BG,OAAOC,sBAAsBD,OAAOE,eAAeL,MAAAA,CAAAA;;AAExD,UAAMM,YAAYJ,QAAQK,KACxB,CAACC,QAAQA,IAAIC,SAAQ,MAAO,qBAAA;AAE9B,UAAMC,gBAAgBR,QAAQK,KAC5B,CAACC,QAAQA,IAAIC,SAAQ,MAAO,yBAAA;AAE9B,QAAI,CAACH,aAAa,CAACI,eAAe;AAEhC,aAAO;IACT;AAEA,QAAI,EAAEf,qBAAqBK,SAAS;AAClCA,aAAOL,iBAAAA,IAAqBK,OAAOM,SAAAA;IACrC;AAEA,UAAMK,iBAAiBX,OAAOL,iBAAAA;AAC9B,QAAIgB,gBAAgB;AAClB,YAAMC,OAAO,MAAM;;QAAiC;MAAA;AACpD,YAAMC,gBAAgB,IAAIC,yBACxBb,aACAD,OAAOU,aAAAA,CAAc;AAEvBV,aAAOM,SAAAA,IAAaM,KAAKG,QAAQC,YAC/B;QACE;UAAEC,OAAO;UAAGC,QAAQP;QAAe;QACnC;UAAEM,OAAO;UAAGC,QAAQL;QAAc;SAEpC;QACEM,QAAQnB,OAAOmB;MACjB,CAAA;IAEJ;AACA,WAAO;EACT,QAAQ;AAEN,WAAO;EACT;AACF;AA/CsBpB;AAiDtB,SAASqB,WAAWC,KAAUC,YAAkB;AAC9C,SAAOD,IAAIC,UAAAA,MAAgB;AAC7B;AAFSF;AAIT,IAAMN,4BAAN,WAAMA;EACIb;EACAqB;EAER,YAAYrB,aAA6CqB,YAAoB;AAC3E,SAAKrB,cAAcA;AACnB,SAAKqB,aAAaA;EACpB;EAEAC,MAAMC,KAAmB;AACvB,UAAMC,OAAO,KAAKxB,YAAYyB,SAAQ;AACtC,QAAI,CAACD,QAAQ,CAACD,OAAOC,KAAKE,UAAUjC,iBAAiB;AACnD;IACF;AAEA,QAAI2B;AACJ,QAAI;AACFA,YAAMO,KAAKC,MAAML,GAAAA;IACnB,SAASM,GAAG;AACV;IACF;AACA,QACET,QAAQ,QACR,OAAOA,QAAQ,YACf,CAACD,WAAWC,KAAK,KAAKC,UAAU,GAChC;AACA;IACF;AAEA,QAAI;AACF,UAAIS,UAAUV,IAAI,KAAKC,UAAU;AACjC,YAAMU,aAAa;QACjB;QACA;QACA,KAAKV;QACL;QACA;QACA;QACA;QACA;;AAEF,UAAI,CAACS,WAAW,UAAUV,OAAO,UAAUA,KAAK;AAE9CU,kBAAUV,IAAIY;AACdD,mBAAWE,KAAK,MAAA;AAChBF,mBAAWE,KAAK,MAAA;MAClB;AACA,YAAMC,WAAOC,yBAAWf,KAAKW,UAAAA;AAC7B,YAAMK,uBAAmBC,4BAAcP,SAASI,IAAAA;AAChD,UAAIE,kBAAkB;AACpBZ,aAAKS,KAAK;UACRK,WAAW,KAAKC,YAAYnB,IAAIoB,IAAI;UACpCxB,OAAOnB,YAAYuB,IAAIJ,KAAK,KAAK;UACjCc,SAASM;QACX,CAAA;MACF;IACF,SAASP,GAAG;IAEZ;EACF;EAEQU,YAAYC,MAAmB;AACrC,QAAI,OAAOA,SAAS,YAAY,CAACC,MAAMD,IAAAA,GAAO;AAC5C,aAAOA,OAAO;IAChB;AACA,WAAOE,KAAKC,IAAG,IAAK;EACtB;AACF,GAnEM9B,wCAAN;","names":["MAX_BUFFER_SIZE","originalStreamSym","Symbol","for","logLevelMap","patchPinoLogger","logger","logsContext","symbols","Object","getOwnPropertySymbols","getPrototypeOf","streamSym","find","sym","toString","messageKeySym","originalStream","pino","captureStream","ApitallyLogCaptureStream","default","multistream","level","stream","levels","filterLogs","obj","messageKey","write","msg","logs","getStore","length","JSON","parse","e","message","ignoreKeys","data","push","rest","removeKeys","formattedMessage","formatMessage","timestamp","convertTime","time","isNaN","Date","now"]}
|
package/dist/loggers/pino.js
CHANGED
|
@@ -28,7 +28,10 @@ async function patchPinoLogger(logger, logsContext) {
|
|
|
28
28
|
}
|
|
29
29
|
const originalStream = logger[originalStreamSym];
|
|
30
30
|
if (originalStream) {
|
|
31
|
-
const pino = await import(
|
|
31
|
+
const pino = await import(
|
|
32
|
+
/* webpackIgnore: true */
|
|
33
|
+
"pino"
|
|
34
|
+
);
|
|
32
35
|
const captureStream = new ApitallyLogCaptureStream(logsContext, logger[messageKeySym]);
|
|
33
36
|
logger[streamSym] = pino.default.multistream([
|
|
34
37
|
{
|
package/dist/loggers/pino.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/loggers/pino.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\n\nimport type { LogRecord } from \"../common/requestLogger.js\";\nimport { formatMessage, removeKeys } from \"./utils.js\";\n\nconst MAX_BUFFER_SIZE = 1000;\n\nconst originalStreamSym = Symbol.for(\"apitally.originalStream\");\nconst logLevelMap: Record<number, string> = {\n 10: \"trace\",\n 20: \"debug\",\n 30: \"info\",\n 40: \"warn\",\n 50: \"error\",\n 60: \"fatal\",\n};\n\nexport async function patchPinoLogger(\n logger: any,\n logsContext: AsyncLocalStorage<LogRecord[]>,\n) {\n try {\n // Find stream and message key symbols on the logger and its prototype\n const symbols = [\n ...Object.getOwnPropertySymbols(logger),\n ...Object.getOwnPropertySymbols(Object.getPrototypeOf(logger)),\n ];\n const streamSym = symbols.find(\n (sym) => sym.toString() === \"Symbol(pino.stream)\",\n );\n const messageKeySym = symbols.find(\n (sym) => sym.toString() === \"Symbol(pino.messageKey)\",\n );\n if (!streamSym || !messageKeySym) {\n // not a pino logger\n return false;\n }\n\n if (!(originalStreamSym in logger)) {\n logger[originalStreamSym] = logger[streamSym];\n }\n\n const originalStream = logger[originalStreamSym];\n if (originalStream) {\n const pino = await import(\"pino\");\n const captureStream = new ApitallyLogCaptureStream(\n logsContext,\n logger[messageKeySym],\n );\n logger[streamSym] = pino.default.multistream(\n [\n { level: 0, stream: originalStream },\n { level: 0, stream: captureStream },\n ],\n {\n levels: logger.levels,\n },\n );\n }\n return true;\n } catch {\n // ignore errors\n return false;\n }\n}\n\nfunction filterLogs(obj: any, messageKey: string) {\n return obj[messageKey] !== \"request completed\";\n}\n\nclass ApitallyLogCaptureStream {\n private logsContext: AsyncLocalStorage<LogRecord[]>;\n private messageKey: string;\n\n constructor(logsContext: AsyncLocalStorage<LogRecord[]>, messageKey: string) {\n this.logsContext = logsContext;\n this.messageKey = messageKey;\n }\n\n write(msg: string): void {\n const logs = this.logsContext.getStore();\n if (!logs || !msg || logs.length >= MAX_BUFFER_SIZE) {\n return;\n }\n\n let obj: any;\n try {\n obj = JSON.parse(msg);\n } catch (e) {\n return;\n }\n if (\n obj === null ||\n typeof obj !== \"object\" ||\n !filterLogs(obj, this.messageKey)\n ) {\n return;\n }\n\n try {\n let message = obj[this.messageKey];\n const ignoreKeys = [\n \"hostname\",\n \"level\",\n this.messageKey,\n \"pid\",\n \"time\",\n \"reqId\",\n \"req\",\n \"res\",\n ];\n if (!message && \"data\" in obj && \"tags\" in obj) {\n // hapi-pino uses data and tags instead of the message key\n message = obj.data;\n ignoreKeys.push(\"data\");\n ignoreKeys.push(\"tags\");\n }\n const rest = removeKeys(obj, ignoreKeys);\n const formattedMessage = formatMessage(message, rest);\n if (formattedMessage) {\n logs.push({\n timestamp: this.convertTime(obj.time),\n level: logLevelMap[obj.level] || \"info\",\n message: formattedMessage,\n });\n }\n } catch (e) {\n // ignore\n }\n }\n\n private convertTime(time: any): number {\n if (typeof time === \"number\" && !isNaN(time)) {\n return time / 1000; // Convert milliseconds to seconds\n }\n return Date.now() / 1000; // Fallback to current time\n }\n}\n"],"mappings":";;AAGA;SAASA,eAAeC,kBAAkB;AAE1C,MAAMC,kBAAkB;AAExB,MAAMC,oBAAoBC,OAAOC,IAAI,yBAAA;AACrC,MAAMC,cAAsC;EAC1C,IAAI;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;AACN;AAEA,eAAsBC,gBACpBC,QACAC,aAA2C;AAE3C,MAAI;AAEF,UAAMC,UAAU;SACXC,OAAOC,sBAAsBJ,MAAAA;SAC7BG,OAAOC,sBAAsBD,OAAOE,eAAeL,MAAAA,CAAAA;;AAExD,UAAMM,YAAYJ,QAAQK,KACxB,CAACC,QAAQA,IAAIC,SAAQ,MAAO,qBAAA;AAE9B,UAAMC,gBAAgBR,QAAQK,KAC5B,CAACC,QAAQA,IAAIC,SAAQ,MAAO,yBAAA;AAE9B,QAAI,CAACH,aAAa,CAACI,eAAe;AAEhC,aAAO;IACT;AAEA,QAAI,EAAEf,qBAAqBK,SAAS;AAClCA,aAAOL,iBAAAA,IAAqBK,OAAOM,SAAAA;IACrC;AAEA,UAAMK,iBAAiBX,OAAOL,iBAAAA;AAC9B,QAAIgB,gBAAgB;AAClB,YAAMC,OAAO,MAAM
|
|
1
|
+
{"version":3,"sources":["../../src/loggers/pino.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\n\nimport type { LogRecord } from \"../common/requestLogger.js\";\nimport { formatMessage, removeKeys } from \"./utils.js\";\n\nconst MAX_BUFFER_SIZE = 1000;\n\nconst originalStreamSym = Symbol.for(\"apitally.originalStream\");\nconst logLevelMap: Record<number, string> = {\n 10: \"trace\",\n 20: \"debug\",\n 30: \"info\",\n 40: \"warn\",\n 50: \"error\",\n 60: \"fatal\",\n};\n\nexport async function patchPinoLogger(\n logger: any,\n logsContext: AsyncLocalStorage<LogRecord[]>,\n) {\n try {\n // Find stream and message key symbols on the logger and its prototype\n const symbols = [\n ...Object.getOwnPropertySymbols(logger),\n ...Object.getOwnPropertySymbols(Object.getPrototypeOf(logger)),\n ];\n const streamSym = symbols.find(\n (sym) => sym.toString() === \"Symbol(pino.stream)\",\n );\n const messageKeySym = symbols.find(\n (sym) => sym.toString() === \"Symbol(pino.messageKey)\",\n );\n if (!streamSym || !messageKeySym) {\n // not a pino logger\n return false;\n }\n\n if (!(originalStreamSym in logger)) {\n logger[originalStreamSym] = logger[streamSym];\n }\n\n const originalStream = logger[originalStreamSym];\n if (originalStream) {\n const pino = await import(/* webpackIgnore: true */ \"pino\");\n const captureStream = new ApitallyLogCaptureStream(\n logsContext,\n logger[messageKeySym],\n );\n logger[streamSym] = pino.default.multistream(\n [\n { level: 0, stream: originalStream },\n { level: 0, stream: captureStream },\n ],\n {\n levels: logger.levels,\n },\n );\n }\n return true;\n } catch {\n // ignore errors\n return false;\n }\n}\n\nfunction filterLogs(obj: any, messageKey: string) {\n return obj[messageKey] !== \"request completed\";\n}\n\nclass ApitallyLogCaptureStream {\n private logsContext: AsyncLocalStorage<LogRecord[]>;\n private messageKey: string;\n\n constructor(logsContext: AsyncLocalStorage<LogRecord[]>, messageKey: string) {\n this.logsContext = logsContext;\n this.messageKey = messageKey;\n }\n\n write(msg: string): void {\n const logs = this.logsContext.getStore();\n if (!logs || !msg || logs.length >= MAX_BUFFER_SIZE) {\n return;\n }\n\n let obj: any;\n try {\n obj = JSON.parse(msg);\n } catch (e) {\n return;\n }\n if (\n obj === null ||\n typeof obj !== \"object\" ||\n !filterLogs(obj, this.messageKey)\n ) {\n return;\n }\n\n try {\n let message = obj[this.messageKey];\n const ignoreKeys = [\n \"hostname\",\n \"level\",\n this.messageKey,\n \"pid\",\n \"time\",\n \"reqId\",\n \"req\",\n \"res\",\n ];\n if (!message && \"data\" in obj && \"tags\" in obj) {\n // hapi-pino uses data and tags instead of the message key\n message = obj.data;\n ignoreKeys.push(\"data\");\n ignoreKeys.push(\"tags\");\n }\n const rest = removeKeys(obj, ignoreKeys);\n const formattedMessage = formatMessage(message, rest);\n if (formattedMessage) {\n logs.push({\n timestamp: this.convertTime(obj.time),\n level: logLevelMap[obj.level] || \"info\",\n message: formattedMessage,\n });\n }\n } catch (e) {\n // ignore\n }\n }\n\n private convertTime(time: any): number {\n if (typeof time === \"number\" && !isNaN(time)) {\n return time / 1000; // Convert milliseconds to seconds\n }\n return Date.now() / 1000; // Fallback to current time\n }\n}\n"],"mappings":";;AAGA;SAASA,eAAeC,kBAAkB;AAE1C,MAAMC,kBAAkB;AAExB,MAAMC,oBAAoBC,OAAOC,IAAI,yBAAA;AACrC,MAAMC,cAAsC;EAC1C,IAAI;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI;AACN;AAEA,eAAsBC,gBACpBC,QACAC,aAA2C;AAE3C,MAAI;AAEF,UAAMC,UAAU;SACXC,OAAOC,sBAAsBJ,MAAAA;SAC7BG,OAAOC,sBAAsBD,OAAOE,eAAeL,MAAAA,CAAAA;;AAExD,UAAMM,YAAYJ,QAAQK,KACxB,CAACC,QAAQA,IAAIC,SAAQ,MAAO,qBAAA;AAE9B,UAAMC,gBAAgBR,QAAQK,KAC5B,CAACC,QAAQA,IAAIC,SAAQ,MAAO,yBAAA;AAE9B,QAAI,CAACH,aAAa,CAACI,eAAe;AAEhC,aAAO;IACT;AAEA,QAAI,EAAEf,qBAAqBK,SAAS;AAClCA,aAAOL,iBAAAA,IAAqBK,OAAOM,SAAAA;IACrC;AAEA,UAAMK,iBAAiBX,OAAOL,iBAAAA;AAC9B,QAAIgB,gBAAgB;AAClB,YAAMC,OAAO,MAAM;;QAAiC;MAAA;AACpD,YAAMC,gBAAgB,IAAIC,yBACxBb,aACAD,OAAOU,aAAAA,CAAc;AAEvBV,aAAOM,SAAAA,IAAaM,KAAKG,QAAQC,YAC/B;QACE;UAAEC,OAAO;UAAGC,QAAQP;QAAe;QACnC;UAAEM,OAAO;UAAGC,QAAQL;QAAc;SAEpC;QACEM,QAAQnB,OAAOmB;MACjB,CAAA;IAEJ;AACA,WAAO;EACT,QAAQ;AAEN,WAAO;EACT;AACF;AA/CsBpB;AAiDtB,SAASqB,WAAWC,KAAUC,YAAkB;AAC9C,SAAOD,IAAIC,UAAAA,MAAgB;AAC7B;AAFSF;AAIT,IAAMN,4BAAN,WAAMA;EACIb;EACAqB;EAER,YAAYrB,aAA6CqB,YAAoB;AAC3E,SAAKrB,cAAcA;AACnB,SAAKqB,aAAaA;EACpB;EAEAC,MAAMC,KAAmB;AACvB,UAAMC,OAAO,KAAKxB,YAAYyB,SAAQ;AACtC,QAAI,CAACD,QAAQ,CAACD,OAAOC,KAAKE,UAAUjC,iBAAiB;AACnD;IACF;AAEA,QAAI2B;AACJ,QAAI;AACFA,YAAMO,KAAKC,MAAML,GAAAA;IACnB,SAASM,GAAG;AACV;IACF;AACA,QACET,QAAQ,QACR,OAAOA,QAAQ,YACf,CAACD,WAAWC,KAAK,KAAKC,UAAU,GAChC;AACA;IACF;AAEA,QAAI;AACF,UAAIS,UAAUV,IAAI,KAAKC,UAAU;AACjC,YAAMU,aAAa;QACjB;QACA;QACA,KAAKV;QACL;QACA;QACA;QACA;QACA;;AAEF,UAAI,CAACS,WAAW,UAAUV,OAAO,UAAUA,KAAK;AAE9CU,kBAAUV,IAAIY;AACdD,mBAAWE,KAAK,MAAA;AAChBF,mBAAWE,KAAK,MAAA;MAClB;AACA,YAAMC,OAAO1C,WAAW4B,KAAKW,UAAAA;AAC7B,YAAMI,mBAAmB5C,cAAcuC,SAASI,IAAAA;AAChD,UAAIC,kBAAkB;AACpBX,aAAKS,KAAK;UACRG,WAAW,KAAKC,YAAYjB,IAAIkB,IAAI;UACpCtB,OAAOnB,YAAYuB,IAAIJ,KAAK,KAAK;UACjCc,SAASK;QACX,CAAA;MACF;IACF,SAASN,GAAG;IAEZ;EACF;EAEQQ,YAAYC,MAAmB;AACrC,QAAI,OAAOA,SAAS,YAAY,CAACC,MAAMD,IAAAA,GAAO;AAC5C,aAAOA,OAAO;IAChB;AACA,WAAOE,KAAKC,IAAG,IAAK;EACtB;AACF,GAnEM5B,wCAAN;","names":["formatMessage","removeKeys","MAX_BUFFER_SIZE","originalStreamSym","Symbol","for","logLevelMap","patchPinoLogger","logger","logsContext","symbols","Object","getOwnPropertySymbols","getPrototypeOf","streamSym","find","sym","toString","messageKeySym","originalStream","pino","captureStream","ApitallyLogCaptureStream","default","multistream","level","stream","levels","filterLogs","obj","messageKey","write","msg","logs","getStore","length","JSON","parse","e","message","ignoreKeys","data","push","rest","formattedMessage","timestamp","convertTime","time","isNaN","Date","now"]}
|
package/dist/loggers/winston.cjs
CHANGED
|
@@ -43,7 +43,11 @@ async function patchWinston(logsContext) {
|
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
45
|
try {
|
|
46
|
-
const loggerModule = await import(
|
|
46
|
+
const loggerModule = await import(
|
|
47
|
+
// @ts-expect-error - file is not typed
|
|
48
|
+
/* webpackIgnore: true */
|
|
49
|
+
"winston/lib/winston/logger.js"
|
|
50
|
+
);
|
|
47
51
|
if ((_b = (_a = loggerModule.default) == null ? void 0 : _a.prototype) == null ? void 0 : _b.write) {
|
|
48
52
|
const originalWrite = loggerModule.default.prototype.write;
|
|
49
53
|
loggerModule.default.prototype.write = function(info) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/loggers/winston.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\n\nimport type { LogRecord } from \"../common/requestLogger.js\";\nimport { formatMessage, removeKeys } from \"./utils.js\";\n\nconst MAX_BUFFER_SIZE = 1000;\n\nlet isPatched = false;\nlet globalLogsContext: AsyncLocalStorage<LogRecord[]>;\n\nexport async function patchWinston(\n logsContext: AsyncLocalStorage<LogRecord[]>,\n) {\n globalLogsContext = logsContext;\n\n if (isPatched) {\n return;\n }\n\n try {\n // @ts-expect-error - file is not typed\n
|
|
1
|
+
{"version":3,"sources":["../../src/loggers/winston.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\n\nimport type { LogRecord } from \"../common/requestLogger.js\";\nimport { formatMessage, removeKeys } from \"./utils.js\";\n\nconst MAX_BUFFER_SIZE = 1000;\n\nlet isPatched = false;\nlet globalLogsContext: AsyncLocalStorage<LogRecord[]>;\n\nexport async function patchWinston(\n logsContext: AsyncLocalStorage<LogRecord[]>,\n) {\n globalLogsContext = logsContext;\n\n if (isPatched) {\n return;\n }\n\n try {\n const loggerModule = await import(\n // @ts-expect-error - file is not typed\n /* webpackIgnore: true */ \"winston/lib/winston/logger.js\"\n );\n if (loggerModule.default?.prototype?.write) {\n const originalWrite = loggerModule.default.prototype.write;\n loggerModule.default.prototype.write = function (info: any) {\n captureLog(info);\n return originalWrite.call(this, info);\n };\n }\n } catch {\n // winston is not installed, silently ignore\n }\n\n isPatched = true;\n}\n\nfunction captureLog(info: any) {\n const logs = globalLogsContext?.getStore();\n if (!logs || !info || logs.length >= MAX_BUFFER_SIZE) {\n return;\n }\n\n try {\n const rest = removeKeys(info, [\"timestamp\", \"level\", \"message\", \"splat\"]);\n const formattedMessage = formatMessage(info.message, rest);\n if (formattedMessage) {\n logs.push({\n timestamp: parseTimestamp(info.timestamp),\n level: info.level || \"info\",\n message: formattedMessage.trim(),\n });\n }\n } catch (e) {\n // ignore\n }\n}\n\nfunction parseTimestamp(timestamp: any) {\n if (timestamp) {\n const ts = new Date(timestamp).getTime();\n if (!isNaN(ts)) {\n return ts / 1000;\n }\n }\n return Date.now() / 1000;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;;;;AAAA,mBAA0C;AAE1C,MAAMA,kBAAkB;AAExB,IAAIC,YAAY;AAChB,IAAIC;AAEJ,eAAsBC,aACpBC,aAA2C;AAR7C;AAUEF,sBAAoBE;AAEpB,MAAIH,WAAW;AACb;EACF;AAEA,MAAI;AACF,UAAMI,eAAe,MAAM;;;MAEC;IAAA;AAE5B,SAAIA,wBAAaC,YAAbD,mBAAsBE,cAAtBF,mBAAiCG,OAAO;AAC1C,YAAMC,gBAAgBJ,aAAaC,QAAQC,UAAUC;AACrDH,mBAAaC,QAAQC,UAAUC,QAAQ,SAAUE,MAAS;AACxDC,mBAAWD,IAAAA;AACX,eAAOD,cAAcG,KAAK,MAAMF,IAAAA;MAClC;IACF;EACF,QAAQ;EAER;AAEAT,cAAY;AACd;AA1BsBE;AA4BtB,SAASQ,WAAWD,MAAS;AAC3B,QAAMG,OAAOX,uDAAmBY;AAChC,MAAI,CAACD,QAAQ,CAACH,QAAQG,KAAKE,UAAUf,iBAAiB;AACpD;EACF;AAEA,MAAI;AACF,UAAMgB,WAAOC,yBAAWP,MAAM;MAAC;MAAa;MAAS;MAAW;KAAQ;AACxE,UAAMQ,uBAAmBC,4BAAcT,KAAKU,SAASJ,IAAAA;AACrD,QAAIE,kBAAkB;AACpBL,WAAKQ,KAAK;QACRC,WAAWC,eAAeb,KAAKY,SAAS;QACxCE,OAAOd,KAAKc,SAAS;QACrBJ,SAASF,iBAAiBO,KAAI;MAChC,CAAA;IACF;EACF,SAASC,GAAG;EAEZ;AACF;AAnBSf;AAqBT,SAASY,eAAeD,WAAc;AACpC,MAAIA,WAAW;AACb,UAAMK,KAAK,IAAIC,KAAKN,SAAAA,EAAWO,QAAO;AACtC,QAAI,CAACC,MAAMH,EAAAA,GAAK;AACd,aAAOA,KAAK;IACd;EACF;AACA,SAAOC,KAAKG,IAAG,IAAK;AACtB;AARSR;","names":["MAX_BUFFER_SIZE","isPatched","globalLogsContext","patchWinston","logsContext","loggerModule","default","prototype","write","originalWrite","info","captureLog","call","logs","getStore","length","rest","removeKeys","formattedMessage","formatMessage","message","push","timestamp","parseTimestamp","level","trim","e","ts","Date","getTime","isNaN","now"]}
|
package/dist/loggers/winston.js
CHANGED
|
@@ -11,7 +11,11 @@ async function patchWinston(logsContext) {
|
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
13
|
try {
|
|
14
|
-
const loggerModule = await import(
|
|
14
|
+
const loggerModule = await import(
|
|
15
|
+
// @ts-expect-error - file is not typed
|
|
16
|
+
/* webpackIgnore: true */
|
|
17
|
+
"winston/lib/winston/logger.js"
|
|
18
|
+
);
|
|
15
19
|
if ((_b = (_a = loggerModule.default) == null ? void 0 : _a.prototype) == null ? void 0 : _b.write) {
|
|
16
20
|
const originalWrite = loggerModule.default.prototype.write;
|
|
17
21
|
loggerModule.default.prototype.write = function(info) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/loggers/winston.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\n\nimport type { LogRecord } from \"../common/requestLogger.js\";\nimport { formatMessage, removeKeys } from \"./utils.js\";\n\nconst MAX_BUFFER_SIZE = 1000;\n\nlet isPatched = false;\nlet globalLogsContext: AsyncLocalStorage<LogRecord[]>;\n\nexport async function patchWinston(\n logsContext: AsyncLocalStorage<LogRecord[]>,\n) {\n globalLogsContext = logsContext;\n\n if (isPatched) {\n return;\n }\n\n try {\n // @ts-expect-error - file is not typed\n
|
|
1
|
+
{"version":3,"sources":["../../src/loggers/winston.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\n\nimport type { LogRecord } from \"../common/requestLogger.js\";\nimport { formatMessage, removeKeys } from \"./utils.js\";\n\nconst MAX_BUFFER_SIZE = 1000;\n\nlet isPatched = false;\nlet globalLogsContext: AsyncLocalStorage<LogRecord[]>;\n\nexport async function patchWinston(\n logsContext: AsyncLocalStorage<LogRecord[]>,\n) {\n globalLogsContext = logsContext;\n\n if (isPatched) {\n return;\n }\n\n try {\n const loggerModule = await import(\n // @ts-expect-error - file is not typed\n /* webpackIgnore: true */ \"winston/lib/winston/logger.js\"\n );\n if (loggerModule.default?.prototype?.write) {\n const originalWrite = loggerModule.default.prototype.write;\n loggerModule.default.prototype.write = function (info: any) {\n captureLog(info);\n return originalWrite.call(this, info);\n };\n }\n } catch {\n // winston is not installed, silently ignore\n }\n\n isPatched = true;\n}\n\nfunction captureLog(info: any) {\n const logs = globalLogsContext?.getStore();\n if (!logs || !info || logs.length >= MAX_BUFFER_SIZE) {\n return;\n }\n\n try {\n const rest = removeKeys(info, [\"timestamp\", \"level\", \"message\", \"splat\"]);\n const formattedMessage = formatMessage(info.message, rest);\n if (formattedMessage) {\n logs.push({\n timestamp: parseTimestamp(info.timestamp),\n level: info.level || \"info\",\n message: formattedMessage.trim(),\n });\n }\n } catch (e) {\n // ignore\n }\n}\n\nfunction parseTimestamp(timestamp: any) {\n if (timestamp) {\n const ts = new Date(timestamp).getTime();\n if (!isNaN(ts)) {\n return ts / 1000;\n }\n }\n return Date.now() / 1000;\n}\n"],"mappings":";;AAGA,SAASA,eAAeC,kBAAkB;AAE1C,MAAMC,kBAAkB;AAExB,IAAIC,YAAY;AAChB,IAAIC;AAEJ,eAAsBC,aACpBC,aAA2C;AAR7C;AAUEF,sBAAoBE;AAEpB,MAAIH,WAAW;AACb;EACF;AAEA,MAAI;AACF,UAAMI,eAAe,MAAM;;;MAEC;IAAA;AAE5B,SAAIA,wBAAaC,YAAbD,mBAAsBE,cAAtBF,mBAAiCG,OAAO;AAC1C,YAAMC,gBAAgBJ,aAAaC,QAAQC,UAAUC;AACrDH,mBAAaC,QAAQC,UAAUC,QAAQ,SAAUE,MAAS;AACxDC,mBAAWD,IAAAA;AACX,eAAOD,cAAcG,KAAK,MAAMF,IAAAA;MAClC;IACF;EACF,QAAQ;EAER;AAEAT,cAAY;AACd;AA1BsBE;AA4BtB,SAASQ,WAAWD,MAAS;AAC3B,QAAMG,OAAOX,uDAAmBY;AAChC,MAAI,CAACD,QAAQ,CAACH,QAAQG,KAAKE,UAAUf,iBAAiB;AACpD;EACF;AAEA,MAAI;AACF,UAAMgB,OAAOjB,WAAWW,MAAM;MAAC;MAAa;MAAS;MAAW;KAAQ;AACxE,UAAMO,mBAAmBnB,cAAcY,KAAKQ,SAASF,IAAAA;AACrD,QAAIC,kBAAkB;AACpBJ,WAAKM,KAAK;QACRC,WAAWC,eAAeX,KAAKU,SAAS;QACxCE,OAAOZ,KAAKY,SAAS;QACrBJ,SAASD,iBAAiBM,KAAI;MAChC,CAAA;IACF;EACF,SAASC,GAAG;EAEZ;AACF;AAnBSb;AAqBT,SAASU,eAAeD,WAAc;AACpC,MAAIA,WAAW;AACb,UAAMK,KAAK,IAAIC,KAAKN,SAAAA,EAAWO,QAAO;AACtC,QAAI,CAACC,MAAMH,EAAAA,GAAK;AACd,aAAOA,KAAK;IACd;EACF;AACA,SAAOC,KAAKG,IAAG,IAAK;AACtB;AARSR;","names":["formatMessage","removeKeys","MAX_BUFFER_SIZE","isPatched","globalLogsContext","patchWinston","logsContext","loggerModule","default","prototype","write","originalWrite","info","captureLog","call","logs","getStore","length","rest","formattedMessage","message","push","timestamp","parseTimestamp","level","trim","e","ts","Date","getTime","isNaN","now"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apitally",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.1",
|
|
4
4
|
"description": "Simple API monitoring & analytics for REST APIs built with Express, Fastify, NestJS, AdonisJS, Hono, H3, Elysia, Hapi, and Koa.",
|
|
5
5
|
"author": "Apitally <hello@apitally.io>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -221,7 +221,8 @@
|
|
|
221
221
|
"fastify-plugin": "^4 || ^5",
|
|
222
222
|
"h3": "^2",
|
|
223
223
|
"hono": "^4",
|
|
224
|
-
"koa": "^2 || ^3"
|
|
224
|
+
"koa": "^2 || ^3",
|
|
225
|
+
"pino": "^8 || ^9 || ^10"
|
|
225
226
|
},
|
|
226
227
|
"peerDependenciesMeta": {
|
|
227
228
|
"@adonisjs/core": {
|
|
@@ -265,6 +266,9 @@
|
|
|
265
266
|
},
|
|
266
267
|
"koa": {
|
|
267
268
|
"optional": true
|
|
269
|
+
},
|
|
270
|
+
"pino": {
|
|
271
|
+
"optional": true
|
|
268
272
|
}
|
|
269
273
|
},
|
|
270
274
|
"devDependencies": {
|