-
Notifications
You must be signed in to change notification settings - Fork 458
Filter Azure monitor logs when customer does not subscribe for the categories #10982
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
base: dev
Are you sure you want to change the base?
Changes from all commits
a8cd4b0
c1bc534
f30df7c
39b7f2c
4628bbe
e8a0b4c
81e274f
47d290a
c1823c1
9803480
e3059af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -25,11 +25,13 @@ | |||
using Microsoft.Azure.WebJobs.Script.WebHost.Management; | ||||
using Microsoft.Azure.WebJobs.Script.WebHost.Middleware; | ||||
using Microsoft.Azure.WebJobs.Script.WebHost.Storage; | ||||
using Microsoft.Extensions.Configuration; | ||||
using Microsoft.Extensions.DependencyInjection; | ||||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||||
using Microsoft.Extensions.Hosting; | ||||
using Microsoft.Extensions.Logging; | ||||
using Microsoft.Extensions.Options; | ||||
using static Microsoft.Azure.WebJobs.Script.Utility; | ||||
|
||||
namespace Microsoft.Azure.WebJobs.Script.WebHost | ||||
{ | ||||
|
@@ -91,6 +93,17 @@ public static IHostBuilder AddWebScriptHost(this IHostBuilder builder, IServiceP | |||
loggingBuilder.AddWebJobsSystem<SystemLoggerProvider>(); | ||||
if (environment.IsAzureMonitorEnabled()) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, this is awkward. Going back and forth on this PR and it looks like it is completely unnecessary. We already completely disable AzureMonitor / shoebox by simply not registering the Which means, is this PR even necessary anymore? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup. I looked at this code and tested the flow. Without the PR, the logs are not getting disabled. I think what was happening is that:
In summary, specialization is updating the env variable and we need options monitor on that env variable in order to enable/ disable azure monitor logs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you saying AzureMonitor env variable is set during placeholder mode? I would expect it to be the opposite: no env variable set, logger not registered, specialization brings in the azure monitor variable, but it has no effect. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean: During placeholder mode, WEBSITE_FUNCTIONS_AZUREMONITOR_CATEGORIES env is set to null. it is not set to anything. So, logger is initialized as we are returning true here for null case:
It is also mentioned here that the logger is initialized but the logs are filtered out in placeholder mode: So, specialization updates the env variable but it has no effect of disabling the logs. I think we both are saying samething. As env variable update is not taking effect, we need this PR so we can disable logging when that env variable is set to None. |
||||
{ | ||||
if (environment.IsConsumptionOnLegion()) | ||||
{ | ||||
loggingBuilder.Services.AddOptions<LoggerFilterOptions>() | ||||
.Configure<IOptionsMonitor<AppServiceOptions>>((filters, options) => | ||||
{ | ||||
filters.AddFilter<AzureMonitorDiagnosticLoggerProvider>((category, level) => | ||||
{ | ||||
return options.CurrentValue.IsAzureMonitorLoggingEnabled; | ||||
}); | ||||
}); | ||||
} | ||||
loggingBuilder.Services.AddSingleton<ILoggerProvider, AzureMonitorDiagnosticLoggerProvider>(); | ||||
} | ||||
|
||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any scenario where this could switch from enabled to disabled? I believe that once enabled, it will stay active. Would you like to store the state so that, after activation, all checks can be bypassed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Customer can unsubscribe the categories which they have subscribed in the past. Then, this would go from enabled to disabled.
In PR, I was initially caching the isenabled value. But, the options monitor in essence handles it for us. We are not doing too much computation like string split or something. We are checking env variables in this change. So, again caching over the options monitor is redundant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RohitRanjanMS my understanding of the changes is that this will correctly enable/disable dynamically as the config value is changed (due to the usage of
OptionsMonitor
).With that said, the primary interaction point is an app setting, which when changed will always cause a site restart.
Do you see some issue or concern with how this will enable/disable?