botframework-solutions icon indicating copy to clipboard operation
botframework-solutions copied to clipboard

how to include metadata in the insight query for QnAMaker logs

Open dabgar opened this issue 5 years ago • 4 comments

Please let me know how to include metadata in the insight query for QnAMaker logs somthing as this, here the meatadata field comes empty

requests | where url endswith "generateAnswer" | project timestamp, id, url, resultCode, duration, performanceBucket | parse kind = regex url with *"(?i)knowledgebases/"KbId"/generateAnswer" | join kind= inner ( traces | extend id = operation_ParentId ) on id | extend question = tostring(customDimensions['traces']) | extend answer = tostring(customDimensions['Answer']) | extend score = tostring(customDimensions['Score']) | extend metadata = tostring(customDimensions['qnaMakerOptions']) | project answer,['metadata']

Originally posted by @dabgar in https://github.com/microsoft/botframework-solutions/issues/3668#issuecomment-925524320

dabgar avatar Sep 24 '21 05:09 dabgar

@dabgar could you give us some details on this? In #3668, Peter suggested telemetry could be logged through these two classes:

https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/Microsoft.Bot.Builder.AI.QnA/Dialogs/QnAMakerDialog.cs https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/Microsoft.Bot.Builder.AI.QnA/QnAMaker.cs

Are you saying that, even coded added to log telemetry data through these classes, it is not appearing in App Insights?

compulim avatar Sep 24 '21 18:09 compulim

Screenshot 2021-09-24 at 10 31 05 AM

Attaching a screenshot of the issue faced. The code shared is C# code , is there a nodejs version of the same. Also like answer and question which comes directly without adding any code is it not possible to get the metadata similar way?

Let me know the way to get the metadata of qnamaker in the insight(complete procedure with the query please)

dabgar avatar Sep 25 '21 03:09 dabgar

@dabgar, Peter's suggestion of writing a custom dialog to achieve this would be my recommendation as well. Unfortunately, we do not have a sample available that illustrates how to achieve this functionality.

There is a sample custom dialog, the MultiplyDialog in the samples repo that shows how to write a custom dialog.

The general approach you would take is to write a custom dialog extending from QnAMakerDialog, probably overriding the protected getQnaMakerClient(...) method to return a custom QnAMaker implementation that includes the metadata you care about in the onQnaResults method. Below is some pseudocode that illustrates the example

class CustomQnAMakerDialog extends QnAMakerDialog {
  async getQnaMakerClient(dialogContext) {
    const client = await super.getQnAMakerClient(dialogContext);

    const onQnaResults = client.onQnaResults.bind(client);
    client.onQnaResults = (qnaResults, turnContext, properties = {}, metrics = {}) => {
      properties = { ...properties, custom: 'property' };
      metrics = { ...metrics, custom: 1.0 };

      return onQnaResults(qnaResults, turnContext, properties, metrics);
    }
  }
}

As I mentioned above, this is pseudocode so you will have to study it and probably amend it further to suit your needs. I hope this helps!

joshgummersall avatar Sep 27 '21 19:09 joshgummersall

Closing with Josh Gummersall's answer.

EricDahlvang avatar Oct 11 '21 18:10 EricDahlvang