27
27
LoggingHandler ,
28
28
LogRecordProcessor ,
29
29
)
30
- from opentelemetry .semconv .trace import SpanAttributes
30
+ from opentelemetry .semconv ._incubating .attributes import code_attributes
31
+ from opentelemetry .semconv .attributes import exception_attributes
31
32
from opentelemetry .trace import INVALID_SPAN_CONTEXT
32
33
33
34
@@ -127,17 +128,19 @@ def test_log_record_user_attributes(self):
127
128
self .assertEqual (len (log_record .attributes ), 4 )
128
129
self .assertEqual (log_record .attributes ["http.status_code" ], 200 )
129
130
self .assertTrue (
130
- log_record .attributes [SpanAttributes . CODE_FILEPATH ].endswith (
131
+ log_record .attributes [code_attributes . CODE_FILE_PATH ].endswith (
131
132
"test_handler.py"
132
133
)
133
134
)
134
135
self .assertEqual (
135
- log_record .attributes [SpanAttributes . CODE_FUNCTION ],
136
+ log_record .attributes [code_attributes . CODE_FUNCTION_NAME ],
136
137
"test_log_record_user_attributes" ,
137
138
)
138
139
# The line of the log statement is not a constant (changing tests may change that),
139
140
# so only check that the attribute is present.
140
- self .assertTrue (SpanAttributes .CODE_LINENO in log_record .attributes )
141
+ self .assertTrue (
142
+ code_attributes .CODE_LINE_NUMBER in log_record .attributes
143
+ )
141
144
self .assertTrue (isinstance (log_record .attributes , BoundedAttributes ))
142
145
143
146
def test_log_record_exception (self ):
@@ -156,15 +159,15 @@ def test_log_record_exception(self):
156
159
self .assertTrue (isinstance (log_record .body , str ))
157
160
self .assertEqual (log_record .body , "Zero Division Error" )
158
161
self .assertEqual (
159
- log_record .attributes [SpanAttributes .EXCEPTION_TYPE ],
162
+ log_record .attributes [exception_attributes .EXCEPTION_TYPE ],
160
163
ZeroDivisionError .__name__ ,
161
164
)
162
165
self .assertEqual (
163
- log_record .attributes [SpanAttributes .EXCEPTION_MESSAGE ],
166
+ log_record .attributes [exception_attributes .EXCEPTION_MESSAGE ],
164
167
"division by zero" ,
165
168
)
166
169
stack_trace = log_record .attributes [
167
- SpanAttributes .EXCEPTION_STACKTRACE
170
+ exception_attributes .EXCEPTION_STACKTRACE
168
171
]
169
172
self .assertIsInstance (stack_trace , str )
170
173
self .assertTrue ("Traceback" in stack_trace )
@@ -189,15 +192,15 @@ def test_log_record_recursive_exception(self):
189
192
self .assertIsNotNone (log_record )
190
193
self .assertEqual (log_record .body , "Zero Division Error" )
191
194
self .assertEqual (
192
- log_record .attributes [SpanAttributes .EXCEPTION_TYPE ],
195
+ log_record .attributes [exception_attributes .EXCEPTION_TYPE ],
193
196
ZeroDivisionError .__name__ ,
194
197
)
195
198
self .assertEqual (
196
- log_record .attributes [SpanAttributes .EXCEPTION_MESSAGE ],
199
+ log_record .attributes [exception_attributes .EXCEPTION_MESSAGE ],
197
200
"division by zero" ,
198
201
)
199
202
stack_trace = log_record .attributes [
200
- SpanAttributes .EXCEPTION_STACKTRACE
203
+ exception_attributes .EXCEPTION_STACKTRACE
201
204
]
202
205
self .assertIsInstance (stack_trace , str )
203
206
self .assertTrue ("Traceback" in stack_trace )
@@ -219,12 +222,14 @@ def test_log_exc_info_false(self):
219
222
220
223
self .assertIsNotNone (log_record )
221
224
self .assertEqual (log_record .body , "Zero Division Error" )
222
- self .assertNotIn (SpanAttributes .EXCEPTION_TYPE , log_record .attributes )
223
225
self .assertNotIn (
224
- SpanAttributes .EXCEPTION_MESSAGE , log_record .attributes
226
+ exception_attributes .EXCEPTION_TYPE , log_record .attributes
227
+ )
228
+ self .assertNotIn (
229
+ exception_attributes .EXCEPTION_MESSAGE , log_record .attributes
225
230
)
226
231
self .assertNotIn (
227
- SpanAttributes .EXCEPTION_STACKTRACE , log_record .attributes
232
+ exception_attributes .EXCEPTION_STACKTRACE , log_record .attributes
228
233
)
229
234
230
235
def test_log_record_exception_with_object_payload (self ):
@@ -246,15 +251,15 @@ def __str__(self):
246
251
self .assertTrue (isinstance (log_record .body , str ))
247
252
self .assertEqual (log_record .body , "CustomException stringified" )
248
253
self .assertEqual (
249
- log_record .attributes [SpanAttributes .EXCEPTION_TYPE ],
254
+ log_record .attributes [exception_attributes .EXCEPTION_TYPE ],
250
255
CustomException .__name__ ,
251
256
)
252
257
self .assertEqual (
253
- log_record .attributes [SpanAttributes .EXCEPTION_MESSAGE ],
258
+ log_record .attributes [exception_attributes .EXCEPTION_MESSAGE ],
254
259
"CustomException message" ,
255
260
)
256
261
stack_trace = log_record .attributes [
257
- SpanAttributes .EXCEPTION_STACKTRACE
262
+ exception_attributes .EXCEPTION_STACKTRACE
258
263
]
259
264
self .assertIsInstance (stack_trace , str )
260
265
self .assertTrue ("Traceback" in stack_trace )
0 commit comments