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 ):
@@ -155,15 +158,15 @@ def test_log_record_exception(self):
155
158
self .assertIsNotNone (log_record )
156
159
self .assertEqual (log_record .body , "Zero Division Error" )
157
160
self .assertEqual (
158
- log_record .attributes [SpanAttributes .EXCEPTION_TYPE ],
161
+ log_record .attributes [exception_attributes .EXCEPTION_TYPE ],
159
162
ZeroDivisionError .__name__ ,
160
163
)
161
164
self .assertEqual (
162
- log_record .attributes [SpanAttributes .EXCEPTION_MESSAGE ],
165
+ log_record .attributes [exception_attributes .EXCEPTION_MESSAGE ],
163
166
"division by zero" ,
164
167
)
165
168
stack_trace = log_record .attributes [
166
- SpanAttributes .EXCEPTION_STACKTRACE
169
+ exception_attributes .EXCEPTION_STACKTRACE
167
170
]
168
171
self .assertIsInstance (stack_trace , str )
169
172
self .assertTrue ("Traceback" in stack_trace )
@@ -188,15 +191,15 @@ def test_log_record_recursive_exception(self):
188
191
self .assertIsNotNone (log_record )
189
192
self .assertEqual (log_record .body , "Zero Division Error" )
190
193
self .assertEqual (
191
- log_record .attributes [SpanAttributes .EXCEPTION_TYPE ],
194
+ log_record .attributes [exception_attributes .EXCEPTION_TYPE ],
192
195
ZeroDivisionError .__name__ ,
193
196
)
194
197
self .assertEqual (
195
- log_record .attributes [SpanAttributes .EXCEPTION_MESSAGE ],
198
+ log_record .attributes [exception_attributes .EXCEPTION_MESSAGE ],
196
199
"division by zero" ,
197
200
)
198
201
stack_trace = log_record .attributes [
199
- SpanAttributes .EXCEPTION_STACKTRACE
202
+ exception_attributes .EXCEPTION_STACKTRACE
200
203
]
201
204
self .assertIsInstance (stack_trace , str )
202
205
self .assertTrue ("Traceback" in stack_trace )
@@ -218,12 +221,14 @@ def test_log_exc_info_false(self):
218
221
219
222
self .assertIsNotNone (log_record )
220
223
self .assertEqual (log_record .body , "Zero Division Error" )
221
- self .assertNotIn (SpanAttributes .EXCEPTION_TYPE , log_record .attributes )
222
224
self .assertNotIn (
223
- SpanAttributes .EXCEPTION_MESSAGE , log_record .attributes
225
+ exception_attributes .EXCEPTION_TYPE , log_record .attributes
226
+ )
227
+ self .assertNotIn (
228
+ exception_attributes .EXCEPTION_MESSAGE , log_record .attributes
224
229
)
225
230
self .assertNotIn (
226
- SpanAttributes .EXCEPTION_STACKTRACE , log_record .attributes
231
+ exception_attributes .EXCEPTION_STACKTRACE , log_record .attributes
227
232
)
228
233
229
234
def test_log_record_trace_correlation (self ):
0 commit comments