azify-logger 1.0.25 → 1.0.28
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 +8 -1
- package/index.js +38 -16
- package/middleware-express.js +218 -367
- package/middleware-restify.js +135 -306
- package/package.json +29 -17
- package/queue/fileQueue.js +100 -0
- package/queue/redisQueue.js +181 -0
- package/queue/workerManager.js +111 -0
- package/register-otel.js +63 -13
- package/register.js +364 -99
- package/sampling.js +79 -0
- package/scripts/redis-worker.js +467 -0
- package/server.js +168 -70
- package/streams/bunyan.d.ts +26 -0
- package/streams/bunyan.js +39 -8
- package/streams/httpQueue.js +357 -0
- package/streams/pino.d.ts +38 -0
- package/streams/pino.js +44 -7
package/README.md
CHANGED
|
@@ -146,7 +146,14 @@ cp env/app.env.example env/app.env
|
|
|
146
146
|
cp env/grafana.env.example env/grafana.env
|
|
147
147
|
```
|
|
148
148
|
|
|
149
|
-
|
|
149
|
+
#### ✅ Importante: configure seu e-mail para ser promovido a Admin
|
|
150
|
+
1. Abra `env/grafana.env`.
|
|
151
|
+
2. Atualize `ADMIN_GLOBAL_EMAIL` com **seu e-mail corporativo** (ex.: `ADMIN_GLOBAL_EMAIL=seu.email@exemplo.com`).
|
|
152
|
+
3. Abra `env/app.env`.
|
|
153
|
+
4. Garanta que `ADMIN_EMAILS` contenha o mesmo e-mail (ex.: `ADMIN_EMAILS=seu.email@exemplo.com`).
|
|
154
|
+
5. Salve os arquivos e reinicie os containers (`./start-docker.sh`).
|
|
155
|
+
|
|
156
|
+
Assim, ao fazer login com Azure AD, você é promovido automaticamente a Server Admin e já enxerga o Explore e os dashboards da sua aplicação.
|
|
150
157
|
|
|
151
158
|
### Testar
|
|
152
159
|
|
package/index.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
const
|
|
1
|
+
const { createHttpLoggerTransport } = require('./streams/httpQueue')
|
|
2
|
+
const nativeConsole = {
|
|
3
|
+
log: console.log.bind(console),
|
|
4
|
+
error: console.error.bind(console),
|
|
5
|
+
warn: console.warn.bind(console),
|
|
6
|
+
info: console.info.bind(console),
|
|
7
|
+
debug: console.debug.bind(console)
|
|
8
|
+
}
|
|
2
9
|
|
|
3
10
|
let context, propagation, trace, W3CTraceContextPropagator
|
|
4
11
|
try {
|
|
@@ -34,13 +41,23 @@ class AzifyLogger {
|
|
|
34
41
|
* @param {string} [options.environment] - Environment name (defaults to NODE_ENV or 'development')
|
|
35
42
|
*/
|
|
36
43
|
constructor(options = {}) {
|
|
44
|
+
const fallbackLoggerUrl = process.env.AZIFY_LOGGER_URL || 'http://localhost:3001/log'
|
|
45
|
+
const fallbackEnvironment = process.env.NODE_ENV || 'development'
|
|
46
|
+
|
|
37
47
|
this.options = {
|
|
38
|
-
serviceName: options.serviceName || '
|
|
39
|
-
loggerUrl: options.loggerUrl ||
|
|
40
|
-
environment: options.environment ||
|
|
48
|
+
serviceName: options.serviceName || process.env.APP_NAME || 'application',
|
|
49
|
+
loggerUrl: options.loggerUrl || fallbackLoggerUrl,
|
|
50
|
+
environment: options.environment || fallbackEnvironment,
|
|
51
|
+
awaitDelivery: options.awaitDelivery !== undefined
|
|
52
|
+
? Boolean(options.awaitDelivery)
|
|
53
|
+
: process.env.AZIFY_LOGGER_AWAIT_DELIVERY === 'true',
|
|
41
54
|
...options
|
|
42
55
|
}
|
|
43
56
|
|
|
57
|
+
this.transport = createHttpLoggerTransport(this.options.loggerUrl, {
|
|
58
|
+
awaitDelivery: this.options.awaitDelivery
|
|
59
|
+
})
|
|
60
|
+
|
|
44
61
|
this.propagator = new W3CTraceContextPropagator()
|
|
45
62
|
propagation.setGlobalPropagator(this.propagator)
|
|
46
63
|
}
|
|
@@ -84,15 +101,17 @@ class AzifyLogger {
|
|
|
84
101
|
carrier[key] = value
|
|
85
102
|
}
|
|
86
103
|
})
|
|
87
|
-
} catch (_) {}
|
|
104
|
+
} catch (_) { }
|
|
88
105
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
106
|
+
if (this.transport && typeof this.transport.enqueue === 'function') {
|
|
107
|
+
try {
|
|
108
|
+
this.transport.enqueue(logData, headers)
|
|
109
|
+
if (this.options.awaitDelivery && typeof this.transport.flush === 'function') {
|
|
110
|
+
this.transport.flush().catch(() => { })
|
|
111
|
+
}
|
|
112
|
+
} catch (err) { }
|
|
113
|
+
}
|
|
114
|
+
} catch (error) { }
|
|
96
115
|
}
|
|
97
116
|
|
|
98
117
|
/**
|
|
@@ -170,9 +189,9 @@ function createAzifyLogger(options = {}) {
|
|
|
170
189
|
*/
|
|
171
190
|
function createAzifyLoggerFromEnv() {
|
|
172
191
|
const logger = createAzifyLogger({
|
|
173
|
-
serviceName: process.env.APP_NAME
|
|
174
|
-
loggerUrl: process.env.AZIFY_LOGGER_URL
|
|
175
|
-
environment: process.env.NODE_ENV
|
|
192
|
+
serviceName: process.env.APP_NAME,
|
|
193
|
+
loggerUrl: process.env.AZIFY_LOGGER_URL,
|
|
194
|
+
environment: process.env.NODE_ENV
|
|
176
195
|
})
|
|
177
196
|
|
|
178
197
|
interceptConsole(logger)
|
|
@@ -323,4 +342,7 @@ module.exports.streams = {
|
|
|
323
342
|
module.exports.middleware = {
|
|
324
343
|
restify: require('./middleware-restify'),
|
|
325
344
|
express: require('./middleware-express')
|
|
326
|
-
}
|
|
345
|
+
}
|
|
346
|
+
module.exports.startLoggerWorker = require('./queue/workerManager').startLoggerWorker
|
|
347
|
+
module.exports.stopLoggerWorker = require('./queue/workerManager').stopLoggerWorker
|
|
348
|
+
module.exports.ensureLoggerWorker = require('./queue/workerManager').ensureWorker
|