plutin 1.6.6 → 1.7.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.d.ts CHANGED
@@ -3,6 +3,7 @@ import { Express } from 'express';
3
3
  import { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';
4
4
  import { Logger } from '@opentelemetry/api-logs';
5
5
  import winston from 'winston';
6
+ import { NodeSDK } from '@opentelemetry/sdk-node';
6
7
 
7
8
  type AnyObject = Record<string, any>;
8
9
  type Request = {
@@ -341,11 +342,10 @@ interface ILogger {
341
342
  }
342
343
 
343
344
  declare class WinstonOtelFastify implements ILogger {
344
- private readonly env;
345
345
  logger: Logger;
346
346
  consoleLogger: winston.Logger;
347
347
  level: 'info' | 'error' | 'debug' | 'fatal' | 'warn';
348
- constructor(env: Record<string, any>);
348
+ constructor();
349
349
  private bodyIsFastifyRequest;
350
350
  private bodyIsFastifyReply;
351
351
  private buildMessage;
@@ -374,6 +374,13 @@ declare class WinstonOtelFastify implements ILogger {
374
374
  child(): WinstonOtelFastify;
375
375
  }
376
376
 
377
+ declare class OpenTelemetry {
378
+ private readonly env;
379
+ sdk: NodeSDK;
380
+ constructor(env: Record<string, any>);
381
+ startSdk(): void;
382
+ }
383
+
377
384
  declare function Span(): MethodDecorator;
378
385
 
379
386
  interface ITracerGateway {
@@ -393,4 +400,4 @@ declare const logger: {
393
400
  error: (...args: any[]) => void;
394
401
  };
395
402
 
396
- export { AggregateObjectRoot, AggregateRoot, BaseController, CommonDTO, ContextError, Controller, CreateCommonDTO, DependencyContainer, DiscordNotifier, DtoResponsePagination, Entity, EntityObject, ExpressAdapter, FastifyAdapter, GlobalErrorHandler, IErrorNotifier, IHealthCheckDB, IHttp, ILogger, 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 };
403
+ export { AggregateObjectRoot, AggregateRoot, BaseController, CommonDTO, ContextError, Controller, CreateCommonDTO, DependencyContainer, DiscordNotifier, DtoResponsePagination, Entity, EntityObject, ExpressAdapter, FastifyAdapter, GlobalErrorHandler, IErrorNotifier, IHealthCheckDB, IHttp, ILogger, ITracerGateway, Inject, MethodType, MiddlewareFunction, NotPagination, NotificationErrorInMemory, NotificationFactory, OpenTelemetry, Optional, Pagination, Replace, Request, RequestHttp, Response, SentryNotifier, Span, TracerGatewayOpentelemetry, UniqueEntityId, UniqueObjectId, ValueObject, WatchedList, WinstonOtelFastify, ZodSchema, baseEnvSchema, getTakeAndSkip, logger, zodValidator };
package/dist/index.mjs CHANGED
@@ -1467,17 +1467,14 @@ var WinstonOtelFastify = class WinstonOtelFastify2 {
1467
1467
  static {
1468
1468
  __name(this, "WinstonOtelFastify");
1469
1469
  }
1470
- env;
1471
1470
  logger;
1472
1471
  consoleLogger;
1473
- level;
1474
- constructor(env) {
1475
- this.env = env;
1476
- this.level = "info";
1477
- if (this.env.OTEL_ENABLE) {
1478
- this.logger = logs.getLogger(this.env.OTEL_SERVICE_NAME, this.env.OTEL_SERVICE_VERSION);
1479
- this.level = this.env.LOG_LEVEL;
1480
- const transports = this.env.NODE_ENV === "test" ? [
1472
+ level = "info";
1473
+ constructor() {
1474
+ if (process.env.OTEL_ENABLE) {
1475
+ this.logger = logs.getLogger(process.env.OTEL_SERVICE_NAME, process.env.OTEL_SERVICE_VERSION);
1476
+ this.level = process.env.LOG_LEVEL;
1477
+ const transports = process.env.NODE_ENV === "test" ? [
1481
1478
  new winston.transports.Console({
1482
1479
  silent: true
1483
1480
  })
@@ -1489,7 +1486,7 @@ var WinstonOtelFastify = class WinstonOtelFastify2 {
1489
1486
  format: winston.format.combine(winston.format.timestamp({
1490
1487
  format: "YYYY-MM-DD HH:mm:ss:ms"
1491
1488
  }), winston.format((info) => {
1492
- if (this.env.NODE_ENV !== "test") {
1489
+ if (process.env.NODE_ENV !== "test") {
1493
1490
  const span = opentelemetry.trace.getActiveSpan();
1494
1491
  if (span) {
1495
1492
  info.spanId = span.spanContext().spanId;
@@ -1529,7 +1526,7 @@ var WinstonOtelFastify = class WinstonOtelFastify2 {
1529
1526
  logMessage(body, severityNumber, severityText) {
1530
1527
  const message = this.buildMessage(body);
1531
1528
  this.consoleLogger[severityText.toLowerCase()](message);
1532
- if (this.env.NODE_ENV !== "test") {
1529
+ if (process.env.NODE_ENV !== "test") {
1533
1530
  this.logger.emit({
1534
1531
  body: message,
1535
1532
  severityNumber,
@@ -1553,7 +1550,7 @@ var WinstonOtelFastify = class WinstonOtelFastify2 {
1553
1550
  this.logMessage(body, SeverityNumber.WARN, "WARN");
1554
1551
  }
1555
1552
  trace(message) {
1556
- if (this.env.NODE_ENV !== "test") {
1553
+ if (process.env.NODE_ENV !== "test") {
1557
1554
  this.logger.emit({
1558
1555
  body: message,
1559
1556
  severityNumber: SeverityNumber.TRACE,
@@ -1562,7 +1559,47 @@ var WinstonOtelFastify = class WinstonOtelFastify2 {
1562
1559
  }
1563
1560
  }
1564
1561
  child() {
1565
- return new WinstonOtelFastify2(process.env);
1562
+ return new WinstonOtelFastify2();
1563
+ }
1564
+ };
1565
+
1566
+ // src/infra/adapters/observability/otel/opentelemetry.ts
1567
+ import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-proto";
1568
+ import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-proto";
1569
+ import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
1570
+ import { Resource } from "@opentelemetry/resources";
1571
+ import { BatchLogRecordProcessor } from "@opentelemetry/sdk-logs";
1572
+ import { PeriodicExportingMetricReader } from "@opentelemetry/sdk-metrics";
1573
+ import { NodeSDK } from "@opentelemetry/sdk-node";
1574
+ import { SEMRESATTRS_SERVICE_NAME, SEMRESATTRS_SERVICE_VERSION } from "@opentelemetry/semantic-conventions";
1575
+ var OpenTelemetry = class OpenTelemetry2 {
1576
+ static {
1577
+ __name(this, "OpenTelemetry");
1578
+ }
1579
+ env;
1580
+ sdk;
1581
+ constructor(env) {
1582
+ this.env = env;
1583
+ this.sdk = new NodeSDK({
1584
+ resource: new Resource({
1585
+ [SEMRESATTRS_SERVICE_NAME]: this.env.OTEL_SERVICE_NAME,
1586
+ [SEMRESATTRS_SERVICE_VERSION]: this.env.OTEL_SERVICE_VERSION
1587
+ }),
1588
+ traceExporter: new OTLPTraceExporter({
1589
+ url: this.env.OTEL_OTLP_TRACES_EXPORTER_URL
1590
+ }),
1591
+ logRecordProcessor: new BatchLogRecordProcessor(new OTLPLogExporter({
1592
+ url: this.env.OTEL_OTLP_LOGS_EXPORTER_URL
1593
+ })),
1594
+ metricReader: new PeriodicExportingMetricReader({
1595
+ exporter: new OTLPMetricExporter({
1596
+ url: this.env.OTEL_OTLP_METRICS_EXPORTER_URL
1597
+ })
1598
+ })
1599
+ });
1600
+ }
1601
+ startSdk() {
1602
+ this.sdk.start();
1566
1603
  }
1567
1604
  };
1568
1605
 
@@ -1705,6 +1742,7 @@ export {
1705
1742
  Inject,
1706
1743
  NotificationErrorInMemory,
1707
1744
  NotificationFactory,
1745
+ OpenTelemetry,
1708
1746
  SentryNotifier,
1709
1747
  Span,
1710
1748
  TracerGatewayOpentelemetry,