-
Notifications
You must be signed in to change notification settings - Fork 107
Adding support for debug logs in executed functions. #745
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4d84483
Adding support for debug logs in executed functions.
vrdmr a0f66c5
Adding tests to see make sure host prevents debug logs
vrdmr ef3b3de
Merge branch 'dev' into vameru/python-worker-in-debug-mode
vrdmr 02185f1
minor; organizing imports and making a protected member as public
vrdmr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,7 +84,7 @@ celerybeat-schedule | |
|
||
# virtualenv (.venv/.venv36/.venv37/.venv38) | ||
.venv* | ||
venv/ | ||
venv*/ | ||
ENV/ | ||
py3env/ | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
tests/unittests/http_functions/debug_logging/function.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"scriptFile": "main.py", | ||
"bindings": [ | ||
{ | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req" | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "$return" | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
import logging | ||
|
||
import azure.functions | ||
|
||
|
||
def main(req: azure.functions.HttpRequest): | ||
logging.info('logging info', exc_info=True) | ||
logging.warning('logging warning', exc_info=True) | ||
logging.debug('logging debug', exc_info=True) | ||
logging.error('logging error', exc_info=True) | ||
return 'OK-debug' |
15 changes: 15 additions & 0 deletions
15
tests/unittests/http_functions/debug_user_logging/function.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"scriptFile": "main.py", | ||
"bindings": [ | ||
{ | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req" | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "$return" | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
import logging | ||
|
||
import azure.functions | ||
|
||
|
||
logger = logging.getLogger('my function') | ||
|
||
|
||
def main(req: azure.functions.HttpRequest): | ||
logger.info('logging info', exc_info=True) | ||
logger.warning('logging warning', exc_info=True) | ||
logger.debug('logging debug', exc_info=True) | ||
logger.error('logging error', exc_info=True) | ||
return 'OK-user-debug' |
15 changes: 15 additions & 0 deletions
15
tests/unittests/log_filtering_functions/debug_logging/function.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"scriptFile": "main.py", | ||
"bindings": [ | ||
{ | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req" | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "$return" | ||
} | ||
] | ||
} |
13 changes: 13 additions & 0 deletions
13
tests/unittests/log_filtering_functions/debug_logging/main.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
import logging | ||
|
||
import azure.functions | ||
|
||
|
||
def main(req: azure.functions.HttpRequest): | ||
logging.info('logging info', exc_info=True) | ||
logging.warning('logging warning', exc_info=True) | ||
logging.debug('logging debug', exc_info=True) | ||
logging.error('logging error', exc_info=True) | ||
return 'OK-debug' |
15 changes: 15 additions & 0 deletions
15
tests/unittests/log_filtering_functions/debug_user_logging/function.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"scriptFile": "main.py", | ||
"bindings": [ | ||
{ | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req" | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "$return" | ||
} | ||
] | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/unittests/log_filtering_functions/debug_user_logging/main.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
import logging | ||
|
||
import azure.functions | ||
|
||
|
||
logger = logging.getLogger('my function') | ||
|
||
|
||
def main(req: azure.functions.HttpRequest): | ||
logger.info('logging info', exc_info=True) | ||
logger.warning('logging warning', exc_info=True) | ||
logger.debug('logging debug', exc_info=True) | ||
logger.error('logging error', exc_info=True) | ||
return 'OK-user-debug' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
import typing | ||
|
||
from azure_functions_worker import testutils | ||
from azure_functions_worker.testutils import TESTS_ROOT, remove_path | ||
|
||
HOST_JSON_TEMPLATE_WITH_LOGLEVEL_INFO = """\ | ||
{ | ||
"version": "2.0", | ||
"logging": { | ||
"logLevel": { | ||
"default": "Information" | ||
} | ||
}, | ||
"functionTimeout": "00:05:00" | ||
} | ||
""" | ||
|
||
|
||
class TestLogFilteringFunctions(testutils.WebHostTestCase): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
host_json = TESTS_ROOT / cls.get_script_dir() / 'host.json' | ||
|
||
with open(host_json, 'w+') as f: | ||
f.write(HOST_JSON_TEMPLATE_WITH_LOGLEVEL_INFO) | ||
|
||
super(TestLogFilteringFunctions, cls).setUpClass() | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
host_json = TESTS_ROOT / cls.get_script_dir() / 'host.json' | ||
remove_path(host_json) | ||
|
||
super(TestLogFilteringFunctions, cls).tearDownClass() | ||
|
||
@classmethod | ||
def get_script_dir(cls): | ||
return testutils.UNIT_TESTS_FOLDER / 'log_filtering_functions' | ||
|
||
def test_debug_logging(self): | ||
r = self.webhost.request('GET', 'debug_logging') | ||
self.assertEqual(r.status_code, 200) | ||
self.assertEqual(r.text, 'OK-debug') | ||
|
||
def check_log_debug_logging(self, host_out: typing.List[str]): | ||
self.assertIn('logging info', host_out) | ||
self.assertIn('logging warning', host_out) | ||
self.assertIn('logging error', host_out) | ||
self.assertNotIn('logging debug', host_out) | ||
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. Great, this explicitly test the scenario on the host logging control side. Thanks for making the change |
||
|
||
def test_debug_with_user_logging(self): | ||
r = self.webhost.request('GET', 'debug_user_logging') | ||
self.assertEqual(r.status_code, 200) | ||
self.assertEqual(r.text, 'OK-user-debug') | ||
|
||
def check_log_debug_with_user_logging(self, host_out: typing.List[str]): | ||
self.assertIn('logging info', host_out) | ||
self.assertIn('logging warning', host_out) | ||
self.assertIn('logging error', host_out) | ||
self.assertNotIn('logging debug', host_out) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.