1313# limitations under the License.
1414
1515import logging
16+
1617import pytest
18+ from testing_support .fixtures import reset_core_stats_engine
19+ from testing_support .validators .validate_log_event_count import validate_log_event_count
20+ from testing_support .validators .validate_log_event_count_outside_transaction import (
21+ validate_log_event_count_outside_transaction ,
22+ )
23+ from testing_support .validators .validate_log_events import validate_log_events
24+ from testing_support .validators .validate_log_events_outside_transaction import (
25+ validate_log_events_outside_transaction ,
26+ )
1727
1828from newrelic .api .background_task import background_task
1929from newrelic .api .time_trace import current_trace
2030from newrelic .api .transaction import current_transaction
21- from testing_support .fixtures import reset_core_stats_engine
22- from testing_support .validators .validate_log_event_count import validate_log_event_count
23- from testing_support .validators .validate_log_event_count_outside_transaction import validate_log_event_count_outside_transaction
24- from testing_support .validators .validate_log_events import validate_log_events
25- from testing_support .validators .validate_log_events_outside_transaction import validate_log_events_outside_transaction
2631
2732
2833def set_trace_ids ():
@@ -33,23 +38,33 @@ def set_trace_ids():
3338 if trace :
3439 trace .guid = "abcdefgh"
3540
41+
3642def exercise_logging (logger ):
3743 set_trace_ids ()
3844
3945 logger .warning ("C" )
4046 logger .error ("D" )
4147 logger .critical ("E" )
42-
48+
4349 assert len (logger .caplog .records ) == 3
4450
4551
46- _common_attributes_service_linking = {"timestamp" : None , "hostname" : None , "entity.name" : "Python Agent Test (logger_loguru)" , "entity.guid" : None }
47- _common_attributes_trace_linking = {"span.id" : "abcdefgh" , "trace.id" : "abcdefgh12345678" , ** _common_attributes_service_linking }
52+ _common_attributes_service_linking = {
53+ "timestamp" : None ,
54+ "hostname" : None ,
55+ "entity.name" : "Python Agent Test (logger_loguru)" ,
56+ "entity.guid" : None ,
57+ }
58+ _common_attributes_trace_linking = {
59+ "span.id" : "abcdefgh" ,
60+ "trace.id" : "abcdefgh12345678" ,
61+ ** _common_attributes_service_linking ,
62+ }
4863
4964_test_logging_inside_transaction_events = [
5065 {"message" : "C" , "level" : "WARNING" , ** _common_attributes_trace_linking },
5166 {"message" : "D" , "level" : "ERROR" , ** _common_attributes_trace_linking },
52- {"message" : "E" , "level" : "CRITICAL" , ** _common_attributes_trace_linking },
67+ {"message" : "E" , "level" : "CRITICAL" , ** _common_attributes_trace_linking },
5368]
5469
5570
@@ -67,9 +82,10 @@ def test():
6782_test_logging_outside_transaction_events = [
6883 {"message" : "C" , "level" : "WARNING" , ** _common_attributes_service_linking },
6984 {"message" : "D" , "level" : "ERROR" , ** _common_attributes_service_linking },
70- {"message" : "E" , "level" : "CRITICAL" , ** _common_attributes_service_linking },
85+ {"message" : "E" , "level" : "CRITICAL" , ** _common_attributes_service_linking },
7186]
7287
88+
7389@reset_core_stats_engine ()
7490def test_logging_outside_transaction (logger ):
7591 @validate_log_events_outside_transaction (_test_logging_outside_transaction_events )
@@ -96,6 +112,7 @@ def test():
96112_test_patcher_application_captured_event = {"message" : "C-PATCH" , "level" : "WARNING" }
97113_test_patcher_application_captured_event .update (_common_attributes_trace_linking )
98114
115+
99116@reset_core_stats_engine ()
100117def test_patcher_application_captured (logger ):
101118 def patch (record ):
@@ -112,9 +129,11 @@ def test():
112129
113130 test ()
114131
132+
115133_test_logger_catch_event = {"level" : "ERROR" } # Message varies wildly, can't be included in test
116134_test_logger_catch_event .update (_common_attributes_trace_linking )
117135
136+
118137@reset_core_stats_engine ()
119138def test_logger_catch (logger ):
120139 @validate_log_events ([_test_logger_catch_event ])
@@ -132,5 +151,5 @@ def throw():
132151 throw ()
133152 except ValueError :
134153 pass
135-
154+
136155 test ()
0 commit comments