ApplicationInsights-node.js
ApplicationInsights-node.js copied to clipboard
TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["x-ms-qps-machine-name"]
After updating my dependency to "applicationinsights": "^2.2.2"
I see an error because os.hostname()
has an apostrophe and this value is not sanitized before being put into a header. I fixed this only by changing my machine's hostname with scutil --set HostName rob
Full stack trace
(node:8275) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["x-ms-qps-machine-name"]
at ClientRequest.setHeader (_http_outgoing.js:564:3)
at new ClientRequest (_http_client.js:262:14)
at Object.request (https.js:370:10)
at Object.https.request (/Users/rob/workspace/partner-inventory-service/node_modules/applicationinsights/AutoCollection/HttpDependencies.ts:115:74)
at QuickPulseSender.<anonymous> (/Users/rob/workspace/partner-inventory-service/node_modules/applicationinsights/Library/QuickPulseSender.ts:114:27)
at step (/Users/rob/workspace/partner-inventory-service/node_modules/applicationinsights/out/Library/QuickPulseSender.js:33:23)
at Object.next (/Users/rob/workspace/partner-inventory-service/node_modules/applicationinsights/out/Library/QuickPulseSender.js:14:53)
at /Users/rob/workspace/partner-inventory-service/node_modules/applicationinsights/out/Library/QuickPulseSender.js:8:71
at new Promise (<anonymous>)
at __awaiter (/Users/rob/workspace/partner-inventory-service/node_modules/applicationinsights/out/Library/QuickPulseSender.js:4:12)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:8275) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:8275) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
@robadurbin-gp which version of Node.js are you using?, can you share some hostname example, I tried apostrophes and tons of other ASCII characters and I'm not getting any error. Is this error triggered when looking at Live Metrics?
I can reproduce this on Windows using the same version - 2.2.2
(also appears on 2.3.3
). I triggered the error by renaming a VM's computer name to include a unicode character: ¢
-- so something like mycomputer¢
@hectorhdzg I'm using node v16.14.2 and as it turns out, mac default computer names like Rob's Computer
do not use a standard apostrophe ascii code 39, of course they went with the fancy unicode character 8217 so use this character and you should be able to reproduce this.
@robadurbin-gp I was able to connect to Application Insights (specifically QuickPulse which appears to be throwing the error from your stack trace) on a macOS machine with a machine name including Unicode (tested with a few different characters). From my testing it appeared to be sanitizing the machine name input at some point since the machine name displayed on the Azure Portal didn't contain any of the unicode characters. Could you ensure that you're on the latest version of Application insights and send me the headers on your request that's generating your error?