Giter Club home page Giter Club logo

Comments (13)

xiaomi7732 avatar xiaomi7732 commented on May 10, 2024 1

Okay, give it a deep look. There are 2 issues.

  1. The instructions to enable self-diagnostics for ApplicationInsights.Kubernetes needs to be updated because of the way config logger provider changes. @PeterRockstars basically nailed the solution. I'll update the document to reflect the changes. One side note is that in HomeController, dependency injection upon ILogger<> than ILoggerFactory is more recommended:
    public HomeController(ILogger<HomeController> logger)
    {
        _logger = logger;
        _logger.LogTrace("TRACE");
    }

That should address @mumarniaz 's issue.

  1. @PeterRockstars is looking for more logs - logs from the real application insights library. If I understand it correct, you are looking for additional entries like it below:
Application Insights Telemetry: {"name":"Microsoft.ApplicationInsights.Dev.5789ad108b394f8a88dc632d1342d5e0.Message","time":"2018-01-03T23:48:52.4627170Z","iKey":"i-do-not-tell-you-my-ikey","tags":{"ai.application.ver":"1.0.0.0","ai.user.id":"ldoLQ","ai.operation.parentId":"|c2390d17-42b31bbca592ecb8.","ai.operation.id":"c2390d17-42b31bbca592ecb8","ai.cloud.roleInstance":"my-machine-name","ai.internal.sdkVersion":"aspnet5c:2.1.1","ai.location.ip":"::1","ai.internal.nodeName":"xxx","ai.operation.name":"GET /lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2","ai.session.id":"1rbWZ"},"data":{"baseType":"MessageData","baseData":{"ver":2,"message":"The file /lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2 was not modified","severityLevel":"Information","properties":{"Path":"/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2","AspNetCoreEnvironment":"Development","CategoryName":"Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware","DeveloperMode":"true","{OriginalFormat}":"The file {Path} was not modified"}}}}

I think that is totally reasonable during the diagnostic session, you want to see all the way till temelemtry is actually sent, that is, however, not within control of AI.Kubernetes. To make the scenario work in ASP.NET Core 2.0, this work item needs to be addressed first in AI.Aspnetcore:
microsoft/ApplicationInsights-aspnetcore#536 as an active work item.

from applicationinsights-kubernetes.

d3r3kk avatar d3r3kk commented on May 10, 2024

Perhaps (as this document is a draft from back in May) this API has changed.

I found this article that suggests that your ConfigureLogging line would be changed to:

.ConfigureLogging(f => f.AddConsole(), Microsoft.Extensions.Logging.LogLevel.Trace)

... and you can choose from log level values here.

[Edit: Formatting]

from applicationinsights-kubernetes.

mumarniaz avatar mumarniaz commented on May 10, 2024

Thanks @d3r3kk
But this won't work because ConfigureLogging fucntion is expecting only one parameter of type Action

from applicationinsights-kubernetes.

brahmnes avatar brahmnes commented on May 10, 2024

In ASP.NET core 2.0, it looks like ConfigureLogging has changed from taking Action<ILoggingFactory> to
Action<ILoggingBuilder>.

Here is the new AddConsole method
https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.logging.consoleloggerextensions.addconsole?view=aspnetcore-2.0#Microsoft_Extensions_Logging_ConsoleLoggerExtensions_AddConsole_Microsoft_Extensions_Logging_ILoggingBuilder_

You should be able to do this:
.ConfigureLogging(f => f.AddConsole(Microsoft.Extensions.Logging.LogLevel.Trace))

from applicationinsights-kubernetes.

PeterRockstars avatar PeterRockstars commented on May 10, 2024

@brahmnes That doesn't work, as AddConsole(ILoggerFactory, LogLevel) takes an ILoggerFactory, not an ILoggingBuilder..
I'm struggling with the same thing. How do I get to the ILoggerFactory?

from applicationinsights-kubernetes.

PeterRockstars avatar PeterRockstars commented on May 10, 2024

This seems to work, sort-of:

.ConfigureLogging(builder => builder
        .SetMinimumLevel(LogLevel.Trace)
        .AddConsole())

It gives me trace output when I do this:

public HomeController(ILoggerFactory loggerFactory)
   {
     _logger = loggerFactory.CreateLogger<HomeController>();
     _logger.LogTrace("TRACE");
   }

But it doesn't show any of the App Insights logging shown in the example. Curiously, I do see that output in the debug window in Visual Studio.

from applicationinsights-kubernetes.

brahmnes avatar brahmnes commented on May 10, 2024

Did you add the call to UseApplicationInsights()?

from applicationinsights-kubernetes.

PeterRockstars avatar PeterRockstars commented on May 10, 2024

@brahmnes Yes, I did.

It seems that in this line:

ILoggerFactory loggerFactory = (ILoggerFactory)services.FirstOrDefault(s => s.ServiceType == typeof(ILoggerFactory))?.ImplementationInstance;

The ImplementationInstance field is null

from applicationinsights-kubernetes.

brahmnes avatar brahmnes commented on May 10, 2024

Hi Peter,

Application Insights needs to be configured with the LoggerFactory, otherwise ILogger isn't aware of Application Insights. Here is a related post: https://stackoverflow.com/questions/45022693/using-application-insights-with-iloggerfactory

The extension method AddApplicationInsights is in Microsoft.ApplicationInsights.AspNetCore

from applicationinsights-kubernetes.

xiaomi7732 avatar xiaomi7732 commented on May 10, 2024

There are break changes in the configuration settings for ASP.NET Core 2.0. We shall update the library to support it better. I'll look into this issue post 1.0.0-beta2

from applicationinsights-kubernetes.

PeterRockstars avatar PeterRockstars commented on May 10, 2024

@xiaomi7732 Thanks for the deep look, glad we got it figured out. And you're absolutely right on point 2, that is what I was looking for.

from applicationinsights-kubernetes.

xiaomi7732 avatar xiaomi7732 commented on May 10, 2024

@PeterRockstars Thank you for the confirm!

from applicationinsights-kubernetes.

xiaomi7732 avatar xiaomi7732 commented on May 10, 2024

Guys, thanks for raising the issue. The wiki has been updated to provide an example for ASP.NET Core 2.0 Web Apps to enable self-diagnostics.
https://github.com/Microsoft/ApplicationInsights-Kubernetes/wiki/%5BAdvanced%5D-How-to-enable-self-diagnostics-for-ApplicationInsights.Kubernetes

I am closing this issue since there is no more action could be taken in this repo. Please keep an eye on the issue of AI.AspNetCore mentioned above.

from applicationinsights-kubernetes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.