@devopsplaybook.io/otel-utils 1.0.1-beta6 → 1.0.1-beta7

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
@@ -1,4 +1,5 @@
1
1
  export * from "./src/models/ConfigOTelInterface";
2
+ export * from "./src/models/StandardLoggerInterface";
2
3
  export * from "./src/ModuleLogger";
3
4
  export * from "./src/StandardLogger";
4
5
  export * from "./src/StandardMeter";
package/dist/index.js CHANGED
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./src/models/ConfigOTelInterface"), exports);
18
+ __exportStar(require("./src/models/StandardLoggerInterface"), exports);
18
19
  __exportStar(require("./src/ModuleLogger"), exports);
19
20
  __exportStar(require("./src/StandardLogger"), exports);
20
21
  __exportStar(require("./src/StandardMeter"), exports);
@@ -1,8 +1,8 @@
1
- import type { Logger } from "@opentelemetry/api-logs";
1
+ import { StandardLoggerInterface } from "./models/StandardLoggerInterface";
2
2
  export declare class ModuleLogger {
3
3
  private module;
4
- private logger?;
5
- constructor(module: string, logger?: Logger);
4
+ private standardLogger?;
5
+ constructor(module: string, standardLogger: StandardLoggerInterface);
6
6
  info(message: Error | string | any): void;
7
7
  warn(message: Error | string | any): void;
8
8
  error(message: Error | string | any): void;
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ModuleLogger = void 0;
4
4
  const api_logs_1 = require("@opentelemetry/api-logs");
5
5
  class ModuleLogger {
6
- constructor(module, logger) {
6
+ constructor(module, standardLogger) {
7
7
  this.module = module;
8
- this.logger = logger;
8
+ this.standardLogger = standardLogger;
9
9
  }
10
10
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
11
  info(message) {
@@ -22,6 +22,7 @@ class ModuleLogger {
22
22
  display(level,
23
23
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
24
24
  message, severityNumber = api_logs_1.SeverityNumber.INFO) {
25
+ var _a, _b;
25
26
  if (typeof message === "string") {
26
27
  // eslint:disable-next-line:no-console
27
28
  console.log(`[${level}] [${this.module}] ${message}`);
@@ -36,10 +37,10 @@ class ModuleLogger {
36
37
  // eslint:disable-next-line:no-console
37
38
  console.log(`${level} [${this.module}] ${JSON.stringify(message)}`);
38
39
  }
39
- if (!this.logger) {
40
+ if (!((_a = this.standardLogger) === null || _a === void 0 ? void 0 : _a.getLogger())) {
40
41
  return;
41
42
  }
42
- this.logger.emit({
43
+ (_b = this.standardLogger.getLogger()) === null || _b === void 0 ? void 0 : _b.emit({
43
44
  severityNumber,
44
45
  severityText: level,
45
46
  body: message,
@@ -1,9 +1,11 @@
1
+ import type { Logger as OTelLogger } from "@opentelemetry/api-logs";
1
2
  import { ConfigOTelInterface } from "./models/ConfigOTelInterface";
2
3
  import { ModuleLogger } from "./ModuleLogger";
3
4
  export declare class StandardLogger {
4
5
  private logger?;
5
- private serviceVersion;
6
- private serviceName;
7
- constructor(config: ConfigOTelInterface);
6
+ private serviceVersion?;
7
+ private serviceName?;
8
+ initOTel(config: ConfigOTelInterface): void;
9
+ getLogger(): OTelLogger | undefined;
8
10
  createModuleLogger(moduleName: string): ModuleLogger;
9
11
  }
@@ -41,7 +41,7 @@ const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
41
41
  const os = __importStar(require("os"));
42
42
  const ModuleLogger_1 = require("./ModuleLogger");
43
43
  class StandardLogger {
44
- constructor(config) {
44
+ initOTel(config) {
45
45
  this.serviceName = config.SERVICE_ID;
46
46
  this.serviceVersion = config.VERSION;
47
47
  if (config.OPENTELEMETRY_COLLECTOR_HTTP_LOGS) {
@@ -70,8 +70,11 @@ class StandardLogger {
70
70
  this.logger = loggerProvider.getLogger(`${this.serviceName}:${this.serviceVersion}`);
71
71
  }
72
72
  }
73
+ getLogger() {
74
+ return this.logger;
75
+ }
73
76
  createModuleLogger(moduleName) {
74
- return new ModuleLogger_1.ModuleLogger(moduleName, this.logger);
77
+ return new ModuleLogger_1.ModuleLogger(moduleName, this);
75
78
  }
76
79
  }
77
80
  exports.StandardLogger = StandardLogger;
@@ -0,0 +1,4 @@
1
+ import type { Logger } from "@opentelemetry/api-logs";
2
+ export interface StandardLoggerInterface {
3
+ getLogger(): Logger | undefined;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./src/models/ConfigOTelInterface";
2
+ export * from "./src/models/StandardLoggerInterface";
2
3
  export * from "./src/ModuleLogger";
3
4
  export * from "./src/StandardLogger";
4
5
  export * from "./src/StandardMeter";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devopsplaybook.io/otel-utils",
3
- "version": "1.0.1-beta6",
3
+ "version": "1.0.1-beta7",
4
4
  "description": "Utility to simplify integration with Open Telemetry",
5
5
  "keywords": [
6
6
  "Open",
@@ -1,13 +1,13 @@
1
- import type { Logger } from "@opentelemetry/api-logs";
2
1
  import { SeverityNumber } from "@opentelemetry/api-logs";
2
+ import { StandardLoggerInterface } from "./models/StandardLoggerInterface";
3
3
 
4
4
  export class ModuleLogger {
5
5
  private module: string;
6
- private logger?: Logger;
6
+ private standardLogger?: StandardLoggerInterface;
7
7
 
8
- constructor(module: string, logger?: Logger) {
8
+ constructor(module: string, standardLogger: StandardLoggerInterface) {
9
9
  this.module = module;
10
- this.logger = logger;
10
+ this.standardLogger = standardLogger;
11
11
  }
12
12
 
13
13
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -41,10 +41,10 @@ export class ModuleLogger {
41
41
  // eslint:disable-next-line:no-console
42
42
  console.log(`${level} [${this.module}] ${JSON.stringify(message)}`);
43
43
  }
44
- if (!this.logger) {
44
+ if (!this.standardLogger?.getLogger()) {
45
45
  return;
46
46
  }
47
- this.logger.emit({
47
+ this.standardLogger.getLogger()?.emit({
48
48
  severityNumber,
49
49
  severityText: level,
50
50
  body: message,
@@ -1,12 +1,10 @@
1
1
  import type { Logger, Logger as OTelLogger } from "@opentelemetry/api-logs";
2
- import { SeverityNumber } from "@opentelemetry/api-logs";
3
2
  import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
4
3
  import { resourceFromAttributes } from "@opentelemetry/resources";
5
4
  import {
6
5
  BatchLogRecordProcessor,
7
6
  LoggerProvider,
8
7
  } from "@opentelemetry/sdk-logs";
9
- import { Span } from "@opentelemetry/sdk-trace-base";
10
8
  import {
11
9
  ATTR_NETWORK_LOCAL_ADDRESS,
12
10
  ATTR_SERVICE_NAME,
@@ -18,10 +16,10 @@ import { ModuleLogger } from "./ModuleLogger";
18
16
 
19
17
  export class StandardLogger {
20
18
  private logger?: Logger;
21
- private serviceVersion: string;
22
- private serviceName: string;
19
+ private serviceVersion?: string;
20
+ private serviceName?: string;
23
21
 
24
- constructor(config: ConfigOTelInterface) {
22
+ public initOTel(config: ConfigOTelInterface) {
25
23
  this.serviceName = config.SERVICE_ID;
26
24
  this.serviceVersion = config.VERSION;
27
25
 
@@ -59,7 +57,11 @@ export class StandardLogger {
59
57
  }
60
58
  }
61
59
 
60
+ public getLogger(): OTelLogger | undefined {
61
+ return this.logger;
62
+ }
63
+
62
64
  public createModuleLogger(moduleName: string): ModuleLogger {
63
- return new ModuleLogger(moduleName, this.logger);
65
+ return new ModuleLogger(moduleName, this);
64
66
  }
65
67
  }
@@ -0,0 +1,5 @@
1
+ import type { Logger } from "@opentelemetry/api-logs";
2
+
3
+ export interface StandardLoggerInterface {
4
+ getLogger(): Logger | undefined;
5
+ }