-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loguru Attribute Instrumentation (#1025)
* Add tests for logging's json logging * Upgrade record_log_event to handle dict logging * Update logging to capture dict messages * Add attributes for dict log messages * Implementation of JSON message filtering * Correct attributes only log behavior * Testing for logging attributes * Add logging context test for py2 * Logically separate attribute tests * Clean out imports * Fix failing tests * Structlog cleanup * Attempting list instrumentation * Structlog attributes support Co-authored-by: Lalleh Rafeei <lrafeei@users.noreply.github.com> Co-authored-by: Uma Annamalai <umaannamalai@users.noreply.github.com> * Loguru instrumentation refactor * New attribute testing * Move exception settings * Clean up testing * Remove unneeded option * Remove other framework changes * [Mega-Linter] Apply linters fixes * Bump tests --------- Co-authored-by: Lalleh Rafeei <lrafeei@users.noreply.github.com> Co-authored-by: Uma Annamalai <umaannamalai@users.noreply.github.com> Co-authored-by: TimPansino <TimPansino@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
f60c29f
commit 92cca1e
Showing
5 changed files
with
91 additions
and
135 deletions.
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.