plutin 1.6.0 → 1.6.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/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.cjs
CHANGED
|
@@ -463,6 +463,7 @@ __export(src_exports, {
|
|
|
463
463
|
UniqueObjectId: () => UniqueObjectId,
|
|
464
464
|
ValueObject: () => ValueObject,
|
|
465
465
|
WatchedList: () => WatchedList,
|
|
466
|
+
WinstonOtelFastify: () => WinstonOtelFastify,
|
|
466
467
|
baseEnvSchema: () => baseEnvSchema,
|
|
467
468
|
getTakeAndSkip: () => getTakeAndSkip,
|
|
468
469
|
logger: () => logger,
|
|
@@ -1506,8 +1507,115 @@ function zodValidator(schema) {
|
|
|
1506
1507
|
}
|
|
1507
1508
|
__name(zodValidator, "zodValidator");
|
|
1508
1509
|
|
|
1509
|
-
// src/infra/adapters/
|
|
1510
|
+
// src/infra/adapters/logger/winston-otel-fastify.ts
|
|
1510
1511
|
var import_api = __toESM(require("@opentelemetry/api"), 1);
|
|
1512
|
+
var import_api_logs = require("@opentelemetry/api-logs");
|
|
1513
|
+
var import_winston = __toESM(require("winston"), 1);
|
|
1514
|
+
var WinstonOtelFastify = class WinstonOtelFastify2 {
|
|
1515
|
+
static {
|
|
1516
|
+
__name(this, "WinstonOtelFastify");
|
|
1517
|
+
}
|
|
1518
|
+
env;
|
|
1519
|
+
logger;
|
|
1520
|
+
consoleLogger;
|
|
1521
|
+
level;
|
|
1522
|
+
constructor(env) {
|
|
1523
|
+
this.env = env;
|
|
1524
|
+
this.level = "info";
|
|
1525
|
+
if (env.OTEL_ENABLE) {
|
|
1526
|
+
this.logger = import_api_logs.logs.getLogger(this.env.OTEL_SERVICE_NAME, this.env.OTEL_SERVICE_VERSION);
|
|
1527
|
+
this.level = this.env.LOG_LEVEL;
|
|
1528
|
+
const transports = this.env.NODE_ENV === "test" ? [
|
|
1529
|
+
new import_winston.default.transports.Console({
|
|
1530
|
+
silent: true
|
|
1531
|
+
})
|
|
1532
|
+
] : [
|
|
1533
|
+
new import_winston.default.transports.Console()
|
|
1534
|
+
];
|
|
1535
|
+
this.consoleLogger = import_winston.default.createLogger({
|
|
1536
|
+
level: this.level,
|
|
1537
|
+
format: import_winston.default.format.combine(import_winston.default.format.timestamp({
|
|
1538
|
+
format: "YYYY-MM-DD HH:mm:ss:ms"
|
|
1539
|
+
}), import_winston.default.format((info) => {
|
|
1540
|
+
if (this.env.NODE_ENV !== "test") {
|
|
1541
|
+
const span = import_api.default.trace.getActiveSpan();
|
|
1542
|
+
if (span) {
|
|
1543
|
+
info.spanId = span.spanContext().spanId;
|
|
1544
|
+
info.traceId = span.spanContext().traceId;
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
return info;
|
|
1548
|
+
})(), import_winston.default.format.json()),
|
|
1549
|
+
transports
|
|
1550
|
+
});
|
|
1551
|
+
} else {
|
|
1552
|
+
this.consoleLogger = import_winston.default.createLogger({
|
|
1553
|
+
level: this.level,
|
|
1554
|
+
format: import_winston.default.format.combine(import_winston.default.format.timestamp({
|
|
1555
|
+
format: "YYYY-MM-DD HH:mm:ss:ms"
|
|
1556
|
+
}), import_winston.default.format.json())
|
|
1557
|
+
});
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
bodyIsFastifyRequest(body) {
|
|
1561
|
+
return body.method !== void 0;
|
|
1562
|
+
}
|
|
1563
|
+
bodyIsFastifyReply(body) {
|
|
1564
|
+
return body.statusCode !== void 0;
|
|
1565
|
+
}
|
|
1566
|
+
buildMessage(body) {
|
|
1567
|
+
if (typeof body === "object" && body.req && this.bodyIsFastifyRequest(body.req)) {
|
|
1568
|
+
return `${body.req.method} ${body.req.url}`;
|
|
1569
|
+
} else if (typeof body === "object" && body.res && this.bodyIsFastifyReply(body.res)) {
|
|
1570
|
+
return `${body.res.request.method} ${body.res.request.url} ${body.res.statusCode} - ${body.res.elapsedTime} ms`;
|
|
1571
|
+
} else if (typeof body === "string") {
|
|
1572
|
+
return body;
|
|
1573
|
+
} else {
|
|
1574
|
+
return "";
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
logMessage(body, severityNumber, severityText) {
|
|
1578
|
+
const message = this.buildMessage(body);
|
|
1579
|
+
this.consoleLogger[severityText.toLowerCase()](message);
|
|
1580
|
+
if (this.env.NODE_ENV !== "test") {
|
|
1581
|
+
this.logger.emit({
|
|
1582
|
+
body: message,
|
|
1583
|
+
severityNumber,
|
|
1584
|
+
severityText
|
|
1585
|
+
});
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
info(body) {
|
|
1589
|
+
this.logMessage(body, import_api_logs.SeverityNumber.INFO, "INFO");
|
|
1590
|
+
}
|
|
1591
|
+
error(body) {
|
|
1592
|
+
this.logMessage(body, import_api_logs.SeverityNumber.ERROR, "ERROR");
|
|
1593
|
+
}
|
|
1594
|
+
debug(body) {
|
|
1595
|
+
this.logMessage(body, import_api_logs.SeverityNumber.DEBUG, "DEBUG");
|
|
1596
|
+
}
|
|
1597
|
+
fatal(body) {
|
|
1598
|
+
this.logMessage(body, import_api_logs.SeverityNumber.FATAL, "FATAL");
|
|
1599
|
+
}
|
|
1600
|
+
warn(body) {
|
|
1601
|
+
this.logMessage(body, import_api_logs.SeverityNumber.WARN, "WARN");
|
|
1602
|
+
}
|
|
1603
|
+
trace(message) {
|
|
1604
|
+
if (this.env.NODE_ENV !== "test") {
|
|
1605
|
+
this.logger.emit({
|
|
1606
|
+
body: message,
|
|
1607
|
+
severityNumber: import_api_logs.SeverityNumber.TRACE,
|
|
1608
|
+
severityText: "TRACE"
|
|
1609
|
+
});
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
child() {
|
|
1613
|
+
return new WinstonOtelFastify2(process.env);
|
|
1614
|
+
}
|
|
1615
|
+
};
|
|
1616
|
+
|
|
1617
|
+
// src/infra/adapters/observability/otel/span-decorator.ts
|
|
1618
|
+
var import_api2 = __toESM(require("@opentelemetry/api"), 1);
|
|
1511
1619
|
var import_reflect_metadata4 = require("reflect-metadata");
|
|
1512
1620
|
function Span() {
|
|
1513
1621
|
return function(target, propertyKey, descriptor) {
|
|
@@ -1516,7 +1624,7 @@ function Span() {
|
|
|
1516
1624
|
}
|
|
1517
1625
|
const originalMethod = descriptor.value;
|
|
1518
1626
|
descriptor.value = function(...args) {
|
|
1519
|
-
const tracer =
|
|
1627
|
+
const tracer = import_api2.default.trace.getTracer(process.env.OTEL_SERVICE_NAME, process.env.OTEL_SERVICE_VERSION);
|
|
1520
1628
|
const className = target.constructor?.name || "UnknownClass";
|
|
1521
1629
|
const methodName = String(propertyKey);
|
|
1522
1630
|
const spanName = `${className}.${methodName}`;
|
|
@@ -1556,7 +1664,7 @@ function handleSpanError(span, error) {
|
|
|
1556
1664
|
span.recordException(new Error(String(error)));
|
|
1557
1665
|
}
|
|
1558
1666
|
span.setStatus({
|
|
1559
|
-
code:
|
|
1667
|
+
code: import_api2.SpanStatusCode.ERROR,
|
|
1560
1668
|
message: errorMessage
|
|
1561
1669
|
});
|
|
1562
1670
|
span.end();
|
|
@@ -1564,7 +1672,7 @@ function handleSpanError(span, error) {
|
|
|
1564
1672
|
__name(handleSpanError, "handleSpanError");
|
|
1565
1673
|
|
|
1566
1674
|
// src/infra/adapters/observability/otel/tracer-gateway-opentelemetry.ts
|
|
1567
|
-
var
|
|
1675
|
+
var import_api3 = __toESM(require("@opentelemetry/api"), 1);
|
|
1568
1676
|
var TracerGatewayOpentelemetry = class {
|
|
1569
1677
|
static {
|
|
1570
1678
|
__name(this, "TracerGatewayOpentelemetry");
|
|
@@ -1573,7 +1681,7 @@ var TracerGatewayOpentelemetry = class {
|
|
|
1573
1681
|
if (!process.env.OTEL_ENABLE) {
|
|
1574
1682
|
return;
|
|
1575
1683
|
}
|
|
1576
|
-
const span =
|
|
1684
|
+
const span = import_api3.default.trace.getActiveSpan();
|
|
1577
1685
|
if (span && attributes) {
|
|
1578
1686
|
span.addEvent(name, attributes);
|
|
1579
1687
|
} else if (span) {
|
|
@@ -1584,7 +1692,7 @@ var TracerGatewayOpentelemetry = class {
|
|
|
1584
1692
|
if (!process.env.OTEL_ENABLE) {
|
|
1585
1693
|
return;
|
|
1586
1694
|
}
|
|
1587
|
-
const span =
|
|
1695
|
+
const span = import_api3.default.trace.getActiveSpan();
|
|
1588
1696
|
if (span) {
|
|
1589
1697
|
span.setAttribute(key, value);
|
|
1590
1698
|
}
|
|
@@ -1653,6 +1761,7 @@ var baseEnvSchema = import_zod.z.object({
|
|
|
1653
1761
|
UniqueObjectId,
|
|
1654
1762
|
ValueObject,
|
|
1655
1763
|
WatchedList,
|
|
1764
|
+
WinstonOtelFastify,
|
|
1656
1765
|
baseEnvSchema,
|
|
1657
1766
|
getTakeAndSkip,
|
|
1658
1767
|
logger,
|