Skip to content

Enable debug logging using the PYTHON_ENABLE_DEBUG_LOGGING flag #939

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

Merged
merged 7 commits into from
Jan 14, 2022

Conversation

YunchuWang
Copy link
Member

Description

Per customers' requests to log messages at debug level in their python function code and view them in App Insights, there will be a new field named PYTHON_ENABLE_DEBUG_LOGGING in Function App Settings supported. It will determine whether debug level logs in the customer function code will be recorded to App Insights. When the field is set to 0 or unspecified in the App Settings, debug level logs will not be recorded; when the field is set to 1, debug level logs will be recorded.

Fixes #


PR information

  • The title of the PR is clear and informative.
  • There are a small number of commits, each of which has an informative message. This means that previously merged commits do not appear in the history of the PR. For information on cleaning up the commits in your pull request, see this page.
  • If applicable, the PR references the bug/issue that it fixes in the description.
  • New Unit tests were added for the changes made and CI is passing.

Quality of Code and Contribution Guidelines

Copy link
Member

@vrdmr vrdmr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor changes requested. Overall looks good. :)

from azure_functions_worker.constants import PYTHON_ENABLE_DEBUG_LOGGING


class TestDebugLoggingEnabledFunctions(testutils.WebHostTestCase):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking - didn't you have to update the host.json file for enabling the logging? Or is it enabled by default now?

If yes - Do we need another test where it is not enabled by default and we are still enabling the flag and checking that the new debug log doesn't get logged?

Ideally - there is a potential issue -
If a customer didn't update host.json, but enables the new feature flag, we start sending the logs from our end. This could result the choking of the gRPC channel that we already know about. If we can also get the host.json information from the host (which I think we do get during worker_init), then we can also do some check if we need to actually send the logs at all or not.
Note: Not very important but something to be aware of.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, will add a test case for that. As discussed, the host.json logging filter is set at function level while this flag is at function app level for the shared root logger. It is not possible to define the flag validity if functions have inconsistent log levels in the host.json. Separate investigation/change will be made to warn customers in case of inconsistent host.json log level and PYTHON_ENABLE_DEBUG_LOGGING value being set.

@YunchuWang YunchuWang requested a review from vrdmr January 13, 2022 20:32
@@ -0,0 +1,14 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add this function? Can we just reuse the functions in log_filtering_functions directory?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, will remove

@@ -98,34 +97,22 @@ def check_log_async_logging(self, host_out: typing.List[str]):
self.assertIn('hello info', host_out)
self.assertIn('and another error', host_out)

@unittest.skip("Reverting the debug logs PR as host currently cannot handle"
"apps with lot of debug statements. Reverting PR: "
"azure-functions-python-worker/pull/745")
def test_debug_logging(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need all of these tests if you are already testing this in the test_enable_debug_logging_functions.py? If not, then I guess these can be removed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this is kept for testing flag unset case

@vrdmr vrdmr changed the title Wangbill/enable debug logging Enable debug logging using the PYTHON_ENABLE_DEBUG_LOGGING flag Jan 14, 2022
Copy link
Member

@vrdmr vrdmr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Left minor comments.

self.assertIn('logging error', host_out)


class TestDebugLoggingDisabledFunctions(testutils.WebHostTestCase):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add PyDoc comments to describe what the tests do? That'll help in the future.

self.assertNotIn('logging debug', host_out)


class TestLogFilteringFunctions(testutils.WebHostTestCase):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please change the class name to describe what this test is specifically testing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the same comments of comments.

@YunchuWang YunchuWang merged commit 191c9a0 into dev Jan 14, 2022
@YunchuWang YunchuWang deleted the wangbill/enable-debug-logging branch January 14, 2022 22:05
@YunchuWang YunchuWang restored the wangbill/enable-debug-logging branch January 14, 2022 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants