microsoft/botbuilder-js

Method “telemetryClient.trackException(error);” is causing container crash

Alassaneokp opened this issue · 2 comments

Application use App Insights SDK for Nodejs in a Bot Service running on Azure App Services Node 16.20.2

----- Problem -----

Method “telemetryClient.trackException(error);” is causing container crash

------Library requirement in Package.json------:

"botbuilder-applicationinsights": "^4.10.4",

------Library installed at deployment time on Package-lock.json------:

"botbuilder-applicationinsights": {

        "version": "4.22.2",

        "requires": {

            "applicationinsights": "^1.7.5",

            "botbuilder-core": "4.22.2",

            "cls-hooked": "^4.2.2"

        },

"applicationinsights": {

        "version": "1.8.10",

        "requires": {

            "cls-hooked": "^4.2.2",

            "continuation-local-storage": "^3.2.1",

            "diagnostic-channel": "0.3.1",

            "diagnostic-channel-publishers": "0.4.4"

        }

    }

------Code extract from Index.js------:

const { ApplicationInsightsTelemetryClient, TelemetryInitializerMiddleware } = require('botbuilder-applicationinsights');

function getTelemetryClient(instrumentationKey) {

if (instrumentationKey) {

    return new ApplicationInsightsTelemetryClient(instrumentationKey);

}

return new NullTelemetryClient();

}

var telemetryClient = getTelemetryClient(process.env.APPINSIGHTS_INSTRUMENTATIONKEY);

var telemetryLoggerMiddleware = new TelemetryLoggerMiddleware(telemetryClient, true);

var initializerMiddleware = new TelemetryInitializerMiddleware(telemetryLoggerMiddleware, true);

adapter.use(initializerMiddleware);

telemetryClient.trackException(error);

----- Workaround -----

App worked for days without issues after commenting the line 101: telemetryClient.trackException(error);,

----- Stack Trace -----

Method “telemetryClient.trackException(error);” is causing crash with following error:

2024-06-02T04:04:05.472628200Z Created new item using POST method

2024-06-02T04:04:05.472651000Z 9FOOB90Dwb7FBL7hbPhN8i-us

2024-06-02T04:04:05.478623676Z /home/site/wwwroot/node_modules/botbuilder/lib/botFrameworkAdapter.js:674

2024-06-02T04:04:05.478643876Z throw new Error(BotFrameworkAdapter.processActivity(): ${status} ERROR\n ${processError.stack});

2024-06-02T04:04:05.478649576Z ^

2024-06-02T04:04:05.478653676Z

2024-06-02T04:04:05.478657476Z Error: BotFrameworkAdapter.processActivity(): 500 ERROR

2024-06-02T04:04:05.478662376Z TypeError: Cannot read properties of undefined (reading 'stack')

2024-06-02T04:04:05.478681476Z at Function.EnvelopeFactory.createExceptionData (/home/site/wwwroot/node_modules/applicationinsights/out/Library/EnvelopeFactory.js:145:40)

2024-06-02T04:04:05.478695976Z at Function.EnvelopeFactory.createEnvelope (/home/site/wwwroot/node_modules/applicationinsights/out/Library/EnvelopeFactory.js:32:40)

2024-06-02T04:04:05.478700577Z at NodeClient.TelemetryClient.track (/home/site/wwwroot/node_modules/applicationinsights/out/Library/TelemetryClient.js:117:44)

2024-06-02T04:04:05.478704677Z at NodeClient.TelemetryClient.trackException (/home/site/wwwroot/node_modules/applicationinsights/out/Library/TelemetryClient.js:70:14)

2024-06-02T04:04:05.478717777Z at ApplicationInsightsTelemetryClient.trackException (/home/site/wwwroot/node_modules/botbuilder-applicationinsights/lib/applicationInsightsTelemetryClient.js:116:28)

2024-06-02T04:04:05.478721777Z at BotFrameworkAdapter.adapter.onTurnError [as turnError] (/home/site/wwwroot/index.js:101:22)

2024-06-02T04:04:05.478725477Z at runMicrotasks ()

2024-06-02T04:04:05.478729577Z at processTicksAndRejections (node:internal/process/task_queues:96:5)

2024-06-02T04:04:05.478733677Z at BotFrameworkAdapter. (/home/site/wwwroot/node_modules/botbuilder/lib/botFrameworkAdapter.js:674:27)

2024-06-02T04:04:05.478737877Z at Generator.tme/site/wwwroot/node_modules/botbuilder/lib/botFrameworkAdapter.js:12:65)

2024-06-02T04:04:05.478745677Z at runMicrotasks ()

2024-06-02T04:04:05.478750177Z at processTicksAndRejections (node:internal/process/task_queues:96:5)

Hi @Alassaneokp and @tracyboehrer,

We were able to reproduce a similar issue by using this sample and executing the telemetryClient.trackException(error); function in the onTurnErrorHandler (line 52) with an Error purposely thrown inside one of the bot's dialogs.

What we've noticed is that by passing the Error instance in the exception property as follows: trackException({ exception: error }), it doesn't fail, and shows the error properly in App Insights.
These are the fields that the trackException parameter accepts:
image

Could this be related to the issue's case? If that isn't the case, what is the error value passed to the trackException call?

Thanks!

Hi @sw-joelmut,
There error value we are passing does not have exception field. I made the same change in my code.
telemetryClient.trackException({exception: new Error(error)});

The botFrameworkAdapter exception is no longer happening.
Thanks for your help.