Azure Function未将LogMetric遥测记录到Application Insights中 [英] Azure Function is not logging LogMetric telemetry to Application Insights
问题描述
我在v2 SDK上有一个为期3周的功能,并且使用了现成的App Insights支持,即只需设置环境变量和... magic.
I have a 3-week-old Function on the v2 SDK and uses the out-box App Insights support, i.e. just set the environment variable and ...magic.
我确实读过默认情况下它不会发送 Information 级别的日志到AppInsights,这看起来是正确的,因为我看不到任何信息跟踪,但确实看到了偶尔的错误用我的自定义消息注销.
I did read that by default it doesn't send Information level logs to AppInsights and this looks correct because I can't see any of my information tracing but I do see occasional errors I've logged out with my custom message.
但是对于指标来说,它是坏的.在日志中,我可以看到一些遥测的相似之处.真奇怪.
But for metrics, its broken. I can see some semblance of my telemetry in the logs, sort of. It's strange.
看.
现在看看这些好奇的日志.
Now look at these curious logs.
...看到那些与我的代码中的LogMetric
行匹配的n/a
?
...see those n/a
that match the LogMetric
lines in my code?
当我明确搜索其中之一时,什么也没找到.
And when I search explicitly for one of them, nothing is found.
如果我深入查看这些n/a
日志.
And if I drill down on those n/a
logs.
...它们很空.
是我还是全是鱼?
如何以一种有效的方式记录功能的指标?
How do I log metrics from a Function in a way that works?
推荐答案
首先,对于指标,您是指自定义指标吗?如果是,那么您应该在应用数据洞察的customMetrics
表中找到它.
First, for the metric, do you mean custom metrics? If yes, then you should find it in the customMetrics
table in your app insights.
第二,您使用什么方法发送指标?从您的代码中,this.Logger?.LogMetric
方法的实现是什么?
Second, what's the method are you using to send metrics? From your code, what's the implementation of this.Logger?.LogMetric
method?
对于发送指标,您可以使用 TrackMetric (通过此方法进行测试,并且可以正常运行)或
For sending metrics, you can use TrackMetric(just tested with this method, and works) or GetMetric method.
示例代码使用TrackMetric(不建议使用,但仍可以使用)/GetMetric(推荐)方法:
A sample code use TrackMetric(deprecated, but still can use) / GetMetric(recommended) method:
TelemetryConfiguration.Active.InstrumentationKey = "your key";
TelemetryClient client = new TelemetryClient();
client.TrackMetric("my metric", 60);
client.GetMetric("my metric").TrackValue(89);
client.Flush();
这篇关于Azure Function未将LogMetric遥测记录到Application Insights中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!