2020from newrelic .api .transaction import current_transaction
2121from testing_support .fixtures import reset_core_stats_engine
2222from 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
23+ from testing_support .validators .validate_log_event_count_outside_transaction import (
24+ validate_log_event_count_outside_transaction ,
25+ )
2426from testing_support .validators .validate_log_events import validate_log_events
2527from testing_support .validators .validate_log_events_outside_transaction import validate_log_events_outside_transaction
2628
@@ -33,23 +35,33 @@ def set_trace_ids():
3335 if trace :
3436 trace .guid = "abcdefgh"
3537
38+
3639def exercise_logging (logger ):
3740 set_trace_ids ()
3841
3942 logger .warning ("C" )
4043 logger .error ("D" )
4144 logger .critical ("E" )
42-
45+
4346 assert len (logger .caplog .records ) == 3
4447
4548
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 }
49+ _common_attributes_service_linking = {
50+ "timestamp" : None ,
51+ "hostname" : None ,
52+ "entity.name" : "Python Agent Test (logger_loguru)" ,
53+ "entity.guid" : None ,
54+ }
55+ _common_attributes_trace_linking = {
56+ "span.id" : "abcdefgh" ,
57+ "trace.id" : "abcdefgh12345678" ,
58+ ** _common_attributes_service_linking ,
59+ }
4860
4961_test_logging_inside_transaction_events = [
5062 {"message" : "C" , "level" : "WARNING" , ** _common_attributes_trace_linking },
5163 {"message" : "D" , "level" : "ERROR" , ** _common_attributes_trace_linking },
52- {"message" : "E" , "level" : "CRITICAL" , ** _common_attributes_trace_linking },
64+ {"message" : "E" , "level" : "CRITICAL" , ** _common_attributes_trace_linking },
5365]
5466
5567
@@ -67,9 +79,10 @@ def test():
6779_test_logging_outside_transaction_events = [
6880 {"message" : "C" , "level" : "WARNING" , ** _common_attributes_service_linking },
6981 {"message" : "D" , "level" : "ERROR" , ** _common_attributes_service_linking },
70- {"message" : "E" , "level" : "CRITICAL" , ** _common_attributes_service_linking },
82+ {"message" : "E" , "level" : "CRITICAL" , ** _common_attributes_service_linking },
7183]
7284
85+
7386@reset_core_stats_engine ()
7487def test_logging_outside_transaction (logger ):
7588 @validate_log_events_outside_transaction (_test_logging_outside_transaction_events )
@@ -96,6 +109,7 @@ def test():
96109_test_patcher_application_captured_event = {"message" : "C-PATCH" , "level" : "WARNING" }
97110_test_patcher_application_captured_event .update (_common_attributes_trace_linking )
98111
112+
99113@reset_core_stats_engine ()
100114def test_patcher_application_captured (logger ):
101115 def patch (record ):
@@ -112,9 +126,11 @@ def test():
112126
113127 test ()
114128
129+
115130_test_logger_catch_event = {"level" : "ERROR" } # Message varies wildly, can't be included in test
116131_test_logger_catch_event .update (_common_attributes_trace_linking )
117132
133+
118134@reset_core_stats_engine ()
119135def test_logger_catch (logger ):
120136 @validate_log_events ([_test_logger_catch_event ])
@@ -132,5 +148,5 @@ def throw():
132148 throw ()
133149 except ValueError :
134150 pass
135-
151+
136152 test ()
0 commit comments