@arnob-b/observability 1.0.0 → 1.0.1
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/README.md +109 -0
- package/package.json +3 -5
- package/src/observability.js +1 -1
- package/observability-1.0.0.tgz +0 -0
package/README.md
CHANGED
|
@@ -1 +1,110 @@
|
|
|
1
1
|
# Observability
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
# usage
|
|
5
|
+
## install dependencies
|
|
6
|
+
```bash
|
|
7
|
+
npm install @arnob-b/observability
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## initializing observability
|
|
11
|
+
```javascript
|
|
12
|
+
const { Observability } = require("@arnob-b/observability");
|
|
13
|
+
Observability.initialize(OBSERVABILITY_CONFIG);
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Sample configuration
|
|
17
|
+
```javascript
|
|
18
|
+
const path = require('path');
|
|
19
|
+
const fs = require('fs');
|
|
20
|
+
const LOG_ROTATION_SIZE = '1K'
|
|
21
|
+
const LOG_WATCHER_FILE_SIZE = '1K'
|
|
22
|
+
|
|
23
|
+
const LOG_DIR = "server_logs";
|
|
24
|
+
if (!fs.existsSync(LOG_DIR)){
|
|
25
|
+
fs.mkdirSync(LOG_DIR);
|
|
26
|
+
}
|
|
27
|
+
const LOG_PATH=path.join(LOG_DIR,'main.%DATE%.log');
|
|
28
|
+
const WATCH_FILE_PATH =path.join(LOG_DIR,'watcher.log');
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
const OBSERVABILITY_CONFIG = {
|
|
32
|
+
LOG:{
|
|
33
|
+
LEVEL: 'debug',
|
|
34
|
+
TRANSPORTS: {
|
|
35
|
+
CONSOLE: {
|
|
36
|
+
NAME: "console-transport",
|
|
37
|
+
ENABLED: true,
|
|
38
|
+
},
|
|
39
|
+
FILE: {
|
|
40
|
+
NAME: "file-rotation-transport",
|
|
41
|
+
ENABLED: true,
|
|
42
|
+
PATH : LOG_PATH,
|
|
43
|
+
DIR : LOG_DIR,
|
|
44
|
+
SIZE: LOG_ROTATION_SIZE,
|
|
45
|
+
ZIP_ARCHIVE: true,
|
|
46
|
+
},
|
|
47
|
+
STREAM: {
|
|
48
|
+
NAME: "stream-transport",
|
|
49
|
+
ENABLED: false,
|
|
50
|
+
STREAM_URL: 'http://localhost:3000/logs',
|
|
51
|
+
HTTP_METHOD: 'POST',
|
|
52
|
+
},
|
|
53
|
+
WATCHER: {
|
|
54
|
+
NAME: "watcher-transport",
|
|
55
|
+
ENABLED: true,
|
|
56
|
+
PATH : WATCH_FILE_PATH,
|
|
57
|
+
SIZE: LOG_WATCHER_FILE_SIZE,
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
OTEL: {
|
|
62
|
+
SERVICE_NAME: 'electron-logger-service',
|
|
63
|
+
SERVICE_VERSION: 'http://localhost:4317',
|
|
64
|
+
INSTRUMENTS: {
|
|
65
|
+
HTTP: {
|
|
66
|
+
ENABLED: false,
|
|
67
|
+
},
|
|
68
|
+
UNDICI: {
|
|
69
|
+
ENABLED: true,
|
|
70
|
+
},
|
|
71
|
+
EXPRESS: {
|
|
72
|
+
ENABLED: false,
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
}
|
|
77
|
+
module.exports = OBSERVABILITY_CONFIG;
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### predefined logger object from factory
|
|
81
|
+
```javascript
|
|
82
|
+
const electronLogger = Observability.getLogger("electron-application");
|
|
83
|
+
|
|
84
|
+
module.exports = electronLogger;
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
there are two products from logger factory, one is for electron-application another is for backend node environment.
|
|
88
|
+
|
|
89
|
+
#### using logger in electron application
|
|
90
|
+
```javascript
|
|
91
|
+
const log = require('./utils/logger');
|
|
92
|
+
log.info("This is an info log from electron application");
|
|
93
|
+
log.render.info("This is a render log from electron application");
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
### adding hooks for events emmited by tranports
|
|
98
|
+
|
|
99
|
+
```javascript
|
|
100
|
+
const logger = Observability.getLogger("electron-application");
|
|
101
|
+
attachHooksOnTransport("file-rotation-transport", {
|
|
102
|
+
'archive': (oldFilename, newFilename) => {
|
|
103
|
+
logger.info(`Log file rotated: ${oldFilename} -> ${newFilename}`);
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
# architechture
|
|
110
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arnob-b/observability",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "observability for nodejs application using winston and opentelemetry",
|
|
5
5
|
"keywords": ["observability", "nodejs", "winston", "opentelemetry", "electron", "desktop application"],
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,11 +14,9 @@
|
|
|
14
14
|
"@opentelemetry/api": "^1.9.0",
|
|
15
15
|
"@opentelemetry/instrumentation-undici": "^0.21.0",
|
|
16
16
|
"@opentelemetry/sdk-node": "^0.212.0",
|
|
17
|
+
"@opentelemetry/instrumentation-express": "^0.59.0",
|
|
18
|
+
"@opentelemetry/instrumentation-http": "^0.212.0",
|
|
17
19
|
"winston": "^3.19.0",
|
|
18
20
|
"winston-daily-rotate-file": "^5.0.0"
|
|
19
|
-
},
|
|
20
|
-
"devDependencies": {
|
|
21
|
-
"@opentelemetry/instrumentation-express": "^0.59.0",
|
|
22
|
-
"@opentelemetry/instrumentation-http": "^0.212.0"
|
|
23
21
|
}
|
|
24
22
|
}
|
package/src/observability.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const {initOtel} = require("./otel");
|
|
2
2
|
const {initLogger} = require("./logger");
|
|
3
3
|
const { LoggerFactory } = require("./wrappers");
|
|
4
|
-
class Observability {
|
|
4
|
+
class Observability {
|
|
5
5
|
constructor() {
|
|
6
6
|
if (Observability.instance) {
|
|
7
7
|
console.warn("Observability instance already exists. Returning existing instance.");
|
package/observability-1.0.0.tgz
DELETED
|
Binary file
|