azure-webjobs-sdk
azure-webjobs-sdk copied to clipboard
Custom Metrics don't seem to work when using DI with typed ILoggers
Function App v2.0
I am using Dependency Injection via FunctionsStartup, and my services request an ILogger<T>
, which seems to be working for trace-logging, but not for metrics.
I have tried a few different variations of my host.json file to see if it is a problem with my logging filters, but nothing so far has worked. Even when I set the default filter to "Debug", no custom metrics show up in Application Insights.
"logLevel": {
"default": "Debug"
}
I am logging metrics using the LogMetric
extension method on ILogger from the Microsoft.Extensions.Logging NuGet package. This all worked fine before switching over to using an injected ILogger<T> instead of the ILogger supplied in the Run() method.
Interestingly enough, I can see some trace-logs in Application Insights that seem to correspond with my custom metric logs. There are empty messages in the log analytics that have LogLevel Information and customDimensions "prop__Name" and "prop__Value" that are the same as my metrics. So it seems like the actual messages are coming through the filters but are not being correctly identified as being metrics.
cc: @brettsam
This is a bug. We currently only apply the metrics if it comes from our logger that we pass in. We check the category/event pair. When you inject a logger, that category isn't what we expect.
One workaround -- you could request a TelemetryClient
in your class constructor (DI will inject it) and log your metrics directly via that.
Thanks for the update. Looking forward to the fix but trying the workaround meanwhile.
This is a bug. We currently only apply the metrics if it comes from our logger that we pass in. We check the category/event pair. When you inject a logger, that category isn't what we expect.
One workaround -- you could request a
TelemetryClient
in your class constructor (DI will inject it) and log your metrics directly via that.
Hi Bett,
I am trying to use the DI injected TelemetryClient from within my function and when I track an event I am not seeing it in AI anywhere. I have my local settings using the correct key (verified my ILogger is sending telemetry). When I inspect the TelemetryClient instance that gets injected the instrumentation key is empty. Any ideas?
More info (that helped me) about how to use DI for TelemetryClient https://docs.microsoft.com/en-us/azure/azure-monitor/app/asp-net-core
Hey guys, Whats the progress on this? This seems to be a small problem that could have been fixed by now, no? @brettsam
@brettsam is this on a roadmap?
Looking for this too.
Any update on this.
@brettsam - Any updates on this issue? Its been 3+ years 🤷
Hello from 2022 ? any luck, having same problem....