Skip to content

Commit b076813

Browse files
committed
reduce request log cardinality
1 parent 4076850 commit b076813

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

packages/dd-trace/src/exporters/common/request.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,25 @@ function request (data, options, callback) {
9696
callback(null, buffer.toString(), res.statusCode)
9797
}
9898
} else {
99-
let errorMessage = ''
99+
let logArgs = [''] // use with log.error(...logArgs), it's a sprintf string with placeholder args
100100
try {
101101
const fullUrl = new URL(
102102
options.path,
103103
options.url || options.hostname || `http://localhost:${options.port}`
104104
).href
105-
errorMessage = `Error from ${fullUrl}: ${res.statusCode} ${http.STATUS_CODES[res.statusCode]}.`
105+
logArgs[0] += 'Error from agent, url=%s, status=%s %s'
106+
logArgs.push(fullUrl, res.statusCode, http.STATUS_CODES[res.statusCode])
106107
} catch {
107108
// ignore error
108109
}
109110
const responseData = buffer.toString()
110111
if (responseData) {
111-
errorMessage += ` Response from the endpoint: "${responseData}"`
112+
logArgs[0] += ', response=%s'
113+
logArgs.push(responseData.substring(0, 100).replaceAll(/[\r\n]/g, ' ')) // can be a 1MB HTML document from an nginx proxy
112114
}
113-
const error = new Error(errorMessage)
115+
const error = new Error('error from agent. DO NOT PASS TO log.error() INSTEAD USE log.error(...error.logArgs)') // TODO DON'T MERGE THIS
114116
error.status = res.statusCode
117+
error.logArgs = logArgs
115118

116119
callback(error, null, res.statusCode)
117120
}

0 commit comments

Comments
 (0)