azify-logger 1.0.54-test-1 → 1.0.54-test-3
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/package.json +1 -1
- package/register-http-client-early.js +69 -25
- package/register.js +9 -2
package/package.json
CHANGED
|
@@ -28,13 +28,70 @@ try {
|
|
|
28
28
|
const MAX_EARLY_LOG_QUEUE = 2000
|
|
29
29
|
const earlyLogQueue = []
|
|
30
30
|
|
|
31
|
+
function normalizePathEarly(p) {
|
|
32
|
+
if (!p) return '/'
|
|
33
|
+
const trimmed = String(p).replace(/\/+$/, '')
|
|
34
|
+
return trimmed === '' ? '/' : trimmed
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Ignora esquema (http vs https): undici muitas vezes resolve como https e AZIFY_LOGGER_URL é http em dev. */
|
|
31
38
|
function isLoggerUrl(urlStr) {
|
|
32
|
-
const
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
const loggerUrlRaw = process.env.AZIFY_LOGGER_URL || 'http://localhost:3001/log'
|
|
40
|
+
if (typeof urlStr !== 'string' || !urlStr.trim()) return false
|
|
41
|
+
try {
|
|
42
|
+
const base = new URL(String(loggerUrlRaw).trim())
|
|
43
|
+
const cand = new URL(String(urlStr).trim())
|
|
44
|
+
if (base.hostname.toLowerCase() !== cand.hostname.toLowerCase()) return false
|
|
45
|
+
const portBase = base.port || (base.protocol === 'https:' ? '443' : '80')
|
|
46
|
+
const portCand = cand.port || (cand.protocol === 'https:' ? '443' : '80')
|
|
47
|
+
if (String(portBase) !== String(portCand)) return false
|
|
48
|
+
const lp = normalizePathEarly(base.pathname)
|
|
49
|
+
const tp = normalizePathEarly(cand.pathname)
|
|
50
|
+
return tp === lp || tp.startsWith(lp + '/')
|
|
51
|
+
} catch (_) {
|
|
52
|
+
return false
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** undici.request(url, opts) / request(opts) — muitas chamadas não trazem origin; path pode ser URL absoluta ou só path + hostname. */
|
|
57
|
+
function resolveUrlStrFromUndiciRequestArgs(url, options) {
|
|
58
|
+
const opts = (typeof url === 'object' && url !== null && !(url instanceof URL)) ? url : options
|
|
59
|
+
const urlArg = (typeof url === 'string' || (url && (url.href || url instanceof URL))) ? url : (opts && (opts.url || opts.uri))
|
|
60
|
+
if (typeof urlArg === 'string') return urlArg
|
|
61
|
+
if (urlArg && typeof urlArg.href === 'string') return urlArg.href
|
|
62
|
+
if (urlArg && typeof urlArg.toString === 'function') return urlArg.toString()
|
|
63
|
+
if (opts && typeof opts.origin === 'string' && opts.path != null) {
|
|
64
|
+
return opts.origin + (String(opts.path).startsWith('/') ? '' : '/') + String(opts.path)
|
|
65
|
+
}
|
|
66
|
+
if (opts && typeof opts.path === 'string' && /^https?:\/\//i.test(opts.path)) {
|
|
67
|
+
return opts.path
|
|
68
|
+
}
|
|
69
|
+
if (opts && (opts.hostname || opts.host)) {
|
|
70
|
+
const h = String(opts.hostname || String(opts.host || '').split(':')[0]).trim()
|
|
71
|
+
if (h) {
|
|
72
|
+
const hl = h.toLowerCase()
|
|
73
|
+
const isLocal = hl === 'localhost' || hl === '127.0.0.1' || hl === '::1'
|
|
74
|
+
const proto = (opts.protocol && String(opts.protocol).replace(/:$/, '')) || (isLocal ? 'http' : 'https')
|
|
75
|
+
const pnum = opts.port != null && opts.port !== '' ? Number(opts.port) : NaN
|
|
76
|
+
const port = !Number.isNaN(pnum) && pnum !== 80 && pnum !== 443 ? ':' + pnum : ''
|
|
77
|
+
const p = opts.path != null ? String(opts.path) : '/'
|
|
78
|
+
return proto + '://' + h + port + (p.startsWith('/') ? p : '/' + p)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return 'unknown'
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function resolveUrlStrFromDispatcherOpts(opts) {
|
|
85
|
+
if (!opts || typeof opts !== 'object') return 'unknown'
|
|
86
|
+
const origin = (opts.origin) || ''
|
|
87
|
+
const pathPart = opts.path != null ? opts.path : '/'
|
|
88
|
+
const pathStr = String(pathPart)
|
|
89
|
+
if (/^https?:\/\//i.test(pathStr)) return pathStr
|
|
90
|
+
if (origin) return origin + (pathStr.startsWith('/') ? pathStr : '/' + pathStr)
|
|
91
|
+
if (opts.hostname || opts.host) {
|
|
92
|
+
return resolveUrlStrFromUndiciRequestArgs(null, opts)
|
|
93
|
+
}
|
|
94
|
+
return 'unknown'
|
|
38
95
|
}
|
|
39
96
|
|
|
40
97
|
function send(level, message, meta) {
|
|
@@ -118,12 +175,7 @@ try {
|
|
|
118
175
|
exports.request = function (url, options, callback) {
|
|
119
176
|
const opts = (typeof url === 'object' && url !== null && !(url instanceof URL)) ? url : options
|
|
120
177
|
const method = ((opts && opts.method) || 'GET').toUpperCase()
|
|
121
|
-
|
|
122
|
-
const urlArg = (typeof url === 'string' || (url && (url.href || url instanceof URL))) ? url : (opts && (opts.url || opts.uri))
|
|
123
|
-
if (typeof urlArg === 'string') urlStr = urlArg
|
|
124
|
-
else if (urlArg && typeof urlArg.href === 'string') urlStr = urlArg.href
|
|
125
|
-
else if (urlArg && typeof urlArg.toString === 'function') urlStr = urlArg.toString()
|
|
126
|
-
else if (opts && typeof opts.origin === 'string' && opts.path != null) urlStr = opts.origin + (String(opts.path).startsWith('/') ? '' : '/') + String(opts.path)
|
|
178
|
+
const urlStr = resolveUrlStrFromUndiciRequestArgs(url, options)
|
|
127
179
|
if (process.env.AZIFY_LOGGER_DEBUG === '1') { try { process.stderr.write('[AZIFY-PATCH] undici.request ' + method + ' ' + urlStr.slice(0, 80) + '\n') } catch (_) {} }
|
|
128
180
|
const _ep = process.env.AZIFY_DEBUG_LOG_PATH
|
|
129
181
|
if (_ep) { try { require('fs').appendFileSync(_ep, new Date().toISOString() + ' [AZIFY] WRAPPER exports.request ' + method + ' ' + urlStr.slice(0, 100) + '\n') } catch (_) {} }
|
|
@@ -174,9 +226,7 @@ try {
|
|
|
174
226
|
const origDisp = proto.request
|
|
175
227
|
proto.request = function (opts, callback) {
|
|
176
228
|
const methodStr = String((opts && opts.method) || 'GET').toUpperCase()
|
|
177
|
-
const
|
|
178
|
-
const path = (opts && opts.path) != null ? opts.path : '/'
|
|
179
|
-
const urlStr = origin ? (origin + (path.startsWith('/') ? path : '/' + path)) : 'unknown'
|
|
229
|
+
const urlStr = resolveUrlStrFromDispatcherOpts(opts)
|
|
180
230
|
httpLog('WRAPPER Dispatcher.request ' + methodStr + ' ' + urlStr.slice(0, 80))
|
|
181
231
|
const ctx = getRequestContext() || getLastJobContext()
|
|
182
232
|
const otelCtx = getOtelTraceContext()
|
|
@@ -255,9 +305,7 @@ try {
|
|
|
255
305
|
if (typeof origReq !== 'function') return d
|
|
256
306
|
d.request = function (opts, callback) {
|
|
257
307
|
const methodStr = String((opts && opts.method) || 'GET').toUpperCase()
|
|
258
|
-
const
|
|
259
|
-
const pathPart = (opts && opts.path) != null ? opts.path : '/'
|
|
260
|
-
const urlStr = origin ? (origin + (pathPart.startsWith('/') ? pathPart : '/' + pathPart)) : 'unknown'
|
|
308
|
+
const urlStr = resolveUrlStrFromDispatcherOpts(opts)
|
|
261
309
|
httpLog('WRAPPER getGlobalDispatcher().request ' + methodStr + ' ' + urlStr.slice(0, 80))
|
|
262
310
|
const ctx = getRequestContext ? getRequestContext() : (getLastJobContext ? getLastJobContext() : null)
|
|
263
311
|
const otelCtx = getOtelTraceContext()
|
|
@@ -333,9 +381,7 @@ try {
|
|
|
333
381
|
const HTTP_CLIENT_MODE = deps ? deps.HTTP_CLIENT_MODE : 'all'
|
|
334
382
|
d.request = function (opts, callback) {
|
|
335
383
|
const methodStr = String((opts && opts.method) || 'GET').toUpperCase()
|
|
336
|
-
const
|
|
337
|
-
const pathPart = (opts && opts.path) != null ? opts.path : '/'
|
|
338
|
-
const urlStr = origin ? (origin + (pathPart.startsWith('/') ? pathPart : '/' + pathPart)) : 'unknown'
|
|
384
|
+
const urlStr = resolveUrlStrFromDispatcherOpts(opts)
|
|
339
385
|
httpLog('WRAPPER globalThis.dispatcher.request ' + methodStr + ' ' + urlStr.slice(0, 80))
|
|
340
386
|
const _dp = process.env.AZIFY_DEBUG_LOG_PATH
|
|
341
387
|
if (_dp) { try { require('fs').appendFileSync(_dp, new Date().toISOString() + ' [AZIFY] WRAPPER globalDispatcher.request ' + methodStr + ' ' + urlStr.slice(0, 100) + '\n') } catch (_) {} }
|
|
@@ -608,14 +654,12 @@ try {
|
|
|
608
654
|
const RequestHandler = mod.exports.RequestHandler
|
|
609
655
|
mod.exports = function wrappedApiRequest(opts, callback) {
|
|
610
656
|
const methodStr = String((opts && opts.method) || 'GET').toUpperCase()
|
|
611
|
-
const
|
|
657
|
+
const urlStr = resolveUrlStrFromDispatcherOpts(opts)
|
|
658
|
+
const urlPart = urlStr !== 'unknown' ? urlStr.slice(0, 80) : ((opts && opts.origin) ? String(opts.origin).slice(0, 80) : (opts && opts.path) || '')
|
|
612
659
|
if (HTTP_DEBUG) try { process.stderr.write('[AZIFY-PATCH] api-request ' + methodStr + ' ' + urlPart + '\n') } catch (_) {}
|
|
613
660
|
if (HTTP_VERBOSE || HTTP_DEBUG) {
|
|
614
661
|
try { process.stderr.write('[AZIFY] HTTP wrapper api-request ' + methodStr + ' ' + urlPart + '\n') } catch (_) {}
|
|
615
662
|
}
|
|
616
|
-
const origin = (opts && opts.origin) || ''
|
|
617
|
-
const pathPart = (opts && opts.path) != null ? opts.path : '/'
|
|
618
|
-
const urlStr = origin ? (origin + (pathPart.startsWith('/') ? pathPart : '/' + pathPart)) : 'unknown'
|
|
619
663
|
httpLog('WRAPPER api-request ' + methodStr + ' ' + urlStr.slice(0, 80))
|
|
620
664
|
const ctx = getRequestContext() || getLastJobContext()
|
|
621
665
|
const otelCtx = getOtelTraceContext()
|
package/register.js
CHANGED
|
@@ -377,9 +377,16 @@ try {
|
|
|
377
377
|
|
|
378
378
|
try {
|
|
379
379
|
const target = new URL(candidate, normalizedLoggerOrigin)
|
|
380
|
-
|
|
380
|
+
if (loggerEndpoint.hostname.toLowerCase() !== target.hostname.toLowerCase()) {
|
|
381
|
+
return false
|
|
382
|
+
}
|
|
383
|
+
const portLogger = loggerEndpoint.port || (loggerEndpoint.protocol === 'https:' ? '443' : '80')
|
|
384
|
+
const portTarget = target.port || (target.protocol === 'https:' ? '443' : '80')
|
|
385
|
+
if (String(portLogger) !== String(portTarget)) {
|
|
386
|
+
return false
|
|
387
|
+
}
|
|
381
388
|
const targetPath = normalizePath(target.pathname)
|
|
382
|
-
return
|
|
389
|
+
return targetPath === normalizedLoggerPath || targetPath.startsWith(normalizedLoggerPath + '/')
|
|
383
390
|
} catch (_) {
|
|
384
391
|
if (typeof candidate === 'string') {
|
|
385
392
|
const relativePath = normalizePath(candidate)
|