azify-logger 1.0.54-test-1 → 1.0.54-test-2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "azify-logger",
3
- "version": "1.0.54-test-1",
3
+ "version": "1.0.54-test-2",
4
4
  "description": "Azify Logger Client - Centralized logging for OpenSearch",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -37,6 +37,45 @@ try {
37
37
  return a === b || a.startsWith(b + '/')
38
38
  }
39
39
 
40
+ /** undici.request(url, opts) / request(opts) — muitas chamadas não trazem origin; path pode ser URL absoluta ou só path + hostname. */
41
+ function resolveUrlStrFromUndiciRequestArgs(url, options) {
42
+ const opts = (typeof url === 'object' && url !== null && !(url instanceof URL)) ? url : options
43
+ const urlArg = (typeof url === 'string' || (url && (url.href || url instanceof URL))) ? url : (opts && (opts.url || opts.uri))
44
+ if (typeof urlArg === 'string') return urlArg
45
+ if (urlArg && typeof urlArg.href === 'string') return urlArg.href
46
+ if (urlArg && typeof urlArg.toString === 'function') return urlArg.toString()
47
+ if (opts && typeof opts.origin === 'string' && opts.path != null) {
48
+ return opts.origin + (String(opts.path).startsWith('/') ? '' : '/') + String(opts.path)
49
+ }
50
+ if (opts && typeof opts.path === 'string' && /^https?:\/\//i.test(opts.path)) {
51
+ return opts.path
52
+ }
53
+ if (opts && (opts.hostname || opts.host)) {
54
+ const h = String(opts.hostname || String(opts.host || '').split(':')[0]).trim()
55
+ if (h) {
56
+ const proto = (opts.protocol && String(opts.protocol).replace(/:$/, '')) || 'https'
57
+ const pnum = opts.port != null && opts.port !== '' ? Number(opts.port) : NaN
58
+ const port = !Number.isNaN(pnum) && pnum !== 80 && pnum !== 443 ? ':' + pnum : ''
59
+ const p = opts.path != null ? String(opts.path) : '/'
60
+ return proto + '://' + h + port + (p.startsWith('/') ? p : '/' + p)
61
+ }
62
+ }
63
+ return 'unknown'
64
+ }
65
+
66
+ function resolveUrlStrFromDispatcherOpts(opts) {
67
+ if (!opts || typeof opts !== 'object') return 'unknown'
68
+ const origin = (opts.origin) || ''
69
+ const pathPart = opts.path != null ? opts.path : '/'
70
+ const pathStr = String(pathPart)
71
+ if (/^https?:\/\//i.test(pathStr)) return pathStr
72
+ if (origin) return origin + (pathStr.startsWith('/') ? pathStr : '/' + pathStr)
73
+ if (opts.hostname || opts.host) {
74
+ return resolveUrlStrFromUndiciRequestArgs(null, opts)
75
+ }
76
+ return 'unknown'
77
+ }
78
+
40
79
  function send(level, message, meta) {
41
80
  try {
42
81
  const msgStr = String(message)
@@ -118,12 +157,7 @@ try {
118
157
  exports.request = function (url, options, callback) {
119
158
  const opts = (typeof url === 'object' && url !== null && !(url instanceof URL)) ? url : options
120
159
  const method = ((opts && opts.method) || 'GET').toUpperCase()
121
- let urlStr = 'unknown'
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)
160
+ const urlStr = resolveUrlStrFromUndiciRequestArgs(url, options)
127
161
  if (process.env.AZIFY_LOGGER_DEBUG === '1') { try { process.stderr.write('[AZIFY-PATCH] undici.request ' + method + ' ' + urlStr.slice(0, 80) + '\n') } catch (_) {} }
128
162
  const _ep = process.env.AZIFY_DEBUG_LOG_PATH
129
163
  if (_ep) { try { require('fs').appendFileSync(_ep, new Date().toISOString() + ' [AZIFY] WRAPPER exports.request ' + method + ' ' + urlStr.slice(0, 100) + '\n') } catch (_) {} }
@@ -174,9 +208,7 @@ try {
174
208
  const origDisp = proto.request
175
209
  proto.request = function (opts, callback) {
176
210
  const methodStr = String((opts && opts.method) || 'GET').toUpperCase()
177
- const origin = (opts && opts.origin) || ''
178
- const path = (opts && opts.path) != null ? opts.path : '/'
179
- const urlStr = origin ? (origin + (path.startsWith('/') ? path : '/' + path)) : 'unknown'
211
+ const urlStr = resolveUrlStrFromDispatcherOpts(opts)
180
212
  httpLog('WRAPPER Dispatcher.request ' + methodStr + ' ' + urlStr.slice(0, 80))
181
213
  const ctx = getRequestContext() || getLastJobContext()
182
214
  const otelCtx = getOtelTraceContext()
@@ -255,9 +287,7 @@ try {
255
287
  if (typeof origReq !== 'function') return d
256
288
  d.request = function (opts, callback) {
257
289
  const methodStr = String((opts && opts.method) || 'GET').toUpperCase()
258
- const origin = (opts && opts.origin) || ''
259
- const pathPart = (opts && opts.path) != null ? opts.path : '/'
260
- const urlStr = origin ? (origin + (pathPart.startsWith('/') ? pathPart : '/' + pathPart)) : 'unknown'
290
+ const urlStr = resolveUrlStrFromDispatcherOpts(opts)
261
291
  httpLog('WRAPPER getGlobalDispatcher().request ' + methodStr + ' ' + urlStr.slice(0, 80))
262
292
  const ctx = getRequestContext ? getRequestContext() : (getLastJobContext ? getLastJobContext() : null)
263
293
  const otelCtx = getOtelTraceContext()
@@ -333,9 +363,7 @@ try {
333
363
  const HTTP_CLIENT_MODE = deps ? deps.HTTP_CLIENT_MODE : 'all'
334
364
  d.request = function (opts, callback) {
335
365
  const methodStr = String((opts && opts.method) || 'GET').toUpperCase()
336
- const origin = (opts && opts.origin) || ''
337
- const pathPart = (opts && opts.path) != null ? opts.path : '/'
338
- const urlStr = origin ? (origin + (pathPart.startsWith('/') ? pathPart : '/' + pathPart)) : 'unknown'
366
+ const urlStr = resolveUrlStrFromDispatcherOpts(opts)
339
367
  httpLog('WRAPPER globalThis.dispatcher.request ' + methodStr + ' ' + urlStr.slice(0, 80))
340
368
  const _dp = process.env.AZIFY_DEBUG_LOG_PATH
341
369
  if (_dp) { try { require('fs').appendFileSync(_dp, new Date().toISOString() + ' [AZIFY] WRAPPER globalDispatcher.request ' + methodStr + ' ' + urlStr.slice(0, 100) + '\n') } catch (_) {} }
@@ -608,14 +636,12 @@ try {
608
636
  const RequestHandler = mod.exports.RequestHandler
609
637
  mod.exports = function wrappedApiRequest(opts, callback) {
610
638
  const methodStr = String((opts && opts.method) || 'GET').toUpperCase()
611
- const urlPart = (opts && opts.origin) ? String(opts.origin).slice(0, 80) : (opts && opts.path) || ''
639
+ const urlStr = resolveUrlStrFromDispatcherOpts(opts)
640
+ const urlPart = urlStr !== 'unknown' ? urlStr.slice(0, 80) : ((opts && opts.origin) ? String(opts.origin).slice(0, 80) : (opts && opts.path) || '')
612
641
  if (HTTP_DEBUG) try { process.stderr.write('[AZIFY-PATCH] api-request ' + methodStr + ' ' + urlPart + '\n') } catch (_) {}
613
642
  if (HTTP_VERBOSE || HTTP_DEBUG) {
614
643
  try { process.stderr.write('[AZIFY] HTTP wrapper api-request ' + methodStr + ' ' + urlPart + '\n') } catch (_) {}
615
644
  }
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
645
  httpLog('WRAPPER api-request ' + methodStr + ' ' + urlStr.slice(0, 80))
620
646
  const ctx = getRequestContext() || getLastJobContext()
621
647
  const otelCtx = getOtelTraceContext()