Application Insights-跨架构跟踪用户和会话 [英] Application Insights - Tracking user and session across schemas

查看:73
本文介绍了Application Insights-跨架构跟踪用户和会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照 https://docs.microsoft.com/zh-CN/azure/application-insights/app-insights-usage-send-user-context ,我认为对用户进行跨方案跟踪会很容易.但是,我发现完全相反.

Following https://docs.microsoft.com/en-us/azure/application-insights/app-insights-usage-send-user-context, I thought it would be easy to get cross-schema tracking of a user. However, I'm finding the absolute opposite.

我创建了遥测初始化程序(该文件的硬核中包含错误):

I created the telemetry initializer (which the document has bugs in it hardcore):

public void Initialize(ITelemetry telemetry)
    {
        if (HttpContext.Current?.Session == null)
            return;

        if (HttpContext.Current.Session["UserId"] == null)
        {
            HttpContext.Current.Session["UserId"] = Guid.NewGuid().ToString();
        }

        telemetry.Context.User.Id = (string)HttpContext.Current.Session["UserId"];
        telemetry.Context.Session.Id = HttpContext.Current.Session.SessionID;

        var authUser = _sessionManager.GetAuthenticatedUser<UserDetails>();
        if (authUser != null)
        {
            telemetry.Context.User.AuthenticatedUserId = authUser.UserId;
        }
    }

然后我去了并将其添加到App Insights

Then I went and added it to App Insights

TelemetryConfiguration.Active.TelemetryInitializers.Add(new UserTrackingTelemetryInitializer());

然后,我在自己的网站上玩,期望这些东西开始出现.它没有.我继续获得user_Id和session_Id的随机字符串(诸如NVhLF之类的东西).因此,我认为,好吧,也许是在更新这些值之前正在记录日志?我先插入了初始化程序:

I then played with my site, expecting this stuff to start showing up. It did not. I continued to get random strings for user_Id and session_Id (things like NVhLF and what not). So, I thought, okay, maybe it's logging before I update those values? I went and inserted my initializer first:

TelemetryConfiguration.Active.TelemetryInitializers.Insert(0, new UserTrackingTelemetryInitializer());

同一件事.因此,我开始查看我通常不会查看的模式.没有.因此我找到了痕迹,然后找到了.最后,这里是我的数据去向.但是其他模式没有更新的值,那么这有什么用?当跟踪显示user_Id和session_Id的期望值时,其他跟踪继续显示垃圾.我在做错什么吗?

Same thing. So I started to look at schemas I don't usually look at. Nothing. So I pulled up traces and I found it. Finally, there is where my data is going. But the other schemas don't have the updated values, so what use is this? While traces is showing the expected values for user_Id and session_Id, the others continue to show garbage. Am I doing something wrong?

推荐答案

The document you followed does not work indeed, a feedback has been submitted here.

仅供参考,我可以找到设置这些值的方法是在实施your own telemetry initializer

Just for your reference, the way I can find to set these values is that use such TrackEvent() / TrackRequest() or other Trackxxx() methods after implemented your own telemetry initializer

这篇关于Application Insights-跨架构跟踪用户和会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆