@devopsplaybook.io/otel-utils 1.0.1-beta4 → 1.0.1-beta6
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 +3 -2
- package/dist/index.js +3 -4
- package/dist/src/ModuleLogger.d.ts +10 -0
- package/dist/src/ModuleLogger.js +50 -0
- package/dist/src/StandardLogger.d.ts +9 -0
- package/dist/src/StandardLogger.js +77 -0
- package/dist/src/StandardMeter.d.ts +11 -6
- package/dist/src/StandardMeter.js +57 -64
- package/dist/src/StandardTracer.d.ts +9 -5
- package/dist/src/StandardTracer.js +49 -58
- package/dist/src/models/{ConfigInterfaceOTel.d.ts → ConfigOTelInterface.d.ts} +2 -2
- package/index.ts +3 -5
- package/package.json +1 -1
- package/src/ModuleLogger.ts +54 -0
- package/src/StandardLogger.ts +65 -0
- package/src/StandardMeter.ts +68 -70
- package/src/StandardTracer.ts +64 -72
- package/src/models/{ConfigInterfaceOTel.ts → ConfigOTelInterface.ts} +2 -2
- package/dist/src/Logger.d.ts +0 -12
- package/dist/src/Logger.js +0 -131
- package/dist/src/PromisePool.d.ts +0 -9
- package/dist/src/PromisePool.js +0 -54
- package/dist/src/SqlDbUtils.d.ts +0 -7
- package/dist/src/SqlDbUtils.js +0 -132
- package/dist/src/SqlDbUtilsNoTelemetry.d.ts +0 -2
- package/dist/src/SqlDbUtilsNoTelemetry.js +0 -38
- package/dist/src/SystemCommand.d.ts +0 -1
- package/dist/src/SystemCommand.js +0 -50
- package/dist/src/Timeout.d.ts +0 -1
- package/dist/src/Timeout.js +0 -10
- package/dist/src/models/ConfigInterface.d.ts +0 -11
- package/dist/src/models/ConfigInterfaceOTel.js +0 -2
- package/src/Logger.ts +0 -120
- /package/dist/src/models/{ConfigInterface.js → ConfigOTelInterface.js} +0 -0
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SqlDbUtilsNoTelemetryExecSQL = SqlDbUtilsNoTelemetryExecSQL;
|
|
4
|
-
exports.SqlDbUtilsNoTelemetryQuerySQL = SqlDbUtilsNoTelemetryQuerySQL;
|
|
5
|
-
const Logger_1 = require("./Logger");
|
|
6
|
-
const SqlDbUtils_1 = require("./SqlDbUtils");
|
|
7
|
-
const logger = new Logger_1.Logger("SqlDbUtilsNoTelemetry");
|
|
8
|
-
function SqlDbUtilsNoTelemetryExecSQL(sql, params = []) {
|
|
9
|
-
return new Promise((resolve, reject) => {
|
|
10
|
-
(0, SqlDbUtils_1.SqlDbUtilsInitGetDatabase)().run(sql, params, (error) => {
|
|
11
|
-
if (error) {
|
|
12
|
-
reject(error);
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
resolve();
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
function SqlDbUtilsNoTelemetryQuerySQL(sql, params = [], debug = false
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
-
) {
|
|
23
|
-
if (debug) {
|
|
24
|
-
console.log(sql);
|
|
25
|
-
}
|
|
26
|
-
return new Promise((resolve, reject) => {
|
|
27
|
-
(0, SqlDbUtils_1.SqlDbUtilsInitGetDatabase)().all(sql, params, (error, rows) => {
|
|
28
|
-
if (error) {
|
|
29
|
-
console.log(error);
|
|
30
|
-
logger.error(`SQL ERROR: ${sql}`);
|
|
31
|
-
reject(error);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
resolve(rows);
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function SystemCommandExecute(command: string, options?: {}): Promise<string>;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.SystemCommandExecute = SystemCommandExecute;
|
|
37
|
-
const childProcess = __importStar(require("child_process"));
|
|
38
|
-
function SystemCommandExecute(command, options = {}) {
|
|
39
|
-
const exec = childProcess.exec;
|
|
40
|
-
return new Promise((resolve, reject) => {
|
|
41
|
-
exec(command, options, (error, stdout) => {
|
|
42
|
-
if (error) {
|
|
43
|
-
reject(error);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
resolve(stdout);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
}
|
package/dist/src/Timeout.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function TimeoutWait(duration: number): Promise<void>;
|
package/dist/src/Timeout.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export interface ConfigInterface {
|
|
2
|
-
SERVICE_ID: string;
|
|
3
|
-
VERSION: number;
|
|
4
|
-
OPENTELEMETRY_COLLECTOR_HTTP_TRACES: string;
|
|
5
|
-
OPENTELEMETRY_COLLECTOR_HTTP_METRICS: string;
|
|
6
|
-
OPENTELEMETRY_COLLECTOR_HTTP_LOGS: string;
|
|
7
|
-
OPENTELEMETRY_COLLECTOR_EXPORT_LOGS_INTERVAL_SECONDS: number;
|
|
8
|
-
OPENTELEMETRY_COLLECTOR_EXPORT_METRICS_INTERVAL_SECONDS: number;
|
|
9
|
-
OPENTELEMETRY_COLLECTOR_AWS: boolean;
|
|
10
|
-
OPENTELEMETRY_COLLECT_AUTHORIZATION_HEADER: string;
|
|
11
|
-
}
|
package/src/Logger.ts
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import type { Logger as OTelLogger } from "@opentelemetry/api-logs";
|
|
2
|
-
import { SeverityNumber } from "@opentelemetry/api-logs";
|
|
3
|
-
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
|
|
4
|
-
import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
5
|
-
import {
|
|
6
|
-
BatchLogRecordProcessor,
|
|
7
|
-
LoggerProvider,
|
|
8
|
-
} from "@opentelemetry/sdk-logs";
|
|
9
|
-
import { Span } from "@opentelemetry/sdk-trace-base";
|
|
10
|
-
import {
|
|
11
|
-
ATTR_NETWORK_LOCAL_ADDRESS,
|
|
12
|
-
ATTR_SERVICE_NAME,
|
|
13
|
-
ATTR_SERVICE_VERSION,
|
|
14
|
-
} from "@opentelemetry/semantic-conventions";
|
|
15
|
-
import * as os from "os";
|
|
16
|
-
import { ConfigInterfaceOTel } from "./models/ConfigInterfaceOTel";
|
|
17
|
-
import { StandardTracerStartSpan } from "./StandardTracer";
|
|
18
|
-
|
|
19
|
-
let loggerOTel: OTelLogger;
|
|
20
|
-
|
|
21
|
-
export function LoggerInit(context: Span, config: ConfigInterfaceOTel) {
|
|
22
|
-
const span = StandardTracerStartSpan("LoggerInit", context);
|
|
23
|
-
|
|
24
|
-
if (config.OPENTELEMETRY_COLLECTOR_HTTP_LOGS) {
|
|
25
|
-
const exporterHeaders: Record<string, string> = {};
|
|
26
|
-
if (config.OPENTELEMETRY_COLLECT_AUTHORIZATION_HEADER) {
|
|
27
|
-
exporterHeaders[
|
|
28
|
-
"Authorization"
|
|
29
|
-
] = `Bearer ${config.OPENTELEMETRY_COLLECT_AUTHORIZATION_HEADER}`;
|
|
30
|
-
}
|
|
31
|
-
const exporter = new OTLPLogExporter({
|
|
32
|
-
url: config.OPENTELEMETRY_COLLECTOR_HTTP_LOGS,
|
|
33
|
-
headers: exporterHeaders,
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
const loggerProvider = new LoggerProvider({
|
|
37
|
-
processors: [
|
|
38
|
-
new BatchLogRecordProcessor(exporter, {
|
|
39
|
-
maxQueueSize: 100,
|
|
40
|
-
scheduledDelayMillis:
|
|
41
|
-
config.OPENTELEMETRY_COLLECTOR_EXPORT_LOGS_INTERVAL_SECONDS * 1000,
|
|
42
|
-
}),
|
|
43
|
-
],
|
|
44
|
-
resource: resourceFromAttributes({
|
|
45
|
-
[ATTR_SERVICE_NAME]: `${config.SERVICE_ID}`,
|
|
46
|
-
[ATTR_SERVICE_VERSION]: `${config.VERSION}`,
|
|
47
|
-
[ATTR_NETWORK_LOCAL_ADDRESS]: os.hostname(),
|
|
48
|
-
}),
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
loggerOTel = loggerProvider.getLogger(
|
|
52
|
-
`${config.SERVICE_ID}:${config.VERSION}`
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
span.end();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const DEV_MODE = (() => {
|
|
59
|
-
if (process.env.NODE_ENV === "dev") {
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
return false;
|
|
63
|
-
})();
|
|
64
|
-
|
|
65
|
-
export class Logger {
|
|
66
|
-
private module: string;
|
|
67
|
-
|
|
68
|
-
constructor(module: string) {
|
|
69
|
-
this.module = `${module}`;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
73
|
-
public debug(message: Error | string | any): void {
|
|
74
|
-
if (DEV_MODE) {
|
|
75
|
-
this.display("debug", message, SeverityNumber.DEBUG);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
79
|
-
public info(message: Error | string | any): void {
|
|
80
|
-
this.display("info", message, SeverityNumber.WARN);
|
|
81
|
-
}
|
|
82
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
83
|
-
public warn(message: Error | string | any): void {
|
|
84
|
-
this.display("warn", message, SeverityNumber.WARN);
|
|
85
|
-
}
|
|
86
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
87
|
-
public error(message: Error | string | any): void {
|
|
88
|
-
this.display("error", message, SeverityNumber.ERROR);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
private display(
|
|
92
|
-
level: string,
|
|
93
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
94
|
-
message: any,
|
|
95
|
-
severityNumber = SeverityNumber.INFO
|
|
96
|
-
): void {
|
|
97
|
-
if (typeof message === "string") {
|
|
98
|
-
// eslint:disable-next-line:no-console
|
|
99
|
-
console.log(`[${level}] [${this.module}] ${message}`);
|
|
100
|
-
} else if (message instanceof Error) {
|
|
101
|
-
// eslint:disable-next-line:no-console
|
|
102
|
-
console.log(`${level} [${this.module}] ${message}`);
|
|
103
|
-
// eslint:disable-next-line:no-console
|
|
104
|
-
console.log((message as Error).stack);
|
|
105
|
-
} else if (typeof message === "object") {
|
|
106
|
-
// eslint:disable-next-line:no-console
|
|
107
|
-
console.log(`${level} [${this.module}] ${JSON.stringify(message)}`);
|
|
108
|
-
}
|
|
109
|
-
if (loggerOTel) {
|
|
110
|
-
{
|
|
111
|
-
loggerOTel.emit({
|
|
112
|
-
severityNumber,
|
|
113
|
-
severityText: level,
|
|
114
|
-
body: message,
|
|
115
|
-
attributes: { "log.type": "custom" },
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
File without changes
|