-
Notifications
You must be signed in to change notification settings - Fork 442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support structured logging from worker #7452
Comments
Moving this to 108 as we're still working with other teams to get feedback and work through the design |
Could you provide us with some time estimates for this fix? It's blocking Azure/azure-functions-dotnet-worker#423 and it seems this bug is being constantly postponed. |
@kjeske we're still working on some design/open questions and the issue is primarily tracking that work at the moment. When we have more details and start on implementation, we'll be in a better position to provide an ETA |
This comment was marked as off-topic.
This comment was marked as off-topic.
@fabiocav, any update on this? This is quite a crucial feature in our use case. Is there an alternative you could suggest for the time being? |
As a workaround, I thought of adding a custom logger factory to DI that would create an ILogger that doesn't flow through the host GRPC channel and would connect directly to Insights. In theory it should work, but we would loose all console and stream logs in Azure and local dev and would be forced to rely on Insights for ANY diagnostics. If we try to keep the connection to GRPC, to also show in the stream logs, Insights would get duplicated entries with and without the structured information. It should work, but I didn't have the time to try and test it yet. This NEEDS to be FIXED soon. It is a very serious bug. From the looks of it, I'm worried that it might only happen for .NET 7, but that would be a serious case of not giving enough importance to very important community feedback. This specific issue is already 7 months old, and it was not the first on this problem. If the intention really is to have only isolated process in .NET 7, as the roadmap suggests, EVERYTHING that work in process will need to work in isolated, including structured logs. Please make it available as a fix in 6, not only in 7! |
I'm thinking .NET 8 at the earliest |
Hey guys I have a workaround for structured logging by using serilog, to replace the existing ms logger. |
@fabiocav @brettsam is there any update you can share on this issue? I am conscious that as we approach the release of dotnet 7 the capability to go "all in" on the isolated model will be pushed (in particular the support for durable functions which has made me stay with the in-proc model for now) but not if structured logging is still not working? |
At least an "official" statement regarding the roadmap of this issue would be something. Transparency is key. |
hi @colinrippeyfinarne the durable function support is currently in public preview. https://github.com/Azure/azure-functions-dotnet-worker/projects/2 cc @cgillum |
Had a quick check, we had done the work to pull AppInsights logs directly from Worker -> AppInsights, so it supports anything .NET supports directly Related issue : Feel free to try it out : |
I just tested and it seems that it still doesn't support structured log. I noticed this line in the code But even if I set IncludeScopes to true in the options, it still doesn't work.
Any suggestion? |
Tested with https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.ApplicationInsights/1.0.0-preview3. Still no scoped properties. |
Any plans when this will be working? |
This is broken and prevents using .NET 7 and having any meaningfully useful logs and metrics. PLEASE consider updating execution mode comparison to prevent people wasting their time upgrading and end up breaking logs and dashboards that rely on structured logging and custom metrics. |
Do we have an idea of when this work may be picked up? |
Unfortunately doesn't look like it. The team appears to be focusing on other thinks like Durable Functions and updates to Python experience. Since worker/isolated mode is the way forward for dotnet as well, this will have to be fixed be ready before dotnet 6 goes out of support (12 Nov 2024). Until then, dotnet 6 is supported in the in-process mode which has this working, and it is LTS. Bit less pessimistic view is they may fix this before end of 2023 (or mid 2024 like they did for dotnet 7 in mid 2022?) so people can move to dotnet 8 LTS in time to get out of dotnet 6. |
I was able, through the other issue, to get structured logging to show up in application insights. Here's a snippet on how to get this going. Note that I deployed this on a Windows App Service Plan. Did not try on Linux. class Program
{
static async Task Main(string[] args)
{
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureLogging((context, builder) =>
{
// does not work as per https://github.com/Azure/azure-functions-dotnet-worker/issues/423
//builder.AddApplicationInsights();
var applicationInsightsConnectionString = context.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"];
if (!string.IsNullOrEmpty(applicationInsightsConnectionString))
{
builder.AddApplicationInsights(configureTelemetryConfiguration =>
{
configureTelemetryConfiguration.ConnectionString = applicationInsightsConnectionString;
}, _ => { });
}
})
.Build();
await host.RunAsync();
}
} |
This is the right direction @DOMZE. We have a specific package in preview right now that wraps the default App Insights packages and does this wire-up for you. There's a couple small tweaks it makes, but behind-the-scenes it's basically doing what you're doing there. See this for more details on the App Insights package (including the "docs" in the PR): Azure/azure-functions-dotnet-worker#1263 |
@brettsam Your documentation seems to outline how to use in an application, but not an isolated function. |
@JayAtSherweb -- Once you've set things up with App Insights as mentioned in the docs (specifically, calling
will write the message to the |
@brettsam - This doesn't seem to work with ILogger.BeginScope<TState> however e.g. [Function("Pong")]
public void QueueTrigger([QueueTrigger("ping")] string myQueueItem)
{
using var scope = _logger.BeginScope(new Dictionary<string, object>{ ["A"] = "12345" });
_logger.LogInformation("pong {B}", "12345");
} Has a customDimension.B but no customDimension.A present Edit: By this I mean <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.0.0-preview3" /> |
@p-m-j -- can you make sure to set up App Insights to You can override this with
|
@brettsam works like a charm, cheers |
Thank you @DOMZE !
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
},
"logLevel": {
"MyNamespace.MyClass": "Trace"
}
}
} The logger I get logs if I manually set the log level in code: builder.SetMinimumLevel(LogLevel.Trace); @brettsam from my tests, it also works if I add the package |
@fleed host.json configures the host process so there's not going to be any log categories with your namespaces there. Check out Azure/azure-functions-dotnet-worker#1182 |
I'm marking this issue as "won't fix" because this is all taken care of with the Microsoft.Azure.Functions.Worker.ApplicationInsights package. We've decided that the best approach for the future is to not alter the grpc contract for structured logging and instead support logs that go directly to Application Insights (or any logging solution) from the worker. In other words, instead of:
All logging now relies on the Application Insights SDK to emit telemetry directly from the worker to the App Insights backend, without passing through the host.
There's a bunch of benefits to this:
There are, however, some confusing pieces that folks are still struggling with:
I'm also compiling some specific logging-related samples in a repo to help show full end-to-end repros that hopefully help explain some of the scenarios. One that was written for a specific customer's question about App Insights and some of the verbose logging coming from various SDKs was added here, for example: https://github.com/brettsam/dotnet-isolated-worker-samples/tree/main/ApplicationInsightsFiltering. If there are more questions around this, please let us know and I'll see about adding more clarification. We're ultimately trying to "get out of your way" with some of these changes, but the transition from the old "log through the host" model to this one has introduced some confusion that we're still trying to clear up. |
In .NET core 3, we were able to log traces with custom properties, and at that time, they were logged with the prefix "prop" like ""prop_CustomPropertyName." However, after implementing the above solution in .net 8, it is no longer adding the "prop" prefix. How to add that prefix? |
Hi, |
The .NET worker is getting requests for structured logging from the worker -> host -> app insights. We'll need to update the GRPC contract for this to work.
The text was updated successfully, but these errors were encountered: