gpt4 book ai didi

c# - 如何设置 DependencyTelemetry 的 Application Insights AuthenticatedUserId?

转载 作者:行者123 更新时间:2023-12-03 00:09:10 28 4
gpt4 key购买 nike

在 Azure 函数中,我正在提交自定义遥测数据。

//First an event
EventTelemetry eventTelemetry = new EventTelemetry()
{
Name = $"Authenticated user: {portalUser.FullName} - ({portalUser.Id})"
};

ConfigureTelemetry(eventTelemetry);

TelemetryClient.TrackEvent(eventTelemetry);

//Then a dependency
DependencyTelemetry dependencyTelemetry = new DependencyTelemetry()
{
Type = "SOAP",
Name = name,
Target = target,
Data = data,
Timestamp = DateTime.UtcNow,
Success = success
};

ConfigureTelemetry(dependencyTelemetry);

TelemetryClient.TrackDependency(dependencyTelemetry);

...

//Set shared properties
void ConfigureTelemetry(ITelemetry telemetry)
{
telemetry.Context.Operation.Id = FunctionSettings.InvocationId;
telemetry.Context.Operation.ParentId = FunctionSettings.InvocationId;
telemetry.Context.Operation.Name = FunctionSettings.FunctionName;

telemetry.Context.User.Id = PortalUser.Id.ToString();
telemetry.Context.User.AuthenticatedUserId = PortalUser.Id.ToString();
}

已在 Application Insights 中成功跟踪事件和依赖项,但 DependencyTelemetry 缺少 IdAuthenticatedUserId 信息。

依赖项是否支持 user_iduser_authenticatedid

<小时/>

回答问题:

Do you any TelemetryInitializer or TelemetryProcessor which is modifying these fields as well?

没有。正如上面的代码所示。

How do you create the instance of TelemetryClient?

return new TelemetryClient()
{
InstrumentationKey = ApplicationSettings.ApplicationInsightsKey
};

In my opinion you have to set the context for the instance

我也尝试过,但结果相同,在这种情况下我的代码看起来更像这样:

void ConfigureTelemetry()
{
...
TelemetryClient.Context.User.Id = PortalUser.Id.ToString();
TelemetryClient.Context.User.AuthenticatedUserId = PortalUser.Id.ToString();
}

please also share an example for the event and dependency shown in Application Insights's analytics view

在这些示例中,我并没有尝试设置“user_id”,但这确实适用于事件。

自定义事件

timestamp [UTC] | 2018-07-11T16:14:15.48Z   
name | Authenticated user: Cenajog2 Cenajog2 - (127a897f-d16f-e811-810a-3863bb343b78)
itemType | customEvent
operation_Name | TestOperation
operation_Id | c03d657f-6b0b-483e-9a32-c592fd2af701
operation_ParentId | c03d657f-6b0b-483e-9a32-c592fd2af701
user_AuthenticatedId | 127a897f-d16f-e811-810a-3863bb343b78
client_Type | PC
client_IP | 0.0.0.0
client_City | London
client_StateOrProvince | England
client_CountryOrRegion | United Kingdom
cloud_RoleInstance | RD00155D8C9B54
appId | 824c86f8-29be-4a01-b242-44bfe1915520
appName | dev
iKey | 9921a9e7-0c07-49fd-bd71-a9e76b9906bc
sdkVersion | dotnet:2.5.1-172
itemId | 7b2708c1-8525-11e8-a89a-2fa60245d417
itemCount | 1

依赖关系

timestamp [UTC] | 2018-07-11T16:14:15.48Z   
id | yP475Jc3ZwY=
target | Development
type | SOAP
name | RetrieveMultiple
success | True
performanceBucket | >=5min
itemType | dependency
operation_Name | TestOperation
operation_Id | c03d657f-6b0b-483e-9a32-c592fd2af701
operation_ParentId | c03d657f-6b0b-483e-9a32-c592fd2af701
client_Type | PC
client_IP | 0.0.0.0
client_City | London
client_StateOrProvince | England
client_CountryOrRegion | United Kingdom
cloud_RoleInstance | RD00155D8C9B54
appId | 824c86f8-29be-4a01-b242-44bfe1915520
appName | dev
iKey | 9921a9e7-0c07-49fd-bd71-a9e76b9906bc
sdkVersion | dotnet:2.5.1-172
itemId | 7b2708c0-8525-11e8-a89a-2fa60245d417
itemCount | 1

最佳答案

所有类型都支持

UserIdUserAuthenticatedUserId,包括 DependencyTelemetry。因此,如果 PortalUser.Id.ToString(); 返回非空值,上面的代码也应该显示依赖项的 userid 等。

您是否也修改这些字段的 TelemetryInitializerTelemetryProcessor

关于c# - 如何设置 DependencyTelemetry 的 Application Insights AuthenticatedUserId?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51288840/

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