question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom Metrics don't seem to work when using DI with typed ILoggers

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:5
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
j03INTHECLOUDcommented, Aug 19, 2021

Any update on this.

3reactions
brettsamcommented, Aug 23, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ILogger<T>.LogMetric of Azure function is not logging ...
I have checked traces section of transaction search as well as traces and custom metrics of logs. Even host.json file logging configuration ...
Read more >
Application Insights API for custom events and metrics
Use the Application Insights core telemetry API to send custom events and metrics and your own versions of standard telemetry.
Read more >
Application Insights for Worker Service apps (non-HTTP ...
Retrieve an ILogger instance or TelemetryClient instance from the Dependency Injection (DI) container by calling serviceProvider.
Read more >
Configure labels on log-based metrics
All log-based metrics come with some predefined labels: Resource labels: All metrics use a monitored resource object to identify the source of time...
Read more >
Possible to access default logger from environment? - RLlib
Just started looking at ray and it seems cool, though it is hard ... Right now I just use the on_episode_end and sample...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found