plutin 1.6.0 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +115 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -2
- package/dist/index.d.ts +38 -2
- package/dist/index.mjs +113 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { Express } from 'express';
|
|
3
|
-
import { FastifyInstance } from 'fastify';
|
|
3
|
+
import { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';
|
|
4
|
+
import { Logger } from '@opentelemetry/api-logs';
|
|
5
|
+
import winston from 'winston';
|
|
4
6
|
|
|
5
7
|
type AnyObject = Record<string, any>;
|
|
6
8
|
type Request = {
|
|
@@ -329,6 +331,40 @@ declare class SentryNotifier implements IErrorNotifier {
|
|
|
329
331
|
notify(error: Error, context: ContextError): Promise<void>;
|
|
330
332
|
}
|
|
331
333
|
|
|
334
|
+
declare class WinstonOtelFastify {
|
|
335
|
+
private readonly env;
|
|
336
|
+
logger: Logger;
|
|
337
|
+
consoleLogger: winston.Logger;
|
|
338
|
+
level: 'info' | 'error' | 'debug' | 'fatal' | 'warn';
|
|
339
|
+
constructor(env: Record<string, any>);
|
|
340
|
+
private bodyIsFastifyRequest;
|
|
341
|
+
private bodyIsFastifyReply;
|
|
342
|
+
private buildMessage;
|
|
343
|
+
private logMessage;
|
|
344
|
+
info(body: string | {
|
|
345
|
+
req?: FastifyRequest;
|
|
346
|
+
res?: FastifyReply;
|
|
347
|
+
}): void;
|
|
348
|
+
error(body: string | {
|
|
349
|
+
req?: FastifyRequest;
|
|
350
|
+
res?: FastifyReply;
|
|
351
|
+
}): void;
|
|
352
|
+
debug(body: string | {
|
|
353
|
+
req?: FastifyRequest;
|
|
354
|
+
res?: FastifyReply;
|
|
355
|
+
}): void;
|
|
356
|
+
fatal(body: string | {
|
|
357
|
+
req?: FastifyRequest;
|
|
358
|
+
res?: FastifyReply;
|
|
359
|
+
}): void;
|
|
360
|
+
warn(body: string | {
|
|
361
|
+
req?: FastifyRequest;
|
|
362
|
+
res?: FastifyReply;
|
|
363
|
+
}): void;
|
|
364
|
+
trace(message: string): void;
|
|
365
|
+
child(): WinstonOtelFastify;
|
|
366
|
+
}
|
|
367
|
+
|
|
332
368
|
declare function Span(): MethodDecorator;
|
|
333
369
|
|
|
334
370
|
interface ITracerGateway {
|
|
@@ -348,4 +384,4 @@ declare const logger: {
|
|
|
348
384
|
error: (...args: any[]) => void;
|
|
349
385
|
};
|
|
350
386
|
|
|
351
|
-
export { AggregateObjectRoot, AggregateRoot, BaseController, CommonDTO, ContextError, Controller, CreateCommonDTO, DependencyContainer, DiscordNotifier, DtoResponsePagination, Entity, EntityObject, ExpressAdapter, FastifyAdapter, GlobalErrorHandler, IErrorNotifier, IHealthCheckDB, IHttp, ITracerGateway, Inject, MethodType, MiddlewareFunction, NotPagination, NotificationErrorInMemory, NotificationFactory, Optional, Pagination, Replace, Request, RequestHttp, Response, SentryNotifier, Span, TracerGatewayOpentelemetry, UniqueEntityId, UniqueObjectId, ValueObject, WatchedList, ZodSchema, baseEnvSchema, getTakeAndSkip, logger, zodValidator };
|
|
387
|
+
export { AggregateObjectRoot, AggregateRoot, BaseController, CommonDTO, ContextError, Controller, CreateCommonDTO, DependencyContainer, DiscordNotifier, DtoResponsePagination, Entity, EntityObject, ExpressAdapter, FastifyAdapter, GlobalErrorHandler, IErrorNotifier, IHealthCheckDB, IHttp, ITracerGateway, Inject, MethodType, MiddlewareFunction, NotPagination, NotificationErrorInMemory, NotificationFactory, Optional, Pagination, Replace, Request, RequestHttp, Response, SentryNotifier, Span, TracerGatewayOpentelemetry, UniqueEntityId, UniqueObjectId, ValueObject, WatchedList, WinstonOtelFastify, ZodSchema, baseEnvSchema, getTakeAndSkip, logger, zodValidator };
|
package/dist/index.mjs
CHANGED
|
@@ -1456,8 +1456,115 @@ function zodValidator(schema) {
|
|
|
1456
1456
|
}
|
|
1457
1457
|
__name(zodValidator, "zodValidator");
|
|
1458
1458
|
|
|
1459
|
+
// src/infra/adapters/logger/winston-otel-fastify.ts
|
|
1460
|
+
import opentelemetry from "@opentelemetry/api";
|
|
1461
|
+
import { logs, SeverityNumber } from "@opentelemetry/api-logs";
|
|
1462
|
+
import winston from "winston";
|
|
1463
|
+
var WinstonOtelFastify = class WinstonOtelFastify2 {
|
|
1464
|
+
static {
|
|
1465
|
+
__name(this, "WinstonOtelFastify");
|
|
1466
|
+
}
|
|
1467
|
+
env;
|
|
1468
|
+
logger;
|
|
1469
|
+
consoleLogger;
|
|
1470
|
+
level;
|
|
1471
|
+
constructor(env) {
|
|
1472
|
+
this.env = env;
|
|
1473
|
+
this.level = "info";
|
|
1474
|
+
if (env.OTEL_ENABLE) {
|
|
1475
|
+
this.logger = logs.getLogger(this.env.OTEL_SERVICE_NAME, this.env.OTEL_SERVICE_VERSION);
|
|
1476
|
+
this.level = this.env.LOG_LEVEL;
|
|
1477
|
+
const transports = this.env.NODE_ENV === "test" ? [
|
|
1478
|
+
new winston.transports.Console({
|
|
1479
|
+
silent: true
|
|
1480
|
+
})
|
|
1481
|
+
] : [
|
|
1482
|
+
new winston.transports.Console()
|
|
1483
|
+
];
|
|
1484
|
+
this.consoleLogger = winston.createLogger({
|
|
1485
|
+
level: this.level,
|
|
1486
|
+
format: winston.format.combine(winston.format.timestamp({
|
|
1487
|
+
format: "YYYY-MM-DD HH:mm:ss:ms"
|
|
1488
|
+
}), winston.format((info) => {
|
|
1489
|
+
if (this.env.NODE_ENV !== "test") {
|
|
1490
|
+
const span = opentelemetry.trace.getActiveSpan();
|
|
1491
|
+
if (span) {
|
|
1492
|
+
info.spanId = span.spanContext().spanId;
|
|
1493
|
+
info.traceId = span.spanContext().traceId;
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
return info;
|
|
1497
|
+
})(), winston.format.json()),
|
|
1498
|
+
transports
|
|
1499
|
+
});
|
|
1500
|
+
} else {
|
|
1501
|
+
this.consoleLogger = winston.createLogger({
|
|
1502
|
+
level: this.level,
|
|
1503
|
+
format: winston.format.combine(winston.format.timestamp({
|
|
1504
|
+
format: "YYYY-MM-DD HH:mm:ss:ms"
|
|
1505
|
+
}), winston.format.json())
|
|
1506
|
+
});
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
bodyIsFastifyRequest(body) {
|
|
1510
|
+
return body.method !== void 0;
|
|
1511
|
+
}
|
|
1512
|
+
bodyIsFastifyReply(body) {
|
|
1513
|
+
return body.statusCode !== void 0;
|
|
1514
|
+
}
|
|
1515
|
+
buildMessage(body) {
|
|
1516
|
+
if (typeof body === "object" && body.req && this.bodyIsFastifyRequest(body.req)) {
|
|
1517
|
+
return `${body.req.method} ${body.req.url}`;
|
|
1518
|
+
} else if (typeof body === "object" && body.res && this.bodyIsFastifyReply(body.res)) {
|
|
1519
|
+
return `${body.res.request.method} ${body.res.request.url} ${body.res.statusCode} - ${body.res.elapsedTime} ms`;
|
|
1520
|
+
} else if (typeof body === "string") {
|
|
1521
|
+
return body;
|
|
1522
|
+
} else {
|
|
1523
|
+
return "";
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
logMessage(body, severityNumber, severityText) {
|
|
1527
|
+
const message = this.buildMessage(body);
|
|
1528
|
+
this.consoleLogger[severityText.toLowerCase()](message);
|
|
1529
|
+
if (this.env.NODE_ENV !== "test") {
|
|
1530
|
+
this.logger.emit({
|
|
1531
|
+
body: message,
|
|
1532
|
+
severityNumber,
|
|
1533
|
+
severityText
|
|
1534
|
+
});
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
info(body) {
|
|
1538
|
+
this.logMessage(body, SeverityNumber.INFO, "INFO");
|
|
1539
|
+
}
|
|
1540
|
+
error(body) {
|
|
1541
|
+
this.logMessage(body, SeverityNumber.ERROR, "ERROR");
|
|
1542
|
+
}
|
|
1543
|
+
debug(body) {
|
|
1544
|
+
this.logMessage(body, SeverityNumber.DEBUG, "DEBUG");
|
|
1545
|
+
}
|
|
1546
|
+
fatal(body) {
|
|
1547
|
+
this.logMessage(body, SeverityNumber.FATAL, "FATAL");
|
|
1548
|
+
}
|
|
1549
|
+
warn(body) {
|
|
1550
|
+
this.logMessage(body, SeverityNumber.WARN, "WARN");
|
|
1551
|
+
}
|
|
1552
|
+
trace(message) {
|
|
1553
|
+
if (this.env.NODE_ENV !== "test") {
|
|
1554
|
+
this.logger.emit({
|
|
1555
|
+
body: message,
|
|
1556
|
+
severityNumber: SeverityNumber.TRACE,
|
|
1557
|
+
severityText: "TRACE"
|
|
1558
|
+
});
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
child() {
|
|
1562
|
+
return new WinstonOtelFastify2(process.env);
|
|
1563
|
+
}
|
|
1564
|
+
};
|
|
1565
|
+
|
|
1459
1566
|
// src/infra/adapters/observability/otel/span-decorator.ts
|
|
1460
|
-
import
|
|
1567
|
+
import opentelemetry2, { SpanStatusCode } from "@opentelemetry/api";
|
|
1461
1568
|
import "reflect-metadata";
|
|
1462
1569
|
function Span() {
|
|
1463
1570
|
return function(target, propertyKey, descriptor) {
|
|
@@ -1466,7 +1573,7 @@ function Span() {
|
|
|
1466
1573
|
}
|
|
1467
1574
|
const originalMethod = descriptor.value;
|
|
1468
1575
|
descriptor.value = function(...args) {
|
|
1469
|
-
const tracer =
|
|
1576
|
+
const tracer = opentelemetry2.trace.getTracer(process.env.OTEL_SERVICE_NAME, process.env.OTEL_SERVICE_VERSION);
|
|
1470
1577
|
const className = target.constructor?.name || "UnknownClass";
|
|
1471
1578
|
const methodName = String(propertyKey);
|
|
1472
1579
|
const spanName = `${className}.${methodName}`;
|
|
@@ -1514,7 +1621,7 @@ function handleSpanError(span, error) {
|
|
|
1514
1621
|
__name(handleSpanError, "handleSpanError");
|
|
1515
1622
|
|
|
1516
1623
|
// src/infra/adapters/observability/otel/tracer-gateway-opentelemetry.ts
|
|
1517
|
-
import
|
|
1624
|
+
import opentelemetry3 from "@opentelemetry/api";
|
|
1518
1625
|
var TracerGatewayOpentelemetry = class {
|
|
1519
1626
|
static {
|
|
1520
1627
|
__name(this, "TracerGatewayOpentelemetry");
|
|
@@ -1523,7 +1630,7 @@ var TracerGatewayOpentelemetry = class {
|
|
|
1523
1630
|
if (!process.env.OTEL_ENABLE) {
|
|
1524
1631
|
return;
|
|
1525
1632
|
}
|
|
1526
|
-
const span =
|
|
1633
|
+
const span = opentelemetry3.trace.getActiveSpan();
|
|
1527
1634
|
if (span && attributes) {
|
|
1528
1635
|
span.addEvent(name, attributes);
|
|
1529
1636
|
} else if (span) {
|
|
@@ -1534,7 +1641,7 @@ var TracerGatewayOpentelemetry = class {
|
|
|
1534
1641
|
if (!process.env.OTEL_ENABLE) {
|
|
1535
1642
|
return;
|
|
1536
1643
|
}
|
|
1537
|
-
const span =
|
|
1644
|
+
const span = opentelemetry3.trace.getActiveSpan();
|
|
1538
1645
|
if (span) {
|
|
1539
1646
|
span.setAttribute(key, value);
|
|
1540
1647
|
}
|
|
@@ -1602,6 +1709,7 @@ export {
|
|
|
1602
1709
|
UniqueObjectId,
|
|
1603
1710
|
ValueObject,
|
|
1604
1711
|
WatchedList,
|
|
1712
|
+
WinstonOtelFastify,
|
|
1605
1713
|
baseEnvSchema,
|
|
1606
1714
|
getTakeAndSkip,
|
|
1607
1715
|
logger,
|