|
17 | 17 | import sys |
18 | 18 |
|
19 | 19 | from io import StringIO as Buffer |
20 | | -from traceback import format_tb |
| 20 | +from traceback import format_exception |
21 | 21 |
|
22 | 22 | import pytest |
23 | 23 |
|
@@ -237,12 +237,14 @@ def test_newrelic_logger_error_inside_transaction_no_stack_trace(log_buffer): |
237 | 237 |
|
238 | 238 | @background_task() |
239 | 239 | def test_newrelic_logger_error_inside_transaction_with_stack_trace(log_buffer_with_stack_trace): |
240 | | - expected_stack_trace = "" |
241 | 240 | try: |
242 | | - raise ExceptionForTest |
| 241 | + try: |
| 242 | + raise ExceptionForTest("cause") |
| 243 | + except ExceptionForTest: |
| 244 | + raise ExceptionForTest("exception-with-cause") |
243 | 245 | except ExceptionForTest: |
244 | 246 | _logger.exception("oops") |
245 | | - expected_stack_trace = "".join(format_tb(sys.exc_info()[2])) |
| 247 | + expected_stack_trace = "".join(format_exception(*sys.exc_info())) |
246 | 248 |
|
247 | 249 | log_buffer_with_stack_trace.seek(0) |
248 | 250 | message = json.load(log_buffer_with_stack_trace) |
@@ -271,7 +273,7 @@ def test_newrelic_logger_error_inside_transaction_with_stack_trace(log_buffer_wi |
271 | 273 | "thread.name": "MainThread", |
272 | 274 | "process.name": "MainProcess", |
273 | 275 | "error.class": "test_logs_in_context:ExceptionForTest", |
274 | | - "error.message": "", |
| 276 | + "error.message": "exception-with-cause", |
275 | 277 | "error.expected": False |
276 | 278 | } |
277 | 279 | expected_extra_txn_keys = ( |
@@ -331,12 +333,14 @@ def test_newrelic_logger_error_outside_transaction_no_stack_trace(log_buffer): |
331 | 333 |
|
332 | 334 |
|
333 | 335 | def test_newrelic_logger_error_outside_transaction_with_stack_trace(log_buffer_with_stack_trace): |
334 | | - expected_stack_trace = "" |
335 | 336 | try: |
336 | | - raise ExceptionForTest |
| 337 | + try: |
| 338 | + raise ExceptionForTest("cause") |
| 339 | + except ExceptionForTest: |
| 340 | + raise ExceptionForTest("exception-with-cause") |
337 | 341 | except ExceptionForTest: |
338 | 342 | _logger.exception("oops") |
339 | | - expected_stack_trace = "".join(format_tb(sys.exc_info()[2])) |
| 343 | + expected_stack_trace = "".join(format_exception(*sys.exc_info())) |
340 | 344 |
|
341 | 345 | log_buffer_with_stack_trace.seek(0) |
342 | 346 | message = json.load(log_buffer_with_stack_trace) |
@@ -365,7 +369,7 @@ def test_newrelic_logger_error_outside_transaction_with_stack_trace(log_buffer_w |
365 | 369 | "thread.name": "MainThread", |
366 | 370 | "process.name": "MainProcess", |
367 | 371 | "error.class": "test_logs_in_context:ExceptionForTest", |
368 | | - "error.message": "", |
| 372 | + "error.message": "exception-with-cause", |
369 | 373 | } |
370 | 374 | expected_extra_txn_keys = ( |
371 | 375 | "entity.guid", |
|
0 commit comments