Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix(event-webhook): Improve error logging with exception type and stack trace (#12202)

Graham Neubig4dec38c7ce2f
diff --git a/enterprise/server/routes/event_webhook.py b/enterprise/server/routes/event_webhook.py
index b4f8b71f68..e174f71660 100644
--- a/enterprise/server/routes/event_webhook.py
+++ b/enterprise/server/routes/event_webhook.py
@@ -134,12 +134,12 @@ async def _process_batch_operations_background(
)
except Exception as e:
logger.error(
- 'error_processing_batch_operation',
+ f'error_processing_batch_operation: {type(e).__name__}: {e}',
extra={
'path': batch_op.path,
'method': str(batch_op.method),
- 'error': str(e),
},
+ exc_info=True,
)
diff --git a/enterprise/tests/unit/server/test_event_webhook.py b/enterprise/tests/unit/server/test_event_webhook.py
index 71ba143ae4..64bf491c96 100644
--- a/enterprise/tests/unit/server/test_event_webhook.py
+++ b/enterprise/tests/unit/server/test_event_webhook.py
@@ -699,12 +699,11 @@ class TestProcessBatchOperationsBackground:
# Should not raise exceptions
await _process_batch_operations_background(batch_ops, 'test-api-key')
- # Should log the error
- mock_logger.error.assert_called_once_with(
- 'error_processing_batch_operation',
- extra={
- 'path': 'invalid-path',
- 'method': 'BatchMethod.POST',
- 'error': mock_logger.error.call_args[1]['extra']['error'],
- },
- )
+ # Should log the error with exception type and message in the log message
+ mock_logger.error.assert_called_once()
+ call_args = mock_logger.error.call_args
+ log_message = call_args[0][0]
+ assert log_message.startswith('error_processing_batch_operation:')
+ assert call_args[1]['extra']['path'] == 'invalid-path'
+ assert call_args[1]['extra']['method'] == 'BatchMethod.POST'
+ assert call_args[1]['exc_info'] is True