Gio*_*lbo 7 azure azure-application-insights
我注意到App Insights在分析工具中查询时有一个名为appName(和appId)的字段(见下文),但我没有看到在客户端库中设置此方法的方法.这可以设置吗?
我正在尝试将相关项目记录到应用洞察,尽管日志源可能不同.使用该字段似乎是处理该场景的一种很好的方式,尽管我对不同的场景持开放态度.
有一个预览,您可以在其中设置应用程序名称。这可以通过以下方式完成:
启用预览:转到门户->应用程序见解->预览->启用多角色应用程序图
设置应用程序名称:
这可以通过添加一个拦截器来完成:
public class ServiceNameInitializer : ITelemetryInitializer
{
public void Initialize(ITelemetry telemetry)
{
telemetry.Context.Cloud.RoleName = "MyProcessName";
// RoleInstance property modifies the app name in the telmetry dashboard
telemetry.Context.Cloud.RoleInstance = "MyAppInstanceName";
}
}
Run Code Online (Sandbox Code Playgroud)
将拦截器添加到startup.cs中的应用程序见解配置中:
private void ConfigureAppInsights(IServiceCollection services)
{
services.AddApplicationInsightsTelemetry(Configuration);
TelemetryConfiguration.Active.TelemetryInitializers
.Add(new ServiceNameInitializer());
}
Run Code Online (Sandbox Code Playgroud)
在以下网址了解更多信息:跨流程应用程序洞察与多角色应用程序映射
这些值将填充在后端,并指定Application Insights资源详细信息,因此无法更改.
您正在寻找的是自定义尺寸.
例如,发送遥测:
EventTelemetry telemetry = new EventTelemetry("my custom event");
telemetry.Properties.Add("MyApp", "HelloWorld");
telemetryClient.TrackEvent(telemetry);
Run Code Online (Sandbox Code Playgroud)
要查询这些自定义维度:
customEvents
| where customDimensions['MyApp'] == "HelloWorld"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2176 次 |
| 最近记录: |