@globalart/nestjs-logger 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +83 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -2
- package/dist/index.d.mts +10 -2
- package/dist/index.mjs +83 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.d.cts
CHANGED
|
@@ -363,12 +363,16 @@ interface LogEntry {
|
|
|
363
363
|
readonly context?: string;
|
|
364
364
|
readonly metadata?: Record<string, unknown>;
|
|
365
365
|
readonly trace?: string;
|
|
366
|
+
readonly traceId?: string;
|
|
367
|
+
readonly spanId?: string;
|
|
366
368
|
}
|
|
367
369
|
interface LogOptions {
|
|
368
|
-
message:
|
|
370
|
+
message: string;
|
|
369
371
|
context?: string;
|
|
370
|
-
metadata?:
|
|
372
|
+
metadata?: Record<string, unknown>;
|
|
371
373
|
trace?: string;
|
|
374
|
+
traceId?: string;
|
|
375
|
+
spanId?: string;
|
|
372
376
|
}
|
|
373
377
|
interface HttpRequest {
|
|
374
378
|
readonly id: string;
|
|
@@ -394,6 +398,8 @@ interface HttpRequestLogEntry {
|
|
|
394
398
|
readonly res: HttpResponse;
|
|
395
399
|
readonly responseTime: number;
|
|
396
400
|
readonly msg: string;
|
|
401
|
+
readonly traceId?: string;
|
|
402
|
+
readonly spanId?: string;
|
|
397
403
|
}
|
|
398
404
|
interface ExcludeOption {
|
|
399
405
|
method: RequestMethod;
|
|
@@ -485,6 +491,8 @@ declare class LoggerService implements LoggerService$1, ILogger {
|
|
|
485
491
|
verbose(options: LogOptions): void;
|
|
486
492
|
logHttpRequest(entry: HttpRequestLogEntry): void;
|
|
487
493
|
private writeLog;
|
|
494
|
+
private resolveTraceIds;
|
|
495
|
+
private enrichWithTraceIds;
|
|
488
496
|
}
|
|
489
497
|
//#endregion
|
|
490
498
|
//#region src/core/http-logger.interceptor.d.ts
|
package/dist/index.d.mts
CHANGED
|
@@ -363,12 +363,16 @@ interface LogEntry {
|
|
|
363
363
|
readonly context?: string;
|
|
364
364
|
readonly metadata?: Record<string, unknown>;
|
|
365
365
|
readonly trace?: string;
|
|
366
|
+
readonly traceId?: string;
|
|
367
|
+
readonly spanId?: string;
|
|
366
368
|
}
|
|
367
369
|
interface LogOptions {
|
|
368
|
-
message:
|
|
370
|
+
message: string;
|
|
369
371
|
context?: string;
|
|
370
|
-
metadata?:
|
|
372
|
+
metadata?: Record<string, unknown>;
|
|
371
373
|
trace?: string;
|
|
374
|
+
traceId?: string;
|
|
375
|
+
spanId?: string;
|
|
372
376
|
}
|
|
373
377
|
interface HttpRequest {
|
|
374
378
|
readonly id: string;
|
|
@@ -394,6 +398,8 @@ interface HttpRequestLogEntry {
|
|
|
394
398
|
readonly res: HttpResponse;
|
|
395
399
|
readonly responseTime: number;
|
|
396
400
|
readonly msg: string;
|
|
401
|
+
readonly traceId?: string;
|
|
402
|
+
readonly spanId?: string;
|
|
397
403
|
}
|
|
398
404
|
interface ExcludeOption {
|
|
399
405
|
method: RequestMethod;
|
|
@@ -485,6 +491,8 @@ declare class LoggerService implements LoggerService$1, ILogger {
|
|
|
485
491
|
verbose(options: LogOptions): void;
|
|
486
492
|
logHttpRequest(entry: HttpRequestLogEntry): void;
|
|
487
493
|
private writeLog;
|
|
494
|
+
private resolveTraceIds;
|
|
495
|
+
private enrichWithTraceIds;
|
|
488
496
|
}
|
|
489
497
|
//#endregion
|
|
490
498
|
//#region src/core/http-logger.interceptor.d.ts
|
package/dist/index.mjs
CHANGED
|
@@ -7262,6 +7262,30 @@ const DEFAULT_LOGGER_CONFIG = {
|
|
|
7262
7262
|
logRequests: false
|
|
7263
7263
|
};
|
|
7264
7264
|
|
|
7265
|
+
//#endregion
|
|
7266
|
+
//#region src/utils/opentelemetry-trace.ts
|
|
7267
|
+
let cachedGetter = void 0;
|
|
7268
|
+
function createGetter() {
|
|
7269
|
+
try {
|
|
7270
|
+
const api = __require("@opentelemetry/api");
|
|
7271
|
+
return () => {
|
|
7272
|
+
const span = api.trace?.getSpan?.(api.context?.active?.());
|
|
7273
|
+
if (!span) return {};
|
|
7274
|
+
const { spanId, traceId } = span.spanContext?.() ?? {};
|
|
7275
|
+
return spanId && traceId ? {
|
|
7276
|
+
spanId,
|
|
7277
|
+
traceId
|
|
7278
|
+
} : {};
|
|
7279
|
+
};
|
|
7280
|
+
} catch {
|
|
7281
|
+
return () => ({});
|
|
7282
|
+
}
|
|
7283
|
+
}
|
|
7284
|
+
function getOpenTelemetryTraceIds() {
|
|
7285
|
+
if (cachedGetter === void 0) cachedGetter = createGetter();
|
|
7286
|
+
return cachedGetter?.() ?? {};
|
|
7287
|
+
}
|
|
7288
|
+
|
|
7265
7289
|
//#endregion
|
|
7266
7290
|
//#region \0@oxc-project+runtime@0.112.0/helpers/decorateMetadata.js
|
|
7267
7291
|
function __decorateMetadata(k, v) {
|
|
@@ -7291,36 +7315,60 @@ let LoggerService = class LoggerService {
|
|
|
7291
7315
|
this.context = context;
|
|
7292
7316
|
}
|
|
7293
7317
|
log(options) {
|
|
7294
|
-
this.writeLog("info", options
|
|
7318
|
+
this.writeLog("info", options);
|
|
7295
7319
|
}
|
|
7296
7320
|
error(options) {
|
|
7297
|
-
this.writeLog("error", options
|
|
7321
|
+
this.writeLog("error", options);
|
|
7298
7322
|
}
|
|
7299
7323
|
warn(options) {
|
|
7300
|
-
this.writeLog("warn", options
|
|
7324
|
+
this.writeLog("warn", options);
|
|
7301
7325
|
}
|
|
7302
7326
|
debug(options) {
|
|
7303
|
-
this.writeLog("debug", options
|
|
7327
|
+
this.writeLog("debug", options);
|
|
7304
7328
|
}
|
|
7305
7329
|
verbose(options) {
|
|
7306
|
-
this.writeLog("verbose", options
|
|
7330
|
+
this.writeLog("verbose", options);
|
|
7307
7331
|
}
|
|
7308
7332
|
logHttpRequest(entry) {
|
|
7309
|
-
const
|
|
7333
|
+
const enriched = this.enrichWithTraceIds(entry);
|
|
7334
|
+
const formatted = this.formatter.formatHttpRequest(enriched);
|
|
7310
7335
|
this.writer.write(formatted);
|
|
7311
7336
|
}
|
|
7312
|
-
writeLog(level,
|
|
7337
|
+
writeLog(level, options) {
|
|
7338
|
+
const { traceId, spanId } = this.resolveTraceIds(options);
|
|
7313
7339
|
const entry = {
|
|
7314
7340
|
level,
|
|
7315
|
-
message,
|
|
7341
|
+
message: options.message,
|
|
7316
7342
|
timestamp: /* @__PURE__ */ new Date(),
|
|
7317
|
-
context: context ?? this.context ?? this.contextResolver.resolve(),
|
|
7318
|
-
metadata,
|
|
7319
|
-
trace
|
|
7343
|
+
context: options.context ?? this.context ?? this.contextResolver.resolve(),
|
|
7344
|
+
metadata: options.metadata,
|
|
7345
|
+
trace: options.trace,
|
|
7346
|
+
traceId,
|
|
7347
|
+
spanId
|
|
7320
7348
|
};
|
|
7321
7349
|
const formatted = this.formatter.format(entry);
|
|
7322
7350
|
this.writer.write(formatted);
|
|
7323
7351
|
}
|
|
7352
|
+
resolveTraceIds(options) {
|
|
7353
|
+
if (options.traceId && options.spanId) return {
|
|
7354
|
+
traceId: options.traceId,
|
|
7355
|
+
spanId: options.spanId
|
|
7356
|
+
};
|
|
7357
|
+
const otel = getOpenTelemetryTraceIds();
|
|
7358
|
+
return {
|
|
7359
|
+
traceId: options.traceId ?? otel.traceId,
|
|
7360
|
+
spanId: options.spanId ?? otel.spanId
|
|
7361
|
+
};
|
|
7362
|
+
}
|
|
7363
|
+
enrichWithTraceIds(entry) {
|
|
7364
|
+
if (entry.traceId && entry.spanId) return entry;
|
|
7365
|
+
const otel = getOpenTelemetryTraceIds();
|
|
7366
|
+
return {
|
|
7367
|
+
...entry,
|
|
7368
|
+
traceId: entry.traceId ?? otel.traceId,
|
|
7369
|
+
spanId: entry.spanId ?? otel.spanId
|
|
7370
|
+
};
|
|
7371
|
+
}
|
|
7324
7372
|
};
|
|
7325
7373
|
LoggerService = __decorate([Injectable(), __decorateMetadata("design:paramtypes", [
|
|
7326
7374
|
Object,
|
|
@@ -7649,8 +7697,15 @@ let TextFormatter = class TextFormatter extends BaseFormatter {
|
|
|
7649
7697
|
this.addContext(parts, entry);
|
|
7650
7698
|
this.addMessage(parts, entry);
|
|
7651
7699
|
this.addMetadata(parts, entry);
|
|
7700
|
+
this.addTraceIds(parts, entry);
|
|
7652
7701
|
return parts;
|
|
7653
7702
|
}
|
|
7703
|
+
addTraceIds(parts, entry) {
|
|
7704
|
+
if (entry.traceId || entry.spanId) {
|
|
7705
|
+
const ids = [entry.traceId, entry.spanId].filter(Boolean).join("/");
|
|
7706
|
+
parts.push(this.colorize(`[${ids}]`, "magenta"));
|
|
7707
|
+
}
|
|
7708
|
+
}
|
|
7654
7709
|
addTimestamp(parts, entry) {
|
|
7655
7710
|
if (this.options.timestamp) {
|
|
7656
7711
|
const timestamp = this.colorize(`[${this.formatTimestamp(entry.timestamp)}]`, "gray");
|
|
@@ -7710,6 +7765,8 @@ let JsonFormatter = class JsonFormatter extends BaseFormatter {
|
|
|
7710
7765
|
if (entry.context) result.context = entry.context;
|
|
7711
7766
|
if (entry.metadata) result.metadata = entry.metadata;
|
|
7712
7767
|
if (entry.trace) result.trace = entry.trace;
|
|
7768
|
+
if (entry.traceId) result.traceId = entry.traceId;
|
|
7769
|
+
if (entry.spanId) result.spanId = entry.spanId;
|
|
7713
7770
|
return result;
|
|
7714
7771
|
}
|
|
7715
7772
|
};
|
|
@@ -7719,10 +7776,23 @@ JsonFormatter = __decorate([Injectable()], JsonFormatter);
|
|
|
7719
7776
|
//#region src/formatters/pino-formatter.ts
|
|
7720
7777
|
let PinoFormatter = class PinoFormatter extends BaseFormatter {
|
|
7721
7778
|
format(entry) {
|
|
7722
|
-
|
|
7779
|
+
const obj = {
|
|
7780
|
+
level: entry.level,
|
|
7781
|
+
message: entry.message,
|
|
7782
|
+
timestamp: entry.timestamp,
|
|
7783
|
+
context: entry.context,
|
|
7784
|
+
metadata: entry.metadata,
|
|
7785
|
+
trace: entry.trace
|
|
7786
|
+
};
|
|
7787
|
+
if (entry.traceId) obj.traceId = entry.traceId;
|
|
7788
|
+
if (entry.spanId) obj.spanId = entry.spanId;
|
|
7789
|
+
return JSON.stringify(obj);
|
|
7723
7790
|
}
|
|
7724
7791
|
formatHttpRequest(entry) {
|
|
7725
|
-
const
|
|
7792
|
+
const obj = { ...entry };
|
|
7793
|
+
if (entry.traceId) obj.traceId = entry.traceId;
|
|
7794
|
+
if (entry.spanId) obj.spanId = entry.spanId;
|
|
7795
|
+
const jsonString = JSON.stringify(obj);
|
|
7726
7796
|
return this.options.colors ? this.colorize(jsonString, this.getColorForLevel(entry.level)) : jsonString;
|
|
7727
7797
|
}
|
|
7728
7798
|
};
|