plutin 1.5.4 → 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 +212 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +71 -2
- package/dist/index.d.ts +71 -2
- package/dist/index.mjs +209 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -1
- package/readme.md +6 -0
package/dist/index.cjs
CHANGED
|
@@ -457,10 +457,13 @@ __export(src_exports, {
|
|
|
457
457
|
NotificationErrorInMemory: () => NotificationErrorInMemory,
|
|
458
458
|
NotificationFactory: () => NotificationFactory,
|
|
459
459
|
SentryNotifier: () => SentryNotifier,
|
|
460
|
+
Span: () => Span,
|
|
461
|
+
TracerGatewayOpentelemetry: () => TracerGatewayOpentelemetry,
|
|
460
462
|
UniqueEntityId: () => UniqueEntityId,
|
|
461
463
|
UniqueObjectId: () => UniqueObjectId,
|
|
462
464
|
ValueObject: () => ValueObject,
|
|
463
465
|
WatchedList: () => WatchedList,
|
|
466
|
+
WinstonOtelFastify: () => WinstonOtelFastify,
|
|
464
467
|
baseEnvSchema: () => baseEnvSchema,
|
|
465
468
|
getTakeAndSkip: () => getTakeAndSkip,
|
|
466
469
|
logger: () => logger,
|
|
@@ -1504,6 +1507,198 @@ function zodValidator(schema) {
|
|
|
1504
1507
|
}
|
|
1505
1508
|
__name(zodValidator, "zodValidator");
|
|
1506
1509
|
|
|
1510
|
+
// src/infra/adapters/logger/winston-otel-fastify.ts
|
|
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);
|
|
1619
|
+
var import_reflect_metadata4 = require("reflect-metadata");
|
|
1620
|
+
function Span() {
|
|
1621
|
+
return function(target, propertyKey, descriptor) {
|
|
1622
|
+
if (!process.env.OTEL_ENABLE) {
|
|
1623
|
+
return descriptor;
|
|
1624
|
+
}
|
|
1625
|
+
const originalMethod = descriptor.value;
|
|
1626
|
+
descriptor.value = function(...args) {
|
|
1627
|
+
const tracer = import_api2.default.trace.getTracer(process.env.OTEL_SERVICE_NAME, process.env.OTEL_SERVICE_VERSION);
|
|
1628
|
+
const className = target.constructor?.name || "UnknownClass";
|
|
1629
|
+
const methodName = String(propertyKey);
|
|
1630
|
+
const spanName = `${className}.${methodName}`;
|
|
1631
|
+
return tracer.startActiveSpan(spanName, async (span) => {
|
|
1632
|
+
try {
|
|
1633
|
+
const result = originalMethod.apply(this, args);
|
|
1634
|
+
if (result instanceof Promise) {
|
|
1635
|
+
try {
|
|
1636
|
+
const awaitedResult = await result;
|
|
1637
|
+
span.addEvent(`Method [${methodName}] executed successfully`);
|
|
1638
|
+
span.end();
|
|
1639
|
+
return awaitedResult;
|
|
1640
|
+
} catch (error) {
|
|
1641
|
+
handleSpanError(span, error);
|
|
1642
|
+
throw error;
|
|
1643
|
+
}
|
|
1644
|
+
} else {
|
|
1645
|
+
span.addEvent(`Method [${methodName}] executed successfully`);
|
|
1646
|
+
span.end();
|
|
1647
|
+
return result;
|
|
1648
|
+
}
|
|
1649
|
+
} catch (error) {
|
|
1650
|
+
handleSpanError(span, error);
|
|
1651
|
+
throw error;
|
|
1652
|
+
}
|
|
1653
|
+
});
|
|
1654
|
+
};
|
|
1655
|
+
return descriptor;
|
|
1656
|
+
};
|
|
1657
|
+
}
|
|
1658
|
+
__name(Span, "Span");
|
|
1659
|
+
function handleSpanError(span, error) {
|
|
1660
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1661
|
+
if (error instanceof Error) {
|
|
1662
|
+
span.recordException(error);
|
|
1663
|
+
} else {
|
|
1664
|
+
span.recordException(new Error(String(error)));
|
|
1665
|
+
}
|
|
1666
|
+
span.setStatus({
|
|
1667
|
+
code: import_api2.SpanStatusCode.ERROR,
|
|
1668
|
+
message: errorMessage
|
|
1669
|
+
});
|
|
1670
|
+
span.end();
|
|
1671
|
+
}
|
|
1672
|
+
__name(handleSpanError, "handleSpanError");
|
|
1673
|
+
|
|
1674
|
+
// src/infra/adapters/observability/otel/tracer-gateway-opentelemetry.ts
|
|
1675
|
+
var import_api3 = __toESM(require("@opentelemetry/api"), 1);
|
|
1676
|
+
var TracerGatewayOpentelemetry = class {
|
|
1677
|
+
static {
|
|
1678
|
+
__name(this, "TracerGatewayOpentelemetry");
|
|
1679
|
+
}
|
|
1680
|
+
addEvent(name, attributes) {
|
|
1681
|
+
if (!process.env.OTEL_ENABLE) {
|
|
1682
|
+
return;
|
|
1683
|
+
}
|
|
1684
|
+
const span = import_api3.default.trace.getActiveSpan();
|
|
1685
|
+
if (span && attributes) {
|
|
1686
|
+
span.addEvent(name, attributes);
|
|
1687
|
+
} else if (span) {
|
|
1688
|
+
span.addEvent(name);
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
setAttribute(key, value) {
|
|
1692
|
+
if (!process.env.OTEL_ENABLE) {
|
|
1693
|
+
return;
|
|
1694
|
+
}
|
|
1695
|
+
const span = import_api3.default.trace.getActiveSpan();
|
|
1696
|
+
if (span) {
|
|
1697
|
+
span.setAttribute(key, value);
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
};
|
|
1701
|
+
|
|
1507
1702
|
// src/infra/env/index.ts
|
|
1508
1703
|
var import_zod = require("zod");
|
|
1509
1704
|
|
|
@@ -1528,7 +1723,20 @@ var baseEnvSchema = import_zod.z.object({
|
|
|
1528
1723
|
PORT: import_zod.z.coerce.number().default(3333),
|
|
1529
1724
|
SHOULD_NOTIFY_ERROR: import_zod.z.coerce.boolean().default(true),
|
|
1530
1725
|
SENTRY_DSN: import_zod.z.string().optional(),
|
|
1531
|
-
DISCORD_WEBHOOK_URL: import_zod.z.string().optional()
|
|
1726
|
+
DISCORD_WEBHOOK_URL: import_zod.z.string().optional(),
|
|
1727
|
+
LOG_LEVEL: import_zod.z.enum([
|
|
1728
|
+
"info",
|
|
1729
|
+
"error",
|
|
1730
|
+
"debug",
|
|
1731
|
+
"fatal",
|
|
1732
|
+
"warn"
|
|
1733
|
+
]).default("info"),
|
|
1734
|
+
OTEL_ENABLE: import_zod.z.coerce.boolean().default(false),
|
|
1735
|
+
OTEL_SERVICE_NAME: import_zod.z.string().optional(),
|
|
1736
|
+
OTEL_SERVICE_VERSION: import_zod.z.string().optional(),
|
|
1737
|
+
OTEL_OTLP_TRACES_EXPORTER_URL: import_zod.z.string().url().optional(),
|
|
1738
|
+
OTEL_OTLP_LOGS_EXPORTER_URL: import_zod.z.string().url().optional(),
|
|
1739
|
+
OTEL_OTLP_METRICS_EXPORTER_URL: import_zod.z.string().url().optional()
|
|
1532
1740
|
});
|
|
1533
1741
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1534
1742
|
0 && (module.exports = {
|
|
@@ -1547,10 +1755,13 @@ var baseEnvSchema = import_zod.z.object({
|
|
|
1547
1755
|
NotificationErrorInMemory,
|
|
1548
1756
|
NotificationFactory,
|
|
1549
1757
|
SentryNotifier,
|
|
1758
|
+
Span,
|
|
1759
|
+
TracerGatewayOpentelemetry,
|
|
1550
1760
|
UniqueEntityId,
|
|
1551
1761
|
UniqueObjectId,
|
|
1552
1762
|
ValueObject,
|
|
1553
1763
|
WatchedList,
|
|
1764
|
+
WinstonOtelFastify,
|
|
1554
1765
|
baseEnvSchema,
|
|
1555
1766
|
getTakeAndSkip,
|
|
1556
1767
|
logger,
|