Socolin / ApplicationInsightsRiderPlugin

Rider plugin to see, instantly, in a nice way Application Insights logs.
MIT License
30 stars 2 forks source link

Support (isolated) Azure Functions #14

Open surumadurum opened 2 years ago

surumadurum commented 2 years ago

I do not see the tab when debugging isolated azure functions. Will this be supported in the future?

henrikskak commented 2 years ago

I have the same issue, any chance you can get it working when debugging Azure functions?

Socolin commented 2 years ago

The plugin is only listening to the Debug Output from the attached program. I don't really know how the azure function work since they split it in 2 program.

Maybe you can try to attach to the other process if it's a dotnet one too and see the log are here ?

Also is this working in VS ?

henrikskak commented 2 years ago

No you are right, it also does not work in VS.

rafaelmtz commented 1 year ago

I tried with JetBrains Rider 2023.1.2. It partially works, but there is an issue. It doesn't show information logs, only warning or above.

image

In Azure, it shows the configured level: information logs and above:

image

documentation: https://learn.microsoft.com/en-us/azure/azure-monitor/app/worker-service

Socolin commented 1 year ago

Does thos logs appear in Debug Output tab (in rider, near between Console and Paralell Stacks ?

rafaelmtz commented 1 year ago

Does thos logs appear in Debug Output tab (in rider, near between Console and Paralell Stacks ?

only warning and above with this setting:

image

After testing other settings, I found this one to be working:

image

image

Socolin commented 1 year ago

Then the problem is not in the extension, as I said before it's probably the same in VS. If they appear in VS and not in the extension then I would need to investigate.

mariomeyrelles commented 8 months ago

I believe it works fine. However, Isolated Functions need some configuration. I have been able to do this as follow:


    // references also: https://github.com/devops-circle/Azure-Functions-Logging-Tests/blob/master/Func.Isolated.Net7.With.AI/Program.cs
    HostBuilder()
        .ConfigureAppConfiguration( fun hostContext config ->

            // Add appsettings.json configuration so we can set logging in configuration.
            // Add in example a file called appsettings.json to the root and set the properties to:
            // Build Action: Content
            // Copy to Output Directory: Copy if newer
            //
            // Content:
            // {
            //   "Logging": {
            //     "LogLevel": {
            //       "Default": "Error" // Change this to ie Trace for more logging
            //     }
            //   }
            // }
            //
            // It's important to add json config sources before the call to ConfigureFunctionsWorkerDefaults as this
            // adds environment variables into configuration enabling overrides by azure configuration settings.
            config.AddJsonFile("appsettings.json", optional = true) |> ignore
        )
        .ConfigureOpenApi()
        .ConfigureFunctionsWorkerDefaults(
            fun (builder:IFunctionsWorkerApplicationBuilder) ->

                let shouldUse (context: FunctionContext) =
                    let functionName = context.FunctionDefinition.Name.ToLowerInvariant()
                    (functionName.Contains("swagger")
                    || functionName.Contains("openapi")
                    || functionName.Contains("ping")
                    || functionName.Contains("oauth2")) |> not 

                builder.UseWhen<UserIdMiddleware>(shouldUse)  |> ignore
                builder.UseWhen<TraceContextMiddleware>(shouldUse)  |> ignore
      )        
        .ConfigureServices(
            fun context services ->
                services.AddApplicationInsightsTelemetryWorkerService() |> ignore
                services.ConfigureFunctionsApplicationInsights() |> ignore
                // You will need extra configuration because above will only log per default Warning (default AI configuration) and above because of following line:
                // https://github.com/microsoft/ApplicationInsights-dotnet/blob/main/NETCORE/src/Shared/Extensions/ApplicationInsightsExtensions.cs#L427
                // This is documented here:
                // https://github.com/microsoft/ApplicationInsights-dotnet/issues/2610#issuecomment-1316672650
                // So remove the default logger rule (warning and above). This will result that the default will be Information.
                services.Configure<LoggerFilterOptions>(fun (options:LoggerFilterOptions) ->

                    let toRemove = options.Rules.FirstOrDefault (fun rule ->  rule.ProviderName = "Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider")
                    if toRemove <> null then
                        options.Rules.Remove(toRemove) |> ignore
                    ) |> ignore
            )
        .ConfigureLogging(
            fun hostingContext logging ->
                logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging")) |> ignore
            )
        .Build()
        .Run()

The appsettings.json looks like this:


{
  "Logging": {
    "LogLevel": {
      "Default": "Debug"
    }
  }
}

The plugin responds normally after the changes and seems to be working with Information level:

image