ApplicationInsights:Could not decode the auth cookie with error
SDK Version: 2.9.6 Express version: 4.21.1
The above version of the SDK is in use with an Express application, installed on Windows Server.
ApplicationInsights:Could not decode the auth cookie with error: [ "[object Error]{ stack: 'URIError: URI malformed\n" + ' at decodeURI (
)\n' + ' at HttpRequestParser._getId ( \node_modules\applicationinsights\out\AutoCollection\HttpRequestParser.js:217:26)\n' + ' at HttpRequestParser.getRequestTags ( \node_modules\applicationinsights\out\AutoCollection\HttpRequestParser.js:118:110)\n' + ' at AutoCollectHttpRequests.endRequest ( \node_modules\applicationinsights\out\AutoCollection\HttpRequests.js:232:55)\n' + ' at ServerResponse. ( \node_modules\applicationinsights\out\AutoCollection\HttpRequests.js:192:41)\n' + ' at Object.onceWrapper (node:events:631:28)\n' + ' at ServerResponse.clsBind ( \node_modules\cls-hooked\context.js:172:17)\n' + ' at ServerResponse.emit (node:events:529:35)\n' + ' at ServerResponse.emitted ( \node_modules\emitter-listener\listener.js:134:21)\n' + " at onFinish (node:_http_outgoing:1008:10)', message: 'URI malformed', name: 'URIError'" ]
Could you advise / provide some context as to why this might occur? the Module is being loaded relatively simply using the application insights connection string
const appInsights = require('applicationinsights') appInsights .setup() appInsights.defaultClient.context.tags[appInsights.defaultClient.context.keys.cloudRole] = 'our-name' appInsights.start()
I wouldn't be surprised if a malformed request had caused the error (most day to day requests are not causing the error), however I don't understand what the auth cookie aspect refers to.
Many thanks
@DevRCRun We try to parse some values from cookies in the HttpRequestParser. This warning comes from a function concerned with parsing the ai_authUser from the request's cookies. We run decodeURI() on the cookie when trying to get this value. If that function throws an error we catch and log the warning you're seeing above. As the exception is handled and just a warning is logged, this shouldn't impact export of request telemetry.
What format is your authUser cookie in?
We're seeing this warning in our logs too, and I have never heard of that ai_authUser cookie until now.
What exactly is the purpose of that cookie, and where and how is that cookie supposed to be set?
Could it be, that the code just assumes that cookie exists, and logs that warning if it doesn't? Should this maybe just fail silently, instead of spamming our logs with this warning?
The above merged PR should resolve this issue. Please let me know if you still have any trouble.