-
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?
Conversation
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.
Can you give an example of these categories? Are they regular ILogger categories?
If so, we should use built in filtering with Microsoft.Extensions.Logging. We can either transform configuration, or we can simply call:
Part 1: log level filter
// condition on if this is the right sku
services.AddOptions<LoggerFilterOptions>()
.Configure<IConfiguration>((options, config) =>
{
string setting = config[EnvironmentSettingNames.AzureMonitorCategories];
options.AddFilter<AzureMonitorDiagnosticLoggerProvider>((category, level) =>
{
// return false when AzureMonitorCategories does not contain FunctionAppLogs
});
});
Part 2: IsEnabled update
// AzureMonitorDiagnosticLogger.cs
// Update the below method to return false when AzureMonitorCategories does not contain FunctionAppLogs
public bool IsEnabled(LogLevel logLevel)
{
// We want to instantiate this Logger in placeholder mode to warm it up, but do not want to log anything.
return !string.IsNullOrEmpty(_hostNameProvider.Value) && !_environment.IsPlaceholderModeEnabled();
}
Although I have to ask - who sets EnvironmentSettingNames.AzureMonitorCategories
? Is it from the platform, or does the user explicitly set it?
I agree with @jviau that providing more context about the scenario would be beneficial. |
369f120
to
396bf40
Compare
I have removed all the changes. We already have category filter in the host code. I just had to called it in isenabled class |
@manikantanallagatla I believe you will need to also add the filter callback I suggested. It may seem redundant but they have different purposes:
I also am wondering about the Also this change will affect all skus - is the behavior of that env variable consistent across all skus? |
6f22843
to
14d46af
Compare
}); | ||
}); | ||
} | ||
else |
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.
If we put this in else
, would the provider still gets added as a singleton.
@@ -54,6 +54,10 @@ public AzureMonitorDiagnosticLogger(string category, string hostInstanceId, IEve | |||
|
|||
public bool IsEnabled(LogLevel logLevel) | |||
{ | |||
if (_environment.IsLegionBasedSku() && !_environment.IsAzureMonitorEnabled(useCache:true)) | |||
{ |
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.
Did we validate the logs are not being emitted in placeholder mode..
if (useCache && isAzureMonitorLogsSubscribed != null) | ||
{ | ||
return isAzureMonitorLogsSubscribed.Value; | ||
} |
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.
Can this impact other SKUs? should we scope down these changes only to Legion.
/// </summary> | ||
/// <param name="environment">The environment to verify.</param> | ||
/// <returns><see cref="true"/> if running on legion, false otherwise.</returns> | ||
public static bool IsLegionBasedSku(this IEnvironment environment) |
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.
we already have a method called IsConsumptionOnLegion
which we can use instead of adding new method
Issue describing the changes in this PR
For a few SKUs in functions, we want to filter azure monitor logs based on the categories subscribed by the user. This PR checks for the env variable for the categories and skips logging.
Pull request checklist
IMPORTANT: Currently, changes must be backported to the
in-proc
branch to be included in Core Tools and non-Flex deployments.in-proc
branch is not requiredrelease_notes.md
Additional information
Additional PR information