[英]How can I send CustomUserId to Appinsight by writing code in .netcore 2.2?
I created app-insight application in azure to keep track of metrics.我在 azure 中创建了 app-insight 应用程序来跟踪指标。 Everything looks fine and easy to see Req/Res.I did below steps: adding appsettings.json:
一切看起来都很好,很容易看到 Req/Res。我做了以下步骤:添加 appsettings.json:
"ApplicationInsights": {
"InstrumentationKey": "xxxx-7a49-4bc1-yyyy-kkkkk"
},
And adding UseApplicationInsights in Program.cs并在 Program.cs 中添加 UseApplicationInsights
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseApplicationInsights()
.UseStartup<Startup>();
but I want to send something to appinsight and see as a column when I write kusto query.但是我想在编写 kusto 查询时向 appinsight 发送一些内容并作为一列查看。
is there any way like below stuff:有没有像下面这样的东西:
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseApplicationInsights()
.ChangeValue("UserId",Httphelper.GetCurrentUserId)
.AddColumn("MyCustomField", Httphelper.Something)
.UseStartup<Startup>();
Can I do that or any way to send or modify existed value?我可以这样做或以任何方式发送或修改现有值吗? I Tried to find any article about it but I couldn't satisfied solution.
我试图找到任何关于它的文章,但我无法满足解决方案。
You can add it as a custom property via ITelemetryInitializer .您可以通过ITelemetryInitializer将其添加为自定义属性。
In the sample code, you just need a few modification to add a property like below:在示例代码中,您只需进行一些修改即可添加如下属性:
public class MyTelemetryInitializer : ITelemetryInitializer
{
public void Initialize(ITelemetry telemetry)
{
telemetry.Properties["customuserid"] = "your_id";
}
}
For how to register the ITelemetryInitializer to asp.net core project, please refer to this section " ASP.NET Core/ Worker Service apps: Load your initializer " in the above doc.关于如何将 ITelemetryInitializer 注册到 asp.net 核心项目,请参阅上述文档中的“ ASP.NET Core/Worker Service apps: Load your initializer ”一节。 A screenshot as below:
截图如下:
After you add the above code, then every telemetry data will include the custom property.添加上述代码后,每个遥测数据都将包含自定义属性。 Then in your kusto query, you can take use of this property.
然后在您的 kusto 查询中,您可以使用此属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.