Search code examples
javascriptbotframeworkazure-application-insights

ApplicationInsightsTelemetryClient not logging bot identifiers


I'm using the JavaScript version of the botframework. I've followed the documentation to enable telemetry logging in Application Insights. When I access the logs I can see that custom events are being logged.

The issue is that the bot specific identifiers, such as user_Id, session_Id and conversation_Id are not being logged. This can be seen in the screen capture below

screen capture of customDimensions attribute

In the applicationInsightsTelemetryClient.js file there is a function called addBotIdentifiers. As far as I can tell, it is this function that is responsible for adding the bot specific identifiers.

The first lines of the function look like this:

function addBotIdentifiers(envelope, context) {
    if (context.correlationContext && context.correlationContext.activity) {

Inspecting this function shows that the context argument is always null.

This leads me to my questions.

  1. Why is it null?
  2. Any suggestions on what I need to do to have it set appropriately?

Update

In digging into this further it appears the code starting at line 26 in the applicationInsightsTelemetryClient.js file isn't being called. Could this be the cause of the missing context later on in the addBotIdentifiers function?


Solution

  • Further investigation has shown what the issue was. It's not immediately obvious.

    I compared the code in my index.js file with the one in the 21.corebot-app-insights BotBuilder sample.

    Note that the setup of the Restify server happens after the creation of the adapter bot adapter. It is also after the configuration of the main dialog and the middleware.

    In my code the setup of the Restify server and the bot adatper / dialogs was intermingled. This appears to have been the cause of the problem.

    The main lesson here for me, and for anyone who stumbles across this post later, is that the setup of the Restify server should be at the end of the index.js file. To ensure all of the bot framework is setup first.