@hypertrace/nodejsagent
Advanced tools
Comparing version 1.8.0 to 1.8.1-dev
@@ -19,2 +19,3 @@ "use strict"; | ||
const http_2 = __importDefault(require("http")); | ||
const node_stream_1 = __importDefault(require("node:stream")); | ||
const _RECORDABLE_CONTENT_TYPES = ['application/json', 'application/graphql', 'application/x-www-form-urlencoded']; | ||
@@ -178,11 +179,20 @@ class HttpInstrumentationWrapper { | ||
let bodyCapture = new BodyCapture_1.BodyCapture(config_1.Config.getInstance().config.data_capture.body_max_size_bytes, 0); | ||
const listener = (chunk) => { | ||
bodyCapture.appendData(chunk); | ||
const chunks = []; | ||
const originalEmit = response.emit; | ||
response.emit = function (eventName, ...args) { | ||
if (eventName === 'data') { | ||
chunks.push(Buffer.from(args[0])); | ||
} | ||
else if (eventName === 'end') { | ||
const bodyBuffer = Buffer.concat(chunks); | ||
let bodyString = bodyBuffer.toString('utf-8'); | ||
span.setAttribute("http.response.body", bodyString); | ||
// @ts-ignore | ||
if (response.stream) { | ||
// @ts-ignore | ||
response.stream = node_stream_1.default.Readable.from(bodyBuffer); | ||
} | ||
} | ||
return originalEmit.apply(response, [eventName, ...args]); | ||
}; | ||
response.on("data", listener); | ||
response.once("end", () => { | ||
response.removeListener('data', listener); | ||
let bodyString = bodyCapture.dataString(); | ||
span.setAttribute("http.response.body", bodyString); | ||
}); | ||
} | ||
@@ -189,0 +199,0 @@ } |
{ | ||
"name": "@hypertrace/nodejsagent", | ||
"version": "1.8.0", | ||
"version": "1.8.1-dev", | ||
"description": "Hypertrace Node.js Agent", | ||
@@ -5,0 +5,0 @@ "author": "Traceable Inc.", |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
401824
7165
1