天蓝色功能应用程序见解中的自定义属性

编程入门 行业动态 更新时间:2024-10-27 00:26:37
本文介绍了天蓝色功能应用程序见解中的自定义属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在Azure Application Insights中监视许多应用程序.在所有这些代码中,我都向事件,跟踪等添加了一些自定义属性,以便可以在门户中进行过滤/分组.

I am monitoring a lot of applications in Azure Application Insights. In all of them I add some custom properties to events, traces etc so I can filter/group in the portal.

是否可以将相同的自定义属性添加到与Azure Functions的内置应用程序洞察集成中?

Is it possible to add the same custom properties to the built in application insight integration with Azure Functions?

已阅读文档,但找不到任何内容.

Have read the documentation but can't find anything about it.

我维护着各种环境中托管的大量应用程序.其中约有15个是Azure函数.我从所有应用程序中通过日志处理程序将遥测发送到同一应用程序见解实例.为了过滤/分组信息,我通过日志处理程序将"CustomerName"和"CustomerInstance"属性自动添加到所有事件.

I maintain a large number of applications hosted in various environments. About 15 of these are Azure Functions. From all my applications I send telemetry to the same application insights instance via a log handler. To filter/group the information I add "CustomerName" and "CustomerInstance" properties to all events automatically via my log handler.

当我从Azure函数获取标准事件时,很难以有用的方式呈现信息并将其与其他事件相关联.通过对功能应用程序的巧妙命名,我可以在分析中解析请求的URL,但不能在门户中解析.

When I get the standard events from an Azure Function it is difficult to present information in a useful way and correlate it with other events. With some clever naming of the function apps I can parse the request url in analytics but not in the portal.

推荐答案

您可以使用 telemetry.Context.Properties.Add()方法显式添加这些自定义属性.

You can add these custom properties explicitly using telemetry.Context.Properties.Add() method.

我使用功能v2进行了演示,如下所示:

I did a demo with function v2 as below:

1.在Visual Studio中创建功能v2

1.Create a function v2 in visual studio

2.然后在Visual Studio中,通过nuget软件包管理器添加 Microsoft.ApplicationInsights 2.8.1(最新版本)

2.Then in the visual studio, add Microsoft.ApplicationInsights 2.8.1(latest version) via nuget package manager

3.在您的Function.cs中,编写以下代码:

3.In your Function.cs, write the following code:

using Microsoft.ApplicationInsights; using Microsoft.Azure.WebJobs; using Microsoft.Extensions.Logging; using System; namespace FunctionApp17 { public static class Function1 { private static string key = System.Environment.GetEnvironmentVariable("APPINSIGHTS_INSTRUMENTATIONKEY",EnvironmentVariableTarget.Process); private static TelemetryClient telemetry = new TelemetryClient() { InstrumentationKey= key }; [FunctionName("Function1")] public static void Run([TimerTrigger("*/10 * * * * *")]TimerInfo myTimer, ILogger log) { if (!telemetry.Context.Properties.ContainsKey("Function_appName")) { telemetry.Context.Properties.Add("Function_appName", "myfuncapp111"); } else { telemetry.Context.Properties["Function_appName"] = "myfuncapp111"; } log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}"); telemetry.TrackEvent("event111"); telemetry.TrackTrace("trace111"); } } }

4.发布到天蓝色,然后在功能应用程序->应用程序设置中,添加检测键:

4.Publish to azure, and in your function app -> Application settings, add the instrumentation key:

5.运行功能应用程序后,导航至应用程序见解->搜索,您可以添加代码中定义的过滤器.

5.After the function app is running, nav to your application insights -> search, you can add your filters which defined in your code.

然后您将看到过滤的消息:

Then you can see the filtered message:

更多推荐

天蓝色功能应用程序见解中的自定义属性

本文发布于:2023-11-15 22:55:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1598690.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:天蓝色   自定义   见解   应用程序   属性

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!