@devopsplaybook.io/otel-utils 1.0.3 → 1.0.4

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.
@@ -4,8 +4,8 @@ export declare class ModuleLogger {
4
4
  private module;
5
5
  private standardLogger?;
6
6
  constructor(module: string, standardLogger: StandardLoggerInterface);
7
- info(message: Error | string | any, context?: Span): void;
8
- warn(message: Error | string | any, context?: Span): void;
9
- error(message: Error | string | any, context?: Span): void;
7
+ info(message: string, context?: Span): void;
8
+ warn(message: string, context?: Span): void;
9
+ error(message: string, error?: Error, context?: Span): void;
10
10
  private display;
11
11
  }
@@ -7,37 +7,26 @@ class ModuleLogger {
7
7
  this.module = module;
8
8
  this.standardLogger = standardLogger;
9
9
  }
10
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
10
  info(message, context) {
12
- this.display("info", message, api_logs_1.SeverityNumber.INFO, context);
11
+ this.display("info", message, api_logs_1.SeverityNumber.INFO, null, context);
13
12
  }
14
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
13
  warn(message, context) {
16
- this.display("warn", message, api_logs_1.SeverityNumber.WARN, context);
14
+ this.display("warn", message, api_logs_1.SeverityNumber.WARN, null, context);
17
15
  }
18
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
- error(message, context) {
20
- this.display("error", message, api_logs_1.SeverityNumber.ERROR, context);
16
+ error(message, error, context) {
17
+ this.display("error", message, api_logs_1.SeverityNumber.ERROR, error, context);
21
18
  }
22
- display(level,
23
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
24
- message, severityNumber = api_logs_1.SeverityNumber.INFO, context) {
19
+ display(level, message, severityNumber = api_logs_1.SeverityNumber.INFO, error, context) {
25
20
  var _a, _b;
26
- let formattedMessage = "";
21
+ let formattedMessage = message;
27
22
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
23
  const attributes = { "log.type": "custom" };
29
- if (typeof message === "string") {
30
- formattedMessage = message;
31
- }
32
- else if (message instanceof Error) {
33
- formattedMessage = message.message;
34
- attributes["exception.type"] = message.name;
35
- attributes["exception.message"] = message.message;
36
- attributes["exception.stacktrace"] = message.stack;
37
- console.log(message.stack);
38
- }
39
- else if (typeof message === "object") {
40
- formattedMessage = JSON.stringify(message);
24
+ formattedMessage = message;
25
+ if (error) {
26
+ attributes["exception.type"] = error.name;
27
+ attributes["exception.message"] = error.message;
28
+ attributes["exception.stacktrace"] = error.stack;
29
+ formattedMessage += "\n" + error.stack;
41
30
  }
42
31
  if (context) {
43
32
  const spanCtx = context.spanContext();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devopsplaybook.io/otel-utils",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Utility to simplify integration with Open Telemetry",
5
5
  "keywords": [
6
6
  "Open",
@@ -11,40 +11,36 @@ export class ModuleLogger {
11
11
  this.standardLogger = standardLogger;
12
12
  }
13
13
 
14
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
- public info(message: Error | string | any, context?: Span): void {
16
- this.display("info", message, SeverityNumber.INFO, context);
14
+ public info(message: string, context?: Span): void {
15
+ this.display("info", message, SeverityNumber.INFO, null, context);
17
16
  }
18
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
- public warn(message: Error | string | any, context?: Span): void {
20
- this.display("warn", message, SeverityNumber.WARN, context);
17
+
18
+ public warn(message: string, context?: Span): void {
19
+ this.display("warn", message, SeverityNumber.WARN, null, context);
21
20
  }
22
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
- public error(message: Error | string | any, context?: Span): void {
24
- this.display("error", message, SeverityNumber.ERROR, context);
21
+
22
+ public error(message: string, error?: Error, context?: Span): void {
23
+ this.display("error", message, SeverityNumber.ERROR, error, context);
25
24
  }
26
25
 
27
26
  private display(
28
27
  level: string,
29
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
- message: string | Error | any,
28
+ message: string,
31
29
  severityNumber = SeverityNumber.INFO,
30
+ error?: Error | null,
32
31
  context?: Span
33
32
  ): void {
34
- let formattedMessage = "";
33
+ let formattedMessage = message;
34
+
35
35
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
36
36
  const attributes: Record<string, any> = { "log.type": "custom" };
37
37
 
38
- if (typeof message === "string") {
39
- formattedMessage = message;
40
- } else if (message instanceof Error) {
41
- formattedMessage = message.message;
42
- attributes["exception.type"] = message.name;
43
- attributes["exception.message"] = message.message;
44
- attributes["exception.stacktrace"] = message.stack;
45
- console.log((message as Error).stack);
46
- } else if (typeof message === "object") {
47
- formattedMessage = JSON.stringify(message);
38
+ formattedMessage = message;
39
+ if (error) {
40
+ attributes["exception.type"] = error.name;
41
+ attributes["exception.message"] = error.message;
42
+ attributes["exception.stacktrace"] = error.stack;
43
+ formattedMessage += "\n" + error.stack;
48
44
  }
49
45
 
50
46
  if (context) {