gpt4 book ai didi

azure - 从 Azure Function App 将自定义跟踪消息写入 Application Insight

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

我正在开发 Azure Function App,希望添加自定义消息/跟踪,以帮助调试和提高性能。这是我正在使用的代码:

var telemetry = new Microsoft.ApplicationInsights.TelemetryClient();
telemetry.TrackTrace("Alert Button Pressed by Device ->"+CloudObject.A, SeverityLevel.Warning,new Dictionary<string, string> { { "IoT Object", IOTMESSAGE } });

但是当我转到 Application Insight 和查询跟踪(全部)时,我没有看到我正在设置的跟踪消息。

我做错了什么吗?

最佳答案

我用相同的代码重现并得到了预期的结果,如下:

 [FunctionName("Function1")]
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
string name = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
.Value;
var telemetry = new TelemetryClient();
telemetry.TrackEvent("Loading HomeController-Index View");
telemetry.TrackTrace("Alert Button Pressed by Device ->" + CloudObject.A, SeverityLevel.Warning, new Dictionary<string, string> { { "IoT Object", IOTMESSAGE } });
if (name == null)
{
// Get request body
dynamic data = await req.Content.ReadAsAsync<object>();
name = data?.name;
}

return name == null
? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
: req.CreateResponse(HttpStatusCode.OK, "Hello " + name);
}

应用洞察:

https://i.imgur.com/vWEqPNu.png

查询跟踪:

enter image description here

关于azure - 从 Azure Function App 将自定义跟踪消息写入 Application Insight,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74593584/

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