【问题标题】:App insights : can't extract my app ID using instrumentation key应用洞察:无法使用检测密钥提取我的应用 ID
【发布时间】:2018-11-12 11:00:00
【问题描述】:

在我的 .NET 核心项目中,我尝试使用来自我的应用洞察力的仪表键来提取我的 AppId: TelemetryConfiguration.Active.InstrumentationKey = _configuration["ApplicationInsights:InstrumentationKey"];

            TelemetryConfiguration.Active.ApplicationIdProvider = new ApplicationInsightsApplicationIdProvider()
            {
                ProfileQueryEndpoint = "https://dc.services.visualstudio.com/api/profiles/{0}/appId"
            };
            bool isSuccessRetrieve = TelemetryConfiguration.Active.ApplicationIdProvider.TryGetApplicationId(_configuration["ApplicationInsights:InstrumentationKey"], out string applicationId);

但结果始终为 false 并且 appID 为空,就好像我的应用洞察不存在一样。

我错过了一些配置吗?有谁知道为什么?

【问题讨论】:

  • 试试_configuration["ApplicationInsights.InstrumentationKey"]
  • _configuration["ApplicationInsights:InstrumentationKey"] 实际上在 appsettings.json 中返回了包含我的 InstrumentationKey 的字符串,所以问题不在 _configuration 中,而是在 TelemetryConfiguration.Active.ApplicationIdProvider.TryGetApplicationId () 方法

标签: c# azure .net-core azure-application-insights


【解决方案1】:

我可以手动完成:

private bool TryGetApplicationId(string intrumentationKey, out string appId)
        {
            RestClient restClient = new RestClient("https://dc.services.visualstudio.com");
            RestRequest request = new RestRequest(string.Format("api/profiles/{0}/appId", intrumentationKey), Method.GET);
            RestResponse response = (RestResponse) restClient.Execute(request);
            appId = response.Content;
            return response.IsSuccessful;
        }

【讨论】:

  • 你能分享一下RestClient代码还是它的程序集?
  • 这是一个您可以在 NUGET 上找到的程序集。只需输入“RestSharp”并将其安装到您的项目中
  • 非常感谢,您可以将其标记为答案,它确实可以帮助其他人。
  • 这绝对有效 - 但我无法在任何地方找到此 API 的文档。你在哪里找到的?
猜你喜欢
  • 2021-08-22
  • 2019-02-01
  • 1970-01-01
  • 2018-12-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-06
相关资源
最近更新 更多