Azure Function is not logging LogMetric telemetry to Application Insights

雨燕双飞 提交于 2020-02-06 10:02:07

问题


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.

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.

Look.


Now look at these curious logs.

...see those n/a that match the LogMetric lines in my code?


And when I search explicitly for one of them, nothing is found.


And if I drill down on those n/a logs.

...they're pretty empty.


Is it me or is this all rather fishy?

How do I log metrics from a Function in a way that works?


回答1:


First, for the metric, do you mean custom metrics? If yes, then you should find it in the customMetrics table in your app insights.

Second, what's the method are you using to send metrics? From your code, what's the implementation of this.Logger?.LogMetric method?

For sending metrics, you can use TrackMetric(just tested with this method, and works) or GetMetric method.

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();


来源:https://stackoverflow.com/questions/57810950/azure-function-is-not-logging-logmetric-telemetry-to-application-insights

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!