GoogleCloudPlatform/functions-framework-dotnet

Scopes for request are lost

Closed this issue · 0 comments

Create a simple function with logging:

using Google.Cloud.Functions.Framework;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using System.Threading.Tasks;

namespace LoggingFunction;

public class Function : IHttpFunction
{
    private readonly ILogger logger;

    public Function(ILogger<Function> logger)
    {
        this.logger = logger;
    }
    
    public async Task HandleAsync(HttpContext context)
    {
        logger.LogInformation("From HandleAsync");
        await context.Response.WriteAsync("Hello, Functions Framework.");
    }
}

Now run it and we get logs of:

2024-04-30T11:36:50.298Z [Microsoft.AspNetCore.Hosting.Diagnostics] [info] Request starting HTTP/1.1 GET http://127.0.0.1:8080/ - -
Scopes: [{ RequestId: 0HN39179MKOLU:00000002, RequestPath: / }]
2024-04-30T11:36:50.304Z [LoggingFunction.Function] [info] From HandleAsync
2024-04-30T11:36:50.320Z [Microsoft.AspNetCore.Hosting.Diagnostics] [info] Request finished HTTP/1.1 GET http://127.0.0.1:8080/ - - - 200 - - 24.0673ms
Scopes: [{ RequestId: 0HN39179MKOLU:00000002, RequestPath: / }]

Why do we not have the RequestId and RequestPath scopes in the log entry? I'd expect those to be scopes that propagate throughout the request. (A minimal API app certainly gets those scopes...)