简体   繁体   English

从从 WPF 发送到 Azure Application Insights 的数据中删除 RoleInstance

[英]Remove RoleInstance from data sent to Azure Application Insights from WPF

I'm trying to add Application Insights to a WPF app using this documentation: https://docs.microsoft.com/en-us/azure/azure-monitor/app/windows-desktop .我正在尝试使用以下文档将 Application Insights 添加到 WPF 应用程序: https://docs.microsoft.com/en-us/azure/azure-monitor/app/windows-desktop The basic integration is working.基本集成正在工作。 I am now trying to remove the RoleInstance property from the submitted data, as described in the documentation, as this contains the user's computer name (personally identifiable information).我现在正尝试从提交的数据中删除 RoleInstance 属性,如文档中所述,因为它包含用户的计算机名称(个人身份信息)。 Here's my code, based on the documentation above:这是我的代码,基于上面的文档:

Telemetry.cs遥测.cs

public static class Telemetry
{
    public static TelemetryClient Client;

    public static void Close()
    {
        if (Client != null)
        {
            Client.Flush();
            System.Threading.Thread.Sleep(1000);
        }
    }

    public static void Initialize()
    {
        TelemetryConfiguration.Active.InstrumentationKey = "xxxxxxxx";
        TelemetryConfiguration.Active.TelemetryInitializers.Add(new MyTelemetryInitializer());

        Client = new TelemetryClient(TelemetryConfiguration.Active);

        Client.Context.Session.Id = Guid.NewGuid().ToString();
        Client.Context.Device.OperatingSystem = Environment.OSVersion.ToString();
    }

    private class MyTelemetryInitializer : ITelemetryInitializer
    {
        public void Initialize(ITelemetry telemetry)
        {
            if (string.IsNullOrEmpty(telemetry.Context.Cloud.RoleName))
            {
                telemetry.Context.Cloud.RoleInstance = null;
            }
        }
    }
}

App.xaml.cs App.xaml.cs

public partial class App : Application
{
    protected override void OnExit(ExitEventArgs e)
    {
        Telemetry.Close();

        base.OnExit(e);
    }

    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);

        Telemetry.Initialize();
    }
}

When I call Telemetry.Client.TrackEvent() , Telemetry.Initialize() runs, and RoleInstance is null from the start.当我调用Telemetry.Client.TrackEvent()时, Telemetry.Initialize()运行,并且RoleInstance从一开始就是 null 。 But, the data sent to AI contains my computer name as the RoleInstance.但是,发送给 AI 的数据包含我的计算机名称作为 RoleInstance。 Not sure how to debug further.不知道如何进一步调试。

Note: the documentation describes integration into WinForms, and I'm in WPF, so I've guessed at using App.OnStartup instead of Main .注意:文档描述了与 WinForms 的集成,我在 WPF,所以我猜想使用App.OnStartup而不是Main

I just found something interesting, if you set a dummy value for RoleInstance , it really takes effect.我刚刚发现了一些有趣的东西,如果你为RoleInstance设置一个虚拟值,它真的会生效。 Maybe the null/empty value will be checked and replaced by the real RoleInstance in the backend.也许 null/empty 值将在后端被真正的RoleInstance检查和替换。 As a workaround, you can just specify a dummy value instead of null/empty value.作为一种解决方法,您可以只指定一个虚拟值而不是空值/空值。

Here is my test result with a dummy value:这是我的带有虚拟值的测试结果:

在此处输入图像描述

in azure portal:在 azure 门户中:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 需要澄清:从 Azure Functions 将数据记录到 Application Insights - Need Clarification : Logging data in to Application Insights from Azure Functions 更新到Azure Application Insights 1.1,现在不发送数据 - Update to Azure Application Insights 1.1, now data is not sent 我想自定义从Azure Application Insights发送的警报电子邮件。 我该怎么做? - I want to customize alert emails sent from Azure Application Insights. How Can I do it? 数据未在启动时从 ILogger 发送到 App Insights - Data not sent to App Insights from ILogger in Startup 忽略Azure Application Insights中的端点 - Ignore Endpoints from Azure Application Insights 如何使用Application Insights覆盖或忽略cloud_RoleInstance - How to overwrite or ignore cloud_RoleInstance with Application Insights 如何从 ASP.NET Core 应用程序将应用程序洞察数据发布到 REST API 而不是 Azure? - How to post application insights data to REST API instead of Azure from ASP.NET Core application? 从应用程序洞察(Azure 门户)获取数据以将其显示在 asp.net Web 应用程序的网页上 - Fetching data from Application insights (Azure Portal) to display it on a web page in asp.net web application Application Insights - 没有从服务器显示的数据 - Application Insights - No data showing up from server 从 Application Insights 获取页面查看数据 - Get Page View Data from Application Insights
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM