@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 +1 -0
- package/dist/index.js +1 -0
- package/dist/src/ModuleLogger.d.ts +3 -3
- package/dist/src/ModuleLogger.js +5 -4
- package/dist/src/StandardLogger.d.ts +5 -3
- package/dist/src/StandardLogger.js +5 -2
- package/dist/src/models/StandardLoggerInterface.d.ts +4 -0
- package/dist/src/models/StandardLoggerInterface.js +2 -0
- package/index.ts +1 -0
- package/package.json +1 -1
- package/src/ModuleLogger.ts +6 -6
- package/src/StandardLogger.ts +8 -6
- package/src/models/StandardLoggerInterface.ts +5 -0
package/dist/index.d.ts
CHANGED
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
|
|
1
|
+
import { StandardLoggerInterface } from "./models/StandardLoggerInterface";
|
|
2
2
|
export declare class ModuleLogger {
|
|
3
3
|
private module;
|
|
4
|
-
private
|
|
5
|
-
constructor(module: string,
|
|
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;
|
package/dist/src/ModuleLogger.js
CHANGED
|
@@ -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,
|
|
6
|
+
constructor(module, standardLogger) {
|
|
7
7
|
this.module = module;
|
|
8
|
-
this.
|
|
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.
|
|
40
|
+
if (!((_a = this.standardLogger) === null || _a === void 0 ? void 0 : _a.getLogger())) {
|
|
40
41
|
return;
|
|
41
42
|
}
|
|
42
|
-
this.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
77
|
+
return new ModuleLogger_1.ModuleLogger(moduleName, this);
|
|
75
78
|
}
|
|
76
79
|
}
|
|
77
80
|
exports.StandardLogger = StandardLogger;
|
package/index.ts
CHANGED
package/package.json
CHANGED
package/src/ModuleLogger.ts
CHANGED
|
@@ -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
|
|
6
|
+
private standardLogger?: StandardLoggerInterface;
|
|
7
7
|
|
|
8
|
-
constructor(module: string,
|
|
8
|
+
constructor(module: string, standardLogger: StandardLoggerInterface) {
|
|
9
9
|
this.module = module;
|
|
10
|
-
this.
|
|
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.
|
|
44
|
+
if (!this.standardLogger?.getLogger()) {
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
|
-
this.
|
|
47
|
+
this.standardLogger.getLogger()?.emit({
|
|
48
48
|
severityNumber,
|
|
49
49
|
severityText: level,
|
|
50
50
|
body: message,
|
package/src/StandardLogger.ts
CHANGED
|
@@ -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
|
|
22
|
-
private serviceName
|
|
19
|
+
private serviceVersion?: string;
|
|
20
|
+
private serviceName?: string;
|
|
23
21
|
|
|
24
|
-
|
|
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
|
|
65
|
+
return new ModuleLogger(moduleName, this);
|
|
64
66
|
}
|
|
65
67
|
}
|