plutin 1.5.4 → 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 +103 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -1
- package/dist/index.d.ts +34 -1
- package/dist/index.mjs +101 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -1
- package/readme.md +6 -0
package/dist/index.d.cts
CHANGED
|
@@ -269,13 +269,27 @@ declare const baseEnvSchema: z.ZodObject<{
|
|
|
269
269
|
SHOULD_NOTIFY_ERROR: z.ZodDefault<z.ZodBoolean>;
|
|
270
270
|
SENTRY_DSN: z.ZodOptional<z.ZodString>;
|
|
271
271
|
DISCORD_WEBHOOK_URL: z.ZodOptional<z.ZodString>;
|
|
272
|
+
LOG_LEVEL: z.ZodDefault<z.ZodEnum<["info", "error", "debug", "fatal", "warn"]>>;
|
|
273
|
+
OTEL_ENABLE: z.ZodDefault<z.ZodBoolean>;
|
|
274
|
+
OTEL_SERVICE_NAME: z.ZodOptional<z.ZodString>;
|
|
275
|
+
OTEL_SERVICE_VERSION: z.ZodOptional<z.ZodString>;
|
|
276
|
+
OTEL_OTLP_TRACES_EXPORTER_URL: z.ZodOptional<z.ZodString>;
|
|
277
|
+
OTEL_OTLP_LOGS_EXPORTER_URL: z.ZodOptional<z.ZodString>;
|
|
278
|
+
OTEL_OTLP_METRICS_EXPORTER_URL: z.ZodOptional<z.ZodString>;
|
|
272
279
|
}, "strip", z.ZodTypeAny, {
|
|
273
280
|
ENVIRONMENT: "test" | "development" | "production" | "staging";
|
|
274
281
|
SHOULD_NOTIFY_ERROR: boolean;
|
|
275
282
|
NODE_ENV: "test" | "development" | "production";
|
|
276
283
|
PORT: number;
|
|
284
|
+
LOG_LEVEL: "error" | "fatal" | "warn" | "info" | "debug";
|
|
285
|
+
OTEL_ENABLE: boolean;
|
|
277
286
|
SENTRY_DSN?: string | undefined;
|
|
278
287
|
DISCORD_WEBHOOK_URL?: string | undefined;
|
|
288
|
+
OTEL_SERVICE_NAME?: string | undefined;
|
|
289
|
+
OTEL_SERVICE_VERSION?: string | undefined;
|
|
290
|
+
OTEL_OTLP_TRACES_EXPORTER_URL?: string | undefined;
|
|
291
|
+
OTEL_OTLP_LOGS_EXPORTER_URL?: string | undefined;
|
|
292
|
+
OTEL_OTLP_METRICS_EXPORTER_URL?: string | undefined;
|
|
279
293
|
}, {
|
|
280
294
|
ENVIRONMENT?: "test" | "development" | "production" | "staging" | undefined;
|
|
281
295
|
SHOULD_NOTIFY_ERROR?: boolean | undefined;
|
|
@@ -283,6 +297,13 @@ declare const baseEnvSchema: z.ZodObject<{
|
|
|
283
297
|
PORT?: number | undefined;
|
|
284
298
|
SENTRY_DSN?: string | undefined;
|
|
285
299
|
DISCORD_WEBHOOK_URL?: string | undefined;
|
|
300
|
+
LOG_LEVEL?: "error" | "fatal" | "warn" | "info" | "debug" | undefined;
|
|
301
|
+
OTEL_ENABLE?: boolean | undefined;
|
|
302
|
+
OTEL_SERVICE_NAME?: string | undefined;
|
|
303
|
+
OTEL_SERVICE_VERSION?: string | undefined;
|
|
304
|
+
OTEL_OTLP_TRACES_EXPORTER_URL?: string | undefined;
|
|
305
|
+
OTEL_OTLP_LOGS_EXPORTER_URL?: string | undefined;
|
|
306
|
+
OTEL_OTLP_METRICS_EXPORTER_URL?: string | undefined;
|
|
286
307
|
}>;
|
|
287
308
|
|
|
288
309
|
type OptionsNotifications = 'console' | 'discord' | 'sentry';
|
|
@@ -308,6 +329,18 @@ declare class SentryNotifier implements IErrorNotifier {
|
|
|
308
329
|
notify(error: Error, context: ContextError): Promise<void>;
|
|
309
330
|
}
|
|
310
331
|
|
|
332
|
+
declare function Span(): MethodDecorator;
|
|
333
|
+
|
|
334
|
+
interface ITracerGateway {
|
|
335
|
+
addEvent(name: string, attributes?: Record<string, any>): void;
|
|
336
|
+
setAttribute(key: string, value: string | number | boolean): void;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
declare class TracerGatewayOpentelemetry implements ITracerGateway {
|
|
340
|
+
addEvent(name: string, attributes?: Record<string, any>): void;
|
|
341
|
+
setAttribute(key: string, value: string | number | boolean): void;
|
|
342
|
+
}
|
|
343
|
+
|
|
311
344
|
declare const logger: {
|
|
312
345
|
info: (...args: any[]) => void;
|
|
313
346
|
log: (...args: any[]) => void;
|
|
@@ -315,4 +348,4 @@ declare const logger: {
|
|
|
315
348
|
error: (...args: any[]) => void;
|
|
316
349
|
};
|
|
317
350
|
|
|
318
|
-
export { AggregateObjectRoot, AggregateRoot, BaseController, CommonDTO, ContextError, Controller, CreateCommonDTO, DependencyContainer, DiscordNotifier, DtoResponsePagination, Entity, EntityObject, ExpressAdapter, FastifyAdapter, GlobalErrorHandler, IErrorNotifier, IHealthCheckDB, IHttp, Inject, MethodType, MiddlewareFunction, NotPagination, NotificationErrorInMemory, NotificationFactory, Optional, Pagination, Replace, Request, RequestHttp, Response, SentryNotifier, UniqueEntityId, UniqueObjectId, ValueObject, WatchedList, ZodSchema, baseEnvSchema, getTakeAndSkip, logger, zodValidator };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -269,13 +269,27 @@ declare const baseEnvSchema: z.ZodObject<{
|
|
|
269
269
|
SHOULD_NOTIFY_ERROR: z.ZodDefault<z.ZodBoolean>;
|
|
270
270
|
SENTRY_DSN: z.ZodOptional<z.ZodString>;
|
|
271
271
|
DISCORD_WEBHOOK_URL: z.ZodOptional<z.ZodString>;
|
|
272
|
+
LOG_LEVEL: z.ZodDefault<z.ZodEnum<["info", "error", "debug", "fatal", "warn"]>>;
|
|
273
|
+
OTEL_ENABLE: z.ZodDefault<z.ZodBoolean>;
|
|
274
|
+
OTEL_SERVICE_NAME: z.ZodOptional<z.ZodString>;
|
|
275
|
+
OTEL_SERVICE_VERSION: z.ZodOptional<z.ZodString>;
|
|
276
|
+
OTEL_OTLP_TRACES_EXPORTER_URL: z.ZodOptional<z.ZodString>;
|
|
277
|
+
OTEL_OTLP_LOGS_EXPORTER_URL: z.ZodOptional<z.ZodString>;
|
|
278
|
+
OTEL_OTLP_METRICS_EXPORTER_URL: z.ZodOptional<z.ZodString>;
|
|
272
279
|
}, "strip", z.ZodTypeAny, {
|
|
273
280
|
ENVIRONMENT: "test" | "development" | "production" | "staging";
|
|
274
281
|
SHOULD_NOTIFY_ERROR: boolean;
|
|
275
282
|
NODE_ENV: "test" | "development" | "production";
|
|
276
283
|
PORT: number;
|
|
284
|
+
LOG_LEVEL: "error" | "fatal" | "warn" | "info" | "debug";
|
|
285
|
+
OTEL_ENABLE: boolean;
|
|
277
286
|
SENTRY_DSN?: string | undefined;
|
|
278
287
|
DISCORD_WEBHOOK_URL?: string | undefined;
|
|
288
|
+
OTEL_SERVICE_NAME?: string | undefined;
|
|
289
|
+
OTEL_SERVICE_VERSION?: string | undefined;
|
|
290
|
+
OTEL_OTLP_TRACES_EXPORTER_URL?: string | undefined;
|
|
291
|
+
OTEL_OTLP_LOGS_EXPORTER_URL?: string | undefined;
|
|
292
|
+
OTEL_OTLP_METRICS_EXPORTER_URL?: string | undefined;
|
|
279
293
|
}, {
|
|
280
294
|
ENVIRONMENT?: "test" | "development" | "production" | "staging" | undefined;
|
|
281
295
|
SHOULD_NOTIFY_ERROR?: boolean | undefined;
|
|
@@ -283,6 +297,13 @@ declare const baseEnvSchema: z.ZodObject<{
|
|
|
283
297
|
PORT?: number | undefined;
|
|
284
298
|
SENTRY_DSN?: string | undefined;
|
|
285
299
|
DISCORD_WEBHOOK_URL?: string | undefined;
|
|
300
|
+
LOG_LEVEL?: "error" | "fatal" | "warn" | "info" | "debug" | undefined;
|
|
301
|
+
OTEL_ENABLE?: boolean | undefined;
|
|
302
|
+
OTEL_SERVICE_NAME?: string | undefined;
|
|
303
|
+
OTEL_SERVICE_VERSION?: string | undefined;
|
|
304
|
+
OTEL_OTLP_TRACES_EXPORTER_URL?: string | undefined;
|
|
305
|
+
OTEL_OTLP_LOGS_EXPORTER_URL?: string | undefined;
|
|
306
|
+
OTEL_OTLP_METRICS_EXPORTER_URL?: string | undefined;
|
|
286
307
|
}>;
|
|
287
308
|
|
|
288
309
|
type OptionsNotifications = 'console' | 'discord' | 'sentry';
|
|
@@ -308,6 +329,18 @@ declare class SentryNotifier implements IErrorNotifier {
|
|
|
308
329
|
notify(error: Error, context: ContextError): Promise<void>;
|
|
309
330
|
}
|
|
310
331
|
|
|
332
|
+
declare function Span(): MethodDecorator;
|
|
333
|
+
|
|
334
|
+
interface ITracerGateway {
|
|
335
|
+
addEvent(name: string, attributes?: Record<string, any>): void;
|
|
336
|
+
setAttribute(key: string, value: string | number | boolean): void;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
declare class TracerGatewayOpentelemetry implements ITracerGateway {
|
|
340
|
+
addEvent(name: string, attributes?: Record<string, any>): void;
|
|
341
|
+
setAttribute(key: string, value: string | number | boolean): void;
|
|
342
|
+
}
|
|
343
|
+
|
|
311
344
|
declare const logger: {
|
|
312
345
|
info: (...args: any[]) => void;
|
|
313
346
|
log: (...args: any[]) => void;
|
|
@@ -315,4 +348,4 @@ declare const logger: {
|
|
|
315
348
|
error: (...args: any[]) => void;
|
|
316
349
|
};
|
|
317
350
|
|
|
318
|
-
export { AggregateObjectRoot, AggregateRoot, BaseController, CommonDTO, ContextError, Controller, CreateCommonDTO, DependencyContainer, DiscordNotifier, DtoResponsePagination, Entity, EntityObject, ExpressAdapter, FastifyAdapter, GlobalErrorHandler, IErrorNotifier, IHealthCheckDB, IHttp, Inject, MethodType, MiddlewareFunction, NotPagination, NotificationErrorInMemory, NotificationFactory, Optional, Pagination, Replace, Request, RequestHttp, Response, SentryNotifier, UniqueEntityId, UniqueObjectId, ValueObject, WatchedList, ZodSchema, baseEnvSchema, getTakeAndSkip, logger, zodValidator };
|
|
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 };
|
package/dist/index.mjs
CHANGED
|
@@ -1456,6 +1456,91 @@ function zodValidator(schema) {
|
|
|
1456
1456
|
}
|
|
1457
1457
|
__name(zodValidator, "zodValidator");
|
|
1458
1458
|
|
|
1459
|
+
// src/infra/adapters/observability/otel/span-decorator.ts
|
|
1460
|
+
import opentelemetry, { SpanStatusCode } from "@opentelemetry/api";
|
|
1461
|
+
import "reflect-metadata";
|
|
1462
|
+
function Span() {
|
|
1463
|
+
return function(target, propertyKey, descriptor) {
|
|
1464
|
+
if (!process.env.OTEL_ENABLE) {
|
|
1465
|
+
return descriptor;
|
|
1466
|
+
}
|
|
1467
|
+
const originalMethod = descriptor.value;
|
|
1468
|
+
descriptor.value = function(...args) {
|
|
1469
|
+
const tracer = opentelemetry.trace.getTracer(process.env.OTEL_SERVICE_NAME, process.env.OTEL_SERVICE_VERSION);
|
|
1470
|
+
const className = target.constructor?.name || "UnknownClass";
|
|
1471
|
+
const methodName = String(propertyKey);
|
|
1472
|
+
const spanName = `${className}.${methodName}`;
|
|
1473
|
+
return tracer.startActiveSpan(spanName, async (span) => {
|
|
1474
|
+
try {
|
|
1475
|
+
const result = originalMethod.apply(this, args);
|
|
1476
|
+
if (result instanceof Promise) {
|
|
1477
|
+
try {
|
|
1478
|
+
const awaitedResult = await result;
|
|
1479
|
+
span.addEvent(`Method [${methodName}] executed successfully`);
|
|
1480
|
+
span.end();
|
|
1481
|
+
return awaitedResult;
|
|
1482
|
+
} catch (error) {
|
|
1483
|
+
handleSpanError(span, error);
|
|
1484
|
+
throw error;
|
|
1485
|
+
}
|
|
1486
|
+
} else {
|
|
1487
|
+
span.addEvent(`Method [${methodName}] executed successfully`);
|
|
1488
|
+
span.end();
|
|
1489
|
+
return result;
|
|
1490
|
+
}
|
|
1491
|
+
} catch (error) {
|
|
1492
|
+
handleSpanError(span, error);
|
|
1493
|
+
throw error;
|
|
1494
|
+
}
|
|
1495
|
+
});
|
|
1496
|
+
};
|
|
1497
|
+
return descriptor;
|
|
1498
|
+
};
|
|
1499
|
+
}
|
|
1500
|
+
__name(Span, "Span");
|
|
1501
|
+
function handleSpanError(span, error) {
|
|
1502
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1503
|
+
if (error instanceof Error) {
|
|
1504
|
+
span.recordException(error);
|
|
1505
|
+
} else {
|
|
1506
|
+
span.recordException(new Error(String(error)));
|
|
1507
|
+
}
|
|
1508
|
+
span.setStatus({
|
|
1509
|
+
code: SpanStatusCode.ERROR,
|
|
1510
|
+
message: errorMessage
|
|
1511
|
+
});
|
|
1512
|
+
span.end();
|
|
1513
|
+
}
|
|
1514
|
+
__name(handleSpanError, "handleSpanError");
|
|
1515
|
+
|
|
1516
|
+
// src/infra/adapters/observability/otel/tracer-gateway-opentelemetry.ts
|
|
1517
|
+
import opentelemetry2 from "@opentelemetry/api";
|
|
1518
|
+
var TracerGatewayOpentelemetry = class {
|
|
1519
|
+
static {
|
|
1520
|
+
__name(this, "TracerGatewayOpentelemetry");
|
|
1521
|
+
}
|
|
1522
|
+
addEvent(name, attributes) {
|
|
1523
|
+
if (!process.env.OTEL_ENABLE) {
|
|
1524
|
+
return;
|
|
1525
|
+
}
|
|
1526
|
+
const span = opentelemetry2.trace.getActiveSpan();
|
|
1527
|
+
if (span && attributes) {
|
|
1528
|
+
span.addEvent(name, attributes);
|
|
1529
|
+
} else if (span) {
|
|
1530
|
+
span.addEvent(name);
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
setAttribute(key, value) {
|
|
1534
|
+
if (!process.env.OTEL_ENABLE) {
|
|
1535
|
+
return;
|
|
1536
|
+
}
|
|
1537
|
+
const span = opentelemetry2.trace.getActiveSpan();
|
|
1538
|
+
if (span) {
|
|
1539
|
+
span.setAttribute(key, value);
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
};
|
|
1543
|
+
|
|
1459
1544
|
// src/infra/env/index.ts
|
|
1460
1545
|
import { z } from "zod";
|
|
1461
1546
|
|
|
@@ -1480,7 +1565,20 @@ var baseEnvSchema = z.object({
|
|
|
1480
1565
|
PORT: z.coerce.number().default(3333),
|
|
1481
1566
|
SHOULD_NOTIFY_ERROR: z.coerce.boolean().default(true),
|
|
1482
1567
|
SENTRY_DSN: z.string().optional(),
|
|
1483
|
-
DISCORD_WEBHOOK_URL: z.string().optional()
|
|
1568
|
+
DISCORD_WEBHOOK_URL: z.string().optional(),
|
|
1569
|
+
LOG_LEVEL: z.enum([
|
|
1570
|
+
"info",
|
|
1571
|
+
"error",
|
|
1572
|
+
"debug",
|
|
1573
|
+
"fatal",
|
|
1574
|
+
"warn"
|
|
1575
|
+
]).default("info"),
|
|
1576
|
+
OTEL_ENABLE: z.coerce.boolean().default(false),
|
|
1577
|
+
OTEL_SERVICE_NAME: z.string().optional(),
|
|
1578
|
+
OTEL_SERVICE_VERSION: z.string().optional(),
|
|
1579
|
+
OTEL_OTLP_TRACES_EXPORTER_URL: z.string().url().optional(),
|
|
1580
|
+
OTEL_OTLP_LOGS_EXPORTER_URL: z.string().url().optional(),
|
|
1581
|
+
OTEL_OTLP_METRICS_EXPORTER_URL: z.string().url().optional()
|
|
1484
1582
|
});
|
|
1485
1583
|
export {
|
|
1486
1584
|
AggregateObjectRoot,
|
|
@@ -1498,6 +1596,8 @@ export {
|
|
|
1498
1596
|
NotificationErrorInMemory,
|
|
1499
1597
|
NotificationFactory,
|
|
1500
1598
|
SentryNotifier,
|
|
1599
|
+
Span,
|
|
1600
|
+
TracerGatewayOpentelemetry,
|
|
1501
1601
|
UniqueEntityId,
|
|
1502
1602
|
UniqueObjectId,
|
|
1503
1603
|
ValueObject,
|