-
Notifications
You must be signed in to change notification settings - Fork 192
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
Net7 Isolated Functions Logging - Console not working, AppInsights almost working #1415
Comments
You can disable dependency logging like this:
|
Thank Ben, we've tried the setting above with no luck, we're still seeing large numbers of dependency logs in App Insights. We'll keep trying to see if we can stop them. |
@RichardBurns1982 -- first, please update to the latest preview4 in your worker. It fixes the console logging. Second, can you share an example of one of these dependency telemetry? That can help track down where they're coming from. Please include the custom dimensions and It's possible they're coming from the host. You can completely turn off dependency tracking in the host via host.json: https://learn.microsoft.com/en-us/azure/azure-functions/functions-host-json#applicationinsights. (see logging -> applicationInsights -> enableDependencyTracking) |
@brettsam Thanks for responding, we will try preview4. One dependency example:
|
@brettsam Still no luck, we upgraded to preview4 of the app insights and console logging still not working. When you said this is fixed was there any additional config changes needed? I tried not registering app insights locally when running in development and just call builder.AddConsole() and still no debug messages will appear on the console. Only warning, error and critical. This was never a problem on in-process in net6, all worked without issue so something has changed. |
OK, I've managed to get this working again locally. I have changed the local.settings.json to override the Function loglevel like so:
I have also had to modify our local configuration loaded from user secrets to include a logging section like so:
I have also had to change our ConfigureLogging to look like this:
Once all of this is done we are now seeing the console logging locally we were seeing before moving to .net7 Isolated. |
@RichardBurns1982 we're reviewing what you've shared and some of the steps above seem unnecessary. Would you be able to share your repro in a repo so we can take a look at the code there? |
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. |
@fabiocav Repo here: https://github.com/RichardBurns1982/azure-functions-issue-1415 Unless all steps mentioned above are included debug messages are not shown in console |
@RichardBurns1982
These lines are redundant. "Host" (dotnet 'host' config concept not functions 'host' or host.json) configuration is automatically chained into "app" configuration (your first app config source should be What I recommend is to add an .ConfigureAppConfiguration((hostContext, builder) =>
{
builder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true or false)
.AddJsonFile($"appsettings.{hostContext.HostingEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true or false);
}); You can then add your worker specific logging config to |
As for your concern with the dependency telemetry when using our application insights package, this is the point of our package. You have a couple options available to you to avoid these telemetry items:
|
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. |
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. |
@jviau Thank you for the responses. I have tried the following: Changed to use Host.CreateDefaultBuilder() This did work locally for debugging but when deployed to Azure app insights exploded with logs from host.result (over 100k in 15 minutes). But if we set the logging:logLevel in host.json it stops the local debug messages unless we set:
It feels like the log levels we are trying to set in appsettings.json (or from user secrets) are competing with the log levels we set in host.json. Does this sound right that host.json is overriding what we have set in appsettings.json or user secrets locally when debugging. We don't want to change host.json. I'll continue to experiment with this but appreciate any insights. From initial testing it seems the call to Host.CreateDefaultBuilder() which calls many logging extensions (Console, Debug, etc.) is causing app insights to explode with trace messages, etc. |
You will want to set log levels in both For log levels when using the app insights package, they don't override each other - they are separate packages. |
Thanks @jviau I will update the repo with the problem we are seeing. If we swap to Host.CreateDefaultBuilder() then when deployed to Azure App Insights begins filling up with a lot of TRACE messages. We can stop these by setting host.json to:
But doing this stops all logging below Warning locally when we are debugging unless we set:
Our goal is that locally developers can turn logging on and off simply by changing their user secrets with no need to edit either host.json or appsettings.json. I will try to get the repo updated this morning, failing that it will be early next week. Many thanks again for all your help. |
@RichardBurngs1982 there are a couple tools you can make use of here:
|
I am dealing with the same problem right now, figuring out how to configure console logs in the same way as we can with application insights logs. using It appears that appsettings.json and the host.json both filter console logs? In order for a log to reach the console, it must pass the appsettings.json filter, with the Category defined inside the isolated host (I.E. Based on this, I think the best viable solution is to set I think an ideal solution would avoid this double-filtering altogether, so that logs from the isolated dotnet process (ILogger / ILoggerFactory) are filtered only once by the categories configured in appsettings.json, regardless of logging configured in host.json. Then delivered directly to the console. I believe that this is how the logs are delivered to app insights when using I will note that the solution of setting
https://learn.microsoft.com/en-us/azure/azure-functions/functions-develop-local#local-settings-file This is what I'm observing, via a few test cases: Case 1Setup:
Result: Case 2Setup:
Result: Case 3Setup:
Result: Case 4Setup:
Result: Program.cs setupThis is my host builder configuration: public static class Program
{
private static void Main(string[] args)
{
var host = Host.CreateDefaultBuilder()
.ConfigureFunctionsWorkerDefaults(builder =>
{
builder
.AddApplicationInsights()
.AddApplicationInsightsLogger();
})
// below commented out code has been replaced with Host.CreateDefaultBuilder, it performs all of these functions
// .ConfigureLogging((builder, logging) => {
// // this ensures that the logging configuration is loaded from appsettings.json. this is not the default in function apps apparently.
// // in web apps this gets set via the HostApplicationBuilder constructor, HostingHostBuilderExtensions.cs : AddDefaultServices
// logging.AddConfiguration(builder.Configuration.GetSection("Logging"));
// logging.AddConsole();
// })
// .ConfigureAppConfiguration((hostBuilder, cfg) =>
// {
// cfg
// .AddJsonFile("appsettings.json")
// .AddJsonFile($"appsettings.{hostBuilder.HostingEnvironment.EnvironmentName}.json")
// .AddEnvironmentVariables();
//
// if (hostBuilder.HostingEnvironment.IsDevelopment())
// {
// cfg.AddUserSecrets(Assembly.GetExecutingAssembly());
// }
// })
.ConfigureServices((hostBuilder, services) =>
{
services.Configure<FeatureFlags>(
hostBuilder.Configuration.GetSection(FeatureFlags.FeatureFlagsId));
})
.Build();
host.Run();
}
} This is how my function's logger is set up: namespace MyFunctions.SayHello;
public class SayHelloActivity
{
public class Request
{
public required string Greeting { get; set; }
public required string Subject { get; set; }
}
public class Response
{
public required string Message { get; set; }
}
private readonly ILogger logger;
public SayHelloActivity(ILoggerFactory loggerFactory)
{
logger = loggerFactory.CreateLogger<SayHelloActivity>();
}
[Function(nameof(SayHelloActivity))]
public Response Run([ActivityTrigger] Request request, FunctionContext executionContext)
{
logger.LogInformation("EXECUTING {Function} triggered log", nameof(SayHelloActivity));
logger.LogCritical("{Severity} saying hello for \\n Name: {RequestSubject} \\n greet: {RequestGreeting}", "critical", request.Subject, request.Greeting);
logger.LogError("{Severity} saying hello for \\n Name: {RequestSubject} \\n greet: {RequestGreeting}", "error", request.Subject, request.Greeting);
logger.LogWarning("{Severity} saying hello for \\n Name: {RequestSubject} \\n greet: {RequestGreeting}", "warning", request.Subject, request.Greeting);
logger.LogInformation("{Severity} saying hello for \\n Name: {RequestSubject} \\n greet: {RequestGreeting}", "information", request.Subject, request.Greeting);
logger.LogTrace("{Severity} saying hello for \\n Name: {RequestSubject} \\n greet: {RequestGreeting}", "trace", request.Subject, request.Greeting);
logger.LogDebug("{Severity} saying hello for \\n Name: {RequestSubject} \\n greet: {RequestGreeting}", "debug", request.Subject, request.Greeting);
return new Response
{
Message = $"Hello {request.Greeting} {request.Subject}!"
};
}
} |
A side effect of this appears to be that there is no way to filter these types of logs out:
while retaining Information-level logs from |
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. |
Closed without a resolution? This seems to be becoming more common these days... |
@joeyeng this is now a "solved" problem 😁 Please lookup #1182 where I illustrate how to reliably have full control on your logging experience in your function apps running as an isolated worker process. |
We have just migrated from net6 in-process to net7 isolated and the logging is a proving extremely challenging. We have two use cases:
Our setup is as follows:
host.json:
Code:
I'll start with AppInsights. We've managed to mostly get this working looking through various other issues that people have raised but we are seeing a lot of Dependency messages logged which we were not seeing before:
You can see when we first deployed ney7 Isolated and we started seeing thousands of dependency messages logged like so:
How do we stop these?
Locally we want to see debug messages but not the noise from the host/functions, just our DI injected ILogger messages, how do we see these as no matter what we try unless we change the host.json default to Debug we don't see anything and if we do that we see everything, including all the noise.
The text was updated successfully, but these errors were encountered: