ApplicationInsightsRiderPlugin icon indicating copy to clipboard operation
ApplicationInsightsRiderPlugin copied to clipboard

Support (isolated) Azure Functions

Open surumadurum opened this issue 2 years ago • 8 comments

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

surumadurum avatar Jul 01 '22 09:07 surumadurum

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

henrikskak avatar Sep 14 '22 14:09 henrikskak

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 ?

Socolin avatar Sep 14 '22 15:09 Socolin

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

henrikskak avatar Sep 16 '22 10:09 henrikskak

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

rafaelmtz avatar Jun 14 '23 02:06 rafaelmtz

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

Socolin avatar Jun 14 '23 03:06 Socolin

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

rafaelmtz avatar Jun 14 '23 15:06 rafaelmtz

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.

Socolin avatar Jun 14 '23 16:06 Socolin

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

mariomeyrelles avatar Dec 27 '23 20:12 mariomeyrelles