-
Notifications
You must be signed in to change notification settings - Fork 110
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
Loguru Attribute Instrumentation #1025
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
4d9c357
Add tests for logging's json logging
TimPansino a7d4208
Upgrade record_log_event to handle dict logging
TimPansino e9c2753
Update logging to capture dict messages
TimPansino 808811a
Add attributes for dict log messages
TimPansino 42d4aa4
Implementation of JSON message filtering
TimPansino 8faf043
Correct attributes only log behavior
TimPansino 0791206
Testing for logging attributes
TimPansino 9409bed
Add logging context test for py2
TimPansino 3006415
Logically separate attribute tests
TimPansino 0e920cf
Clean out imports
TimPansino 3bd9ab8
Fix failing tests
TimPansino a4905f3
Structlog cleanup
TimPansino c20caa3
Attempting list instrumentation
TimPansino 9837634
Structlog attributes support
TimPansino bb3abf8
Loguru instrumentation refactor
TimPansino 55a35b3
New attribute testing
TimPansino 0a58f1e
Move exception settings
TimPansino dff566c
Clean up testing
TimPansino 860eb13
Remove unneeded option
TimPansino 5974d7b
Merge branch 'develop-logging-attributes' into feature-loguru-attrs
TimPansino e19c95b
Remove other framework changes
TimPansino a8ef21a
[Mega-Linter] Apply linters fixes
TimPansino 3d33f45
Bump tests
TimPansino 49967f8
Merge branch 'develop-logging-attributes' into feature-loguru-attrs
TimPansino fd975bd
Merge branch 'develop-logging-attributes' into feature-loguru-attrs
mergify[bot] 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 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 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 was deleted.
Oops, something went wrong.
This file contains 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,70 @@ | ||
# Copyright 2010 New Relic, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from testing_support.validators.validate_log_event_count import validate_log_event_count | ||
from testing_support.validators.validate_log_events import validate_log_events | ||
|
||
from newrelic.api.background_task import background_task | ||
|
||
|
||
@validate_log_events( | ||
[ | ||
{ # Fixed attributes | ||
"message": "context_attrs: arg1", | ||
"context.file": "(name='%s', path='%s')" % ("test_attributes.py", str(__file__)), | ||
"context.function": "test_loguru_default_context_attributes", | ||
"context.extra.bound_attr": 1, | ||
"context.extra.contextual_attr": 2, | ||
"context.extra.global_extra": 3, | ||
"context.extra.kwarg_attr": 4, | ||
"context.patched_attr": 5, | ||
"context.module": "test_attributes", | ||
"context.name": "test_attributes", | ||
} | ||
], | ||
required_attrs=[ # Variable attributes | ||
"context.elapsed", | ||
"context.line", | ||
"context.process", | ||
"context.thread", | ||
], | ||
) | ||
@validate_log_event_count(1) | ||
@background_task() | ||
def test_loguru_default_context_attributes(logger): | ||
def _patcher(d): | ||
d["patched_attr"] = 5 | ||
return d | ||
|
||
bound_logger = logger.bind(bound_attr=1) | ||
bound_logger = bound_logger.patch(_patcher) | ||
with bound_logger.contextualize(contextual_attr=2): | ||
bound_logger.error("context_attrs: {}", "arg1", kwarg_attr=4) | ||
|
||
|
||
@validate_log_events([{"message": "exc_info"}], required_attrs=["context.exception"]) | ||
@validate_log_event_count(1) | ||
@background_task() | ||
def test_loguru_exception_context_attributes(logger): | ||
try: | ||
raise RuntimeError("Oops") | ||
except Exception: | ||
logger.error("exc_info") | ||
|
||
|
||
@validate_log_events([{"context.extra.attr": 1}]) | ||
@validate_log_event_count(1) | ||
@background_task() | ||
def test_loguru_attributes_only(logger): | ||
logger.error("", attr=1) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Just noting a backwards incompatibility here:
This means that these attributes are named differently than before since they are now being prefixed with
extra.
. This makes sense to me but we should have a note in the release notes about this so customers aren't confused.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.
There weren't attributes in any published releases yet. This is changed from an older unreleased PR that was included on the develop branch.