13
13
# limitations under the License.
14
14
15
15
import logging
16
+
16
17
import 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
+ )
17
27
18
28
from newrelic .api .background_task import background_task
19
29
from newrelic .api .time_trace import current_trace
20
30
from 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
26
31
27
32
28
33
def set_trace_ids ():
@@ -33,23 +38,33 @@ def set_trace_ids():
33
38
if trace :
34
39
trace .guid = "abcdefgh"
35
40
41
+
36
42
def exercise_logging (logger ):
37
43
set_trace_ids ()
38
44
39
45
logger .warning ("C" )
40
46
logger .error ("D" )
41
47
logger .critical ("E" )
42
-
48
+
43
49
assert len (logger .caplog .records ) == 3
44
50
45
51
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
+ }
48
63
49
64
_test_logging_inside_transaction_events = [
50
65
{"message" : "C" , "level" : "WARNING" , ** _common_attributes_trace_linking },
51
66
{"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 },
53
68
]
54
69
55
70
@@ -67,9 +82,10 @@ def test():
67
82
_test_logging_outside_transaction_events = [
68
83
{"message" : "C" , "level" : "WARNING" , ** _common_attributes_service_linking },
69
84
{"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 },
71
86
]
72
87
88
+
73
89
@reset_core_stats_engine ()
74
90
def test_logging_outside_transaction (logger ):
75
91
@validate_log_events_outside_transaction (_test_logging_outside_transaction_events )
@@ -96,6 +112,7 @@ def test():
96
112
_test_patcher_application_captured_event = {"message" : "C-PATCH" , "level" : "WARNING" }
97
113
_test_patcher_application_captured_event .update (_common_attributes_trace_linking )
98
114
115
+
99
116
@reset_core_stats_engine ()
100
117
def test_patcher_application_captured (logger ):
101
118
def patch (record ):
@@ -112,9 +129,11 @@ def test():
112
129
113
130
test ()
114
131
132
+
115
133
_test_logger_catch_event = {"level" : "ERROR" } # Message varies wildly, can't be included in test
116
134
_test_logger_catch_event .update (_common_attributes_trace_linking )
117
135
136
+
118
137
@reset_core_stats_engine ()
119
138
def test_logger_catch (logger ):
120
139
@validate_log_events ([_test_logger_catch_event ])
@@ -132,5 +151,5 @@ def throw():
132
151
throw ()
133
152
except ValueError :
134
153
pass
135
-
154
+
136
155
test ()
0 commit comments