azify-logger 1.0.54-test-3 → 1.0.55-test
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 +13 -1
- package/register.js +50 -15
- package/scripts/redis-worker.js +3 -0
package/package.json
CHANGED
|
@@ -155,8 +155,19 @@ try {
|
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
function patchUndiciExports(exports) {
|
|
158
|
+
if (!exports || typeof exports !== 'object') return
|
|
159
|
+
if (typeof exports.fetch === 'function' && typeof globalThis.fetch === 'function' && globalThis.fetch.__azifyLoggerFetchPatched) {
|
|
160
|
+
if (exports.fetch !== globalThis.fetch) {
|
|
161
|
+
exports.fetch = globalThis.fetch
|
|
162
|
+
httpLog('undici exports.fetch -> globalThis.fetch (body logging)')
|
|
163
|
+
}
|
|
164
|
+
}
|
|
158
165
|
const hasRequest = exports && typeof exports.request === 'function' && !exports.request.__azifyPatched
|
|
159
|
-
const hasFetch =
|
|
166
|
+
const hasFetch =
|
|
167
|
+
exports &&
|
|
168
|
+
typeof exports.fetch === 'function' &&
|
|
169
|
+
!exports.fetch.__azifyPatched &&
|
|
170
|
+
!exports.fetch.__azifyLoggerFetchPatched
|
|
160
171
|
if (!exports || (!hasRequest && !hasFetch)) return
|
|
161
172
|
const deps = loadStoreAndSampling()
|
|
162
173
|
const noDeps = !deps
|
|
@@ -736,6 +747,7 @@ try {
|
|
|
736
747
|
function patchGlobalFetch() {
|
|
737
748
|
try {
|
|
738
749
|
if (typeof globalThis.fetch !== 'function') return
|
|
750
|
+
if (globalThis.fetch.__azifyLoggerFetchPatched) return
|
|
739
751
|
if (globalThis.fetch.__azifyPatched) return
|
|
740
752
|
const deps = loadStoreAndSampling()
|
|
741
753
|
if (!deps || deps.HTTP_CLIENT_MODE === 'off') return
|
package/register.js
CHANGED
|
@@ -1588,6 +1588,35 @@ try {
|
|
|
1588
1588
|
return url
|
|
1589
1589
|
}
|
|
1590
1590
|
|
|
1591
|
+
const MAX_HTTP_BODY_CHARS = Math.min(
|
|
1592
|
+
Math.max(parseInt(String(process.env.AZIFY_LOGGER_HTTP_BODY_MAX_CHARS || '5000'), 10) || 5000, 100),
|
|
1593
|
+
100000
|
|
1594
|
+
)
|
|
1595
|
+
function clipHttpLogString(s) {
|
|
1596
|
+
if (typeof s !== 'string') return s
|
|
1597
|
+
return s.length > MAX_HTTP_BODY_CHARS ? s.slice(0, MAX_HTTP_BODY_CHARS) : s
|
|
1598
|
+
}
|
|
1599
|
+
function stringifyHttpBodyForLog(value) {
|
|
1600
|
+
if (value == null) return null
|
|
1601
|
+
try {
|
|
1602
|
+
if (typeof value === 'string') {
|
|
1603
|
+
return clipHttpLogString(value)
|
|
1604
|
+
}
|
|
1605
|
+
if (Buffer.isBuffer(value)) {
|
|
1606
|
+
return clipHttpLogString(value.toString('utf8'))
|
|
1607
|
+
}
|
|
1608
|
+
if (value && typeof value.pipe === 'function') {
|
|
1609
|
+
return '[Stream]'
|
|
1610
|
+
}
|
|
1611
|
+
if (typeof value === 'object') {
|
|
1612
|
+
return clipHttpLogString(JSON.stringify(value))
|
|
1613
|
+
}
|
|
1614
|
+
return clipHttpLogString(String(value))
|
|
1615
|
+
} catch (_) {
|
|
1616
|
+
return '[unserializable]'
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
|
|
1591
1620
|
const patchInstance = (instance) => {
|
|
1592
1621
|
if (instance.__azifyLoggerPatched) {
|
|
1593
1622
|
return instance
|
|
@@ -1631,6 +1660,11 @@ try {
|
|
|
1631
1660
|
headers: config.headers
|
|
1632
1661
|
}
|
|
1633
1662
|
|
|
1663
|
+
const requestBodyString = stringifyHttpBodyForLog(config.data)
|
|
1664
|
+
if (requestBodyString != null) {
|
|
1665
|
+
requestMeta.requestBody = requestBodyString
|
|
1666
|
+
}
|
|
1667
|
+
|
|
1634
1668
|
markSource(requestMeta, 'http-client')
|
|
1635
1669
|
config.__azifyLogger = {
|
|
1636
1670
|
meta: requestMeta,
|
|
@@ -1684,12 +1718,15 @@ try {
|
|
|
1684
1718
|
|
|
1685
1719
|
const stringifyBody = (value) => {
|
|
1686
1720
|
if (value == null) return null
|
|
1687
|
-
if (typeof value === 'string') return value
|
|
1721
|
+
if (typeof value === 'string') return clipHttpLogString(value)
|
|
1722
|
+
if (Buffer.isBuffer(value)) {
|
|
1723
|
+
return clipHttpLogString(value.toString('utf8'))
|
|
1724
|
+
}
|
|
1688
1725
|
try {
|
|
1689
|
-
return JSON.stringify(value)
|
|
1726
|
+
return clipHttpLogString(JSON.stringify(value))
|
|
1690
1727
|
} catch (_) {
|
|
1691
1728
|
try {
|
|
1692
|
-
return String(value)
|
|
1729
|
+
return clipHttpLogString(String(value))
|
|
1693
1730
|
} catch (_) {
|
|
1694
1731
|
return null
|
|
1695
1732
|
}
|
|
@@ -1698,17 +1735,16 @@ try {
|
|
|
1698
1735
|
|
|
1699
1736
|
if (marker && marker.meta) {
|
|
1700
1737
|
duration = Number((performance.now() - marker.start).toFixed(2))
|
|
1701
|
-
|
|
1702
|
-
if (typeof responseBodyString === 'string' && responseBodyString.length > 5000) {
|
|
1703
|
-
responseBodyString = responseBodyString.slice(0, 5000)
|
|
1704
|
-
}
|
|
1738
|
+
const responseBodyString = stringifyBody(response.data)
|
|
1705
1739
|
meta = {
|
|
1706
1740
|
...marker.meta,
|
|
1707
1741
|
url: finalUrl,
|
|
1708
1742
|
statusCode: response.status,
|
|
1709
1743
|
responseTimeMs: duration,
|
|
1710
|
-
responseHeaders: response.headers
|
|
1711
|
-
|
|
1744
|
+
responseHeaders: response.headers
|
|
1745
|
+
}
|
|
1746
|
+
if (responseBodyString != null) {
|
|
1747
|
+
meta.responseBody = responseBodyString
|
|
1712
1748
|
}
|
|
1713
1749
|
} else {
|
|
1714
1750
|
const requestHeaders = response.config?.headers || {}
|
|
@@ -1717,10 +1753,7 @@ try {
|
|
|
1717
1753
|
const spanId = requestHeaders['x-span-id'] || requestHeaders['X-Span-ID'] || randomBytes(8).toString('hex')
|
|
1718
1754
|
const parentSpanId = requestHeaders['x-parent-span-id'] || requestHeaders['X-Parent-Span-ID'] || ctx?.spanId || null
|
|
1719
1755
|
const requestId = requestHeaders['x-request-id'] || requestHeaders['X-Request-ID'] || ctx?.requestId || randomUUID()
|
|
1720
|
-
|
|
1721
|
-
if (typeof responseBodyString === 'string' && responseBodyString.length > 5000) {
|
|
1722
|
-
responseBodyString = responseBodyString.slice(0, 5000)
|
|
1723
|
-
}
|
|
1756
|
+
const responseBodyString = stringifyBody(response.data)
|
|
1724
1757
|
|
|
1725
1758
|
meta = {
|
|
1726
1759
|
traceId,
|
|
@@ -1731,8 +1764,10 @@ try {
|
|
|
1731
1764
|
url: finalUrl,
|
|
1732
1765
|
statusCode: response.status,
|
|
1733
1766
|
responseTimeMs: duration,
|
|
1734
|
-
responseHeaders: response.headers
|
|
1735
|
-
|
|
1767
|
+
responseHeaders: response.headers
|
|
1768
|
+
}
|
|
1769
|
+
if (responseBodyString != null) {
|
|
1770
|
+
meta.responseBody = responseBodyString
|
|
1736
1771
|
}
|
|
1737
1772
|
}
|
|
1738
1773
|
|
package/scripts/redis-worker.js
CHANGED
|
@@ -254,6 +254,9 @@ function sanitizePayload(payload) {
|
|
|
254
254
|
if (sanitized.meta.responseBody) {
|
|
255
255
|
sanitized.meta.responseBody = sanitizeBody(sanitized.meta.responseBody)
|
|
256
256
|
}
|
|
257
|
+
if (sanitized.meta.requestBody) {
|
|
258
|
+
sanitized.meta.requestBody = sanitizeBody(sanitized.meta.requestBody)
|
|
259
|
+
}
|
|
257
260
|
}
|
|
258
261
|
|
|
259
262
|
return sanitized
|