You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

QnAMaker使用Application Insights日志时customDimensions数据全为空如何调整代码

问题根因

存在两个配置/使用错误导致你拿不到对应的字段值:

  1. QnAMaker初始化时未开启个人信息上报开关,问答内容、用户标识这类属于个人信息的属性默认不会被采集上报
  2. 你查询的requests表并不存储QnAMaker专属遥测数据,这类数据全部上报到customEvents表

调整步骤

1. 修改QnAMaker实例化代码

补充QnAMakerOptions配置,开启个人信息上报权限:

using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.AI.QnA;
using Microsoft.Extensions.Configuration;
using System.Net.Http;

namespace Microsoft.BotBuilderSamples
{
    public class BotServices : IBotServices
    {
        private readonly IHttpClientFactory _httpClientFactory;
        private readonly IBotTelemetryClient _telemetryClient;

        public BotServices(IConfiguration configuration, IBotTelemetryClient telemetryClient, IHttpClientFactory httpClientFactory)
        {
            _httpClientFactory = httpClientFactory;
            _telemetryClient = telemetryClient;

            var httpClient = _httpClientFactory.CreateClient();
            QnAMakerService = new QnAMaker(new QnAMakerEndpoint
            {
                KnowledgeBaseId = configuration["QnAKnowledgebaseId"],
                EndpointKey = configuration["QnAAuthKey"],
                Host = GetHostname(configuration["QnAEndpointHostName"])
            },
            // 替换原来的null参数,添加QnAMakerOptions配置
            new QnAMakerOptions
            {
                LogPersonalInformation = true,
                // 可按需添加其他配置,比如阈值、返回答案数量等
                ScoreThreshold = 0.3F,
                Top = 3
            },
            httpClient,
            _telemetryClient);
        }

        public QnAMaker QnAMakerService { get; private set; }

        private static string GetHostname(string hostname)
        {
            if (!hostname.StartsWith("https://"))
            {
                hostname = string.Concat("https://", hostname);
            }

            if (!hostname.EndsWith("/qnamaker") && !hostname.Contains("/v5.0"))
            {
                hostname = string.Concat(hostname, "/qnamaker");
            }

            return hostname;
        }
    }
}

2. 调整Application Insights查询语句

从customEvents表查询QnAMaker事件(事件固定名称为QnaMessage):

customEvents
| where name == "QnaMessage"
| project
ActivityId = customDimensions.activityId, 
ActivityType = customDimensions.activityType,
ChannelId = customDimensions.channelId  , 
ConversationId = session_Id ,
ReplyActivityId = customDimensions.replyActivityId , 
FromId = customDimensions.fromId , 
Locale = customDimensions.locale  ,
RecipientId = customDimensions.recipientId,  
Speak = customDimensions.speak ,  
Text =    customDimensions.text,
EventName = name, 
Time = timestamp, 
Date = timestamp,
DialogInstanceId = customDimensions.InstanceId,
DialogId = customDimensions.DialogId  , 
DialogStepName = customDimensions.StepName,
QnA_KnowledgeBaseId = customDimensions.knowledgeBaseId,
QnA_Answer = customDimensions.answer,
QnA_ArticleFound = customDimensions.articleFound,
QnA_OriginalQuestion = customDimensions.originalQuestion,
QnA_Question = customDimensions.question,
QnA_QuestionId = customDimensions.questionId,
QnA_Score = customDimensions.score,
QnA_UserName = customDimensions.username,
User_City = client_City, 
User_State = client_StateOrProvince, 
User_Country = client_CountryOrRegion,
Feedback_Value = customDimensions.Feedback,
Feedback_Comment = customDimensions.Comment,
Feedback_Tag = customDimensions.Tag

注:原查询中的LUIS相关字段属于LUIS服务的遥测属性,不会出现在QnAMaker的事件中,可单独查询LUIS对应的LuisMessage事件获取


内容的提问来源于stack exchange,提问作者briand932

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 02:57:01