plutin 1.5.3 → 1.6.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 +108 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +39 -6
- package/dist/index.d.ts +39 -6
- package/dist/index.mjs +105 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -1
- package/readme.md +6 -0
package/dist/index.cjs
CHANGED
|
@@ -457,8 +457,10 @@ __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,
|
|
464
466
|
baseEnvSchema: () => baseEnvSchema,
|
|
@@ -791,9 +793,9 @@ __name(Controller, "Controller");
|
|
|
791
793
|
|
|
792
794
|
// src/core/entities/unique-object-id.ts
|
|
793
795
|
var import_bson = require("bson");
|
|
794
|
-
var
|
|
796
|
+
var UniqueObjectId = class {
|
|
795
797
|
static {
|
|
796
|
-
__name(this, "
|
|
798
|
+
__name(this, "UniqueObjectId");
|
|
797
799
|
}
|
|
798
800
|
value;
|
|
799
801
|
constructor(value) {
|
|
@@ -836,7 +838,7 @@ var EntityObject = class {
|
|
|
836
838
|
this.props.updatedAt = /* @__PURE__ */ new Date();
|
|
837
839
|
}
|
|
838
840
|
constructor(props, id) {
|
|
839
|
-
this._id = id ?? new
|
|
841
|
+
this._id = id ?? new UniqueObjectId(id);
|
|
840
842
|
this.props = props;
|
|
841
843
|
}
|
|
842
844
|
equals(entity) {
|
|
@@ -1504,6 +1506,91 @@ function zodValidator(schema) {
|
|
|
1504
1506
|
}
|
|
1505
1507
|
__name(zodValidator, "zodValidator");
|
|
1506
1508
|
|
|
1509
|
+
// src/infra/adapters/observability/otel/span-decorator.ts
|
|
1510
|
+
var import_api = __toESM(require("@opentelemetry/api"), 1);
|
|
1511
|
+
var import_reflect_metadata4 = require("reflect-metadata");
|
|
1512
|
+
function Span() {
|
|
1513
|
+
return function(target, propertyKey, descriptor) {
|
|
1514
|
+
if (!process.env.OTEL_ENABLE) {
|
|
1515
|
+
return descriptor;
|
|
1516
|
+
}
|
|
1517
|
+
const originalMethod = descriptor.value;
|
|
1518
|
+
descriptor.value = function(...args) {
|
|
1519
|
+
const tracer = import_api.default.trace.getTracer(process.env.OTEL_SERVICE_NAME, process.env.OTEL_SERVICE_VERSION);
|
|
1520
|
+
const className = target.constructor?.name || "UnknownClass";
|
|
1521
|
+
const methodName = String(propertyKey);
|
|
1522
|
+
const spanName = `${className}.${methodName}`;
|
|
1523
|
+
return tracer.startActiveSpan(spanName, async (span) => {
|
|
1524
|
+
try {
|
|
1525
|
+
const result = originalMethod.apply(this, args);
|
|
1526
|
+
if (result instanceof Promise) {
|
|
1527
|
+
try {
|
|
1528
|
+
const awaitedResult = await result;
|
|
1529
|
+
span.addEvent(`Method [${methodName}] executed successfully`);
|
|
1530
|
+
span.end();
|
|
1531
|
+
return awaitedResult;
|
|
1532
|
+
} catch (error) {
|
|
1533
|
+
handleSpanError(span, error);
|
|
1534
|
+
throw error;
|
|
1535
|
+
}
|
|
1536
|
+
} else {
|
|
1537
|
+
span.addEvent(`Method [${methodName}] executed successfully`);
|
|
1538
|
+
span.end();
|
|
1539
|
+
return result;
|
|
1540
|
+
}
|
|
1541
|
+
} catch (error) {
|
|
1542
|
+
handleSpanError(span, error);
|
|
1543
|
+
throw error;
|
|
1544
|
+
}
|
|
1545
|
+
});
|
|
1546
|
+
};
|
|
1547
|
+
return descriptor;
|
|
1548
|
+
};
|
|
1549
|
+
}
|
|
1550
|
+
__name(Span, "Span");
|
|
1551
|
+
function handleSpanError(span, error) {
|
|
1552
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1553
|
+
if (error instanceof Error) {
|
|
1554
|
+
span.recordException(error);
|
|
1555
|
+
} else {
|
|
1556
|
+
span.recordException(new Error(String(error)));
|
|
1557
|
+
}
|
|
1558
|
+
span.setStatus({
|
|
1559
|
+
code: import_api.SpanStatusCode.ERROR,
|
|
1560
|
+
message: errorMessage
|
|
1561
|
+
});
|
|
1562
|
+
span.end();
|
|
1563
|
+
}
|
|
1564
|
+
__name(handleSpanError, "handleSpanError");
|
|
1565
|
+
|
|
1566
|
+
// src/infra/adapters/observability/otel/tracer-gateway-opentelemetry.ts
|
|
1567
|
+
var import_api2 = __toESM(require("@opentelemetry/api"), 1);
|
|
1568
|
+
var TracerGatewayOpentelemetry = class {
|
|
1569
|
+
static {
|
|
1570
|
+
__name(this, "TracerGatewayOpentelemetry");
|
|
1571
|
+
}
|
|
1572
|
+
addEvent(name, attributes) {
|
|
1573
|
+
if (!process.env.OTEL_ENABLE) {
|
|
1574
|
+
return;
|
|
1575
|
+
}
|
|
1576
|
+
const span = import_api2.default.trace.getActiveSpan();
|
|
1577
|
+
if (span && attributes) {
|
|
1578
|
+
span.addEvent(name, attributes);
|
|
1579
|
+
} else if (span) {
|
|
1580
|
+
span.addEvent(name);
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
setAttribute(key, value) {
|
|
1584
|
+
if (!process.env.OTEL_ENABLE) {
|
|
1585
|
+
return;
|
|
1586
|
+
}
|
|
1587
|
+
const span = import_api2.default.trace.getActiveSpan();
|
|
1588
|
+
if (span) {
|
|
1589
|
+
span.setAttribute(key, value);
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
};
|
|
1593
|
+
|
|
1507
1594
|
// src/infra/env/index.ts
|
|
1508
1595
|
var import_zod = require("zod");
|
|
1509
1596
|
|
|
@@ -1528,7 +1615,20 @@ var baseEnvSchema = import_zod.z.object({
|
|
|
1528
1615
|
PORT: import_zod.z.coerce.number().default(3333),
|
|
1529
1616
|
SHOULD_NOTIFY_ERROR: import_zod.z.coerce.boolean().default(true),
|
|
1530
1617
|
SENTRY_DSN: import_zod.z.string().optional(),
|
|
1531
|
-
DISCORD_WEBHOOK_URL: import_zod.z.string().optional()
|
|
1618
|
+
DISCORD_WEBHOOK_URL: import_zod.z.string().optional(),
|
|
1619
|
+
LOG_LEVEL: import_zod.z.enum([
|
|
1620
|
+
"info",
|
|
1621
|
+
"error",
|
|
1622
|
+
"debug",
|
|
1623
|
+
"fatal",
|
|
1624
|
+
"warn"
|
|
1625
|
+
]).default("info"),
|
|
1626
|
+
OTEL_ENABLE: import_zod.z.coerce.boolean().default(false),
|
|
1627
|
+
OTEL_SERVICE_NAME: import_zod.z.string().optional(),
|
|
1628
|
+
OTEL_SERVICE_VERSION: import_zod.z.string().optional(),
|
|
1629
|
+
OTEL_OTLP_TRACES_EXPORTER_URL: import_zod.z.string().url().optional(),
|
|
1630
|
+
OTEL_OTLP_LOGS_EXPORTER_URL: import_zod.z.string().url().optional(),
|
|
1631
|
+
OTEL_OTLP_METRICS_EXPORTER_URL: import_zod.z.string().url().optional()
|
|
1532
1632
|
});
|
|
1533
1633
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1534
1634
|
0 && (module.exports = {
|
|
@@ -1547,8 +1647,10 @@ var baseEnvSchema = import_zod.z.object({
|
|
|
1547
1647
|
NotificationErrorInMemory,
|
|
1548
1648
|
NotificationFactory,
|
|
1549
1649
|
SentryNotifier,
|
|
1650
|
+
Span,
|
|
1651
|
+
TracerGatewayOpentelemetry,
|
|
1550
1652
|
UniqueEntityId,
|
|
1551
|
-
|
|
1653
|
+
UniqueObjectId,
|
|
1552
1654
|
ValueObject,
|
|
1553
1655
|
WatchedList,
|
|
1554
1656
|
baseEnvSchema,
|