gpt4 book ai didi

c# - ApplicationInsightDataClient GetCustomEventWithHttpMessageAsync 未加载自定义维度

转载 作者:行者123 更新时间:2023-12-03 00:41:43 24 4
gpt4 key购买 nike

我正在使用 Microsoft.Azure.ApplicationInsights 0.9.0 预览版从应用程序洞察中获取自定义事件

    public async Task<ApplicationInsightsFooDto[]> Foo(TimeSpan timeSpan)
{
var activeDirectoryServiceSettings = new ActiveDirectoryServiceSettings
{
AuthenticationEndpoint = new Uri("https://login.microsoftonline.com"),
TokenAudience = new Uri("https://api.applicationinsights.io/"),
ValidateAuthority = true
};

ServiceClientCredentials serviceCredentials = ApplicationTokenProvider.LoginSilentAsync(
domain: ApplicationInsightConstants.DirectoryId,
clientId: ApplicationInsightConstants.ClientId,
secret: ApplicationInsightConstants.ClientSecret,
settings: activeDirectoryServiceSettings
).GetAwaiter().GetResult();

var applicationInsightsDataClient = new ApplicationInsightsDataClient(serviceCredentials)
{
AppId = ApplicationInsightConstants.AppId,
};
applicationInsightsDataClient.HttpClient.DefaultRequestHeaders.Add("X-Api-Key", "<myApiKey>");

var myEvents = await applicationInsightsDataClient.GetCustomEventsWithHttpMessagesAsync(search: "LoginEvent", timespan: timeSpan);

return new ApplicationInsightsFooDto[] { };
}

响应电流不包含CustomDimension,如下图所示:

enter image description here

但是,如果我直接进行 api 调用,我会得到 customDimensions

示例请求:

GET https://api.applicationinsights.io/v1/apps/<myAppId>/events/customEvents?$search=LoginEvent&timespan=PT1H HTTP/1.1
User-Agent: Fiddler
X-Api-Key: <myApiKey>

响应示例:

{"@odata.context":"https://api.applicationinsights.io/v1/apps/<myappId>/events/$metadata#customEvents",
"@ai.messages":[{"code":"AddedLimitToQuery","message":"The query was limited to 500 rows"}],"value":
[{"id":"...","count":1,"type":"customEvent","timestamp":"...",
"customEvent":{"name":"LoginEvent"},
"customDimensions":{"AspNetCoreEnvironment":"Development","DeveloperMode":"true","UserId":"...","...":"...","UserName":"Xyz","...":"...","Company":"N/A"},"customMeasurements":null,"operation":{"name":"POST Account/Login","id":"someData","p","syntheticSource":""},...}}]}

主机:api.applicationinsights.io

知道如何使用 C# sdk 获取 customDimension,而不是构建自定义 url 然后发出请求吗?

最佳答案

这就是我最终所做的

 var myEvents = await applicationInsightsDataClient
.QueryWithHttpMessagesAsync(
"customEvents " +
"| where name == \"LoginEvent\"" +
"| project customDimensions ");

显然调用QueryWithHttpMessageAsync有效

关于c# - ApplicationInsightDataClient GetCustomEventWithHttpMessageAsync 未加载自定义维度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58917080/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com