azify-logger 1.0.26 → 1.0.29
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 +26 -5
- package/index.js +40 -17
- package/middleware-express.js +267 -366
- package/middleware-fastify.js +348 -0
- package/middleware-restify.js +147 -303
- package/package.json +31 -30
- package/queue/fileQueue.js +100 -0
- package/queue/redisQueue.js +179 -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 +439 -0
- package/server.js +169 -74
- package/store.js +10 -4
- package/streams/bunyan.d.ts +26 -0
- package/streams/bunyan.js +39 -8
- package/streams/httpQueue.js +342 -0
- package/streams/pino.d.ts +38 -0
- package/streams/pino.js +44 -7
package/README.md
CHANGED
|
@@ -49,7 +49,21 @@ APP_NAME=nome-app
|
|
|
49
49
|
require('azify-logger')
|
|
50
50
|
const express = require('express')
|
|
51
51
|
const app = express()
|
|
52
|
-
|
|
52
|
+
const azifyMiddleware = require('azify-logger/middleware-express')
|
|
53
|
+
app.use(azifyMiddleware())
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Para aplicações Fastify:
|
|
57
|
+
|
|
58
|
+
```javascript
|
|
59
|
+
const fastify = require('fastify')()
|
|
60
|
+
const azifyPlugin = require('azify-logger/middleware-fastify')
|
|
61
|
+
|
|
62
|
+
await fastify.register(azifyPlugin, {
|
|
63
|
+
serviceName: 'minha-app'
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
await fastify.listen({ port: 3000 })
|
|
53
67
|
```
|
|
54
68
|
|
|
55
69
|
## ⚙️ Variáveis de Ambiente
|
|
@@ -146,7 +160,14 @@ cp env/app.env.example env/app.env
|
|
|
146
160
|
cp env/grafana.env.example env/grafana.env
|
|
147
161
|
```
|
|
148
162
|
|
|
149
|
-
|
|
163
|
+
#### ✅ Importante: configure seu e-mail para ser promovido a Admin
|
|
164
|
+
1. Abra `env/grafana.env`.
|
|
165
|
+
2. Atualize `ADMIN_GLOBAL_EMAIL` com **seu e-mail corporativo** (ex.: `ADMIN_GLOBAL_EMAIL=seu.email@exemplo.com`).
|
|
166
|
+
3. Abra `env/app.env`.
|
|
167
|
+
4. Garanta que `ADMIN_EMAILS` contenha o mesmo e-mail (ex.: `ADMIN_EMAILS=seu.email@exemplo.com`).
|
|
168
|
+
5. Salve os arquivos e reinicie os containers (`./start-docker.sh`).
|
|
169
|
+
|
|
170
|
+
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
171
|
|
|
151
172
|
### Testar
|
|
152
173
|
|
|
@@ -185,11 +206,11 @@ O deploy é feito automaticamente via GitHub Actions.
|
|
|
185
206
|
|
|
186
207
|
**Comandos seguros** (preservam dados):
|
|
187
208
|
```bash
|
|
188
|
-
docker
|
|
189
|
-
docker
|
|
209
|
+
docker compose stop
|
|
210
|
+
docker compose restart
|
|
190
211
|
```
|
|
191
212
|
|
|
192
213
|
**Comandos destrutivos** (APAGAM logs):
|
|
193
214
|
```bash
|
|
194
|
-
docker
|
|
215
|
+
docker compose down -v # ⚠️ APAGA VOLUMES!
|
|
195
216
|
```
|
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)
|
|
@@ -322,5 +341,9 @@ module.exports.streams = {
|
|
|
322
341
|
}
|
|
323
342
|
module.exports.middleware = {
|
|
324
343
|
restify: require('./middleware-restify'),
|
|
325
|
-
express: require('./middleware-express')
|
|
326
|
-
|
|
344
|
+
express: require('./middleware-express'),
|
|
345
|
+
fastify: require('./middleware-fastify')
|
|
346
|
+
}
|
|
347
|
+
module.exports.startLoggerWorker = require('./queue/workerManager').startLoggerWorker
|
|
348
|
+
module.exports.stopLoggerWorker = require('./queue/workerManager').stopLoggerWorker
|
|
349
|
+
module.exports.ensureLoggerWorker = require('./queue/workerManager').ensureWorker
|