Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Truncate traceback for failure email #3086

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,9 @@ sender
User name in from field of error e-mails.
Default value: luigi-client@<server_name>

traceback_max_length
Maximum length for traceback included in error email. Default is 5000.


[batch_notifier]
----------------
Expand Down
8 changes: 8 additions & 0 deletions luigi/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ class email(luigi.Config):
default='',
config_path=dict(section='core', name='error-email'),
description='Address to send error e-mails to')
traceback_max_length = luigi.parameter.IntParameter(
default=5000,
description='Max length for error traceback')
sender = luigi.parameter.Parameter(
default=DEFAULT_CLIENT_EMAIL,
config_path=dict(section='core', name='email-sender'),
Expand Down Expand Up @@ -373,6 +376,11 @@ def format_task_error(headline, task, command, formatted_exception=None):
:return: message body
"""

if formatted_exception:
if len(formatted_exception) > email().traceback_max_length:
truncated_exception = formatted_exception[:email().traceback_max_length]
formatted_exception = f"{truncated_exception}...Traceback exceeds max length and has been truncated."

if formatted_exception:
formatted_exception = wrap_traceback(formatted_exception)
else:
Expand Down
11 changes: 11 additions & 0 deletions test/worker_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,17 @@ def run(self):
self.assertEqual(1, len(emails))
self.assertTrue(emails[0].find("Luigi: %s FAILED" % (a,)) != -1)

@email_patch
def test_run_error_long_traceback(self, emails):
class A(luigi.Task):
def run(self):
raise Exception("b0rk"*10500)

a = A()
luigi.build([a], workers=1, local_scheduler=True)
self.assertTrue(len(emails[0]) < 10000)
self.assertTrue(emails[0].find("Traceback exceeds max length and has been truncated"))

@with_config({'batch_email': {'email_interval': '0'}, 'worker': {'send_failure_email': 'False'}})
@email_patch
def test_run_error_email_batch(self, emails):
Expand Down