Skip to content

change the traceback format to print in one line #362

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

Merged
merged 4 commits into from
Aug 22, 2023
Merged
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
22 changes: 14 additions & 8 deletions datadog_lambda/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ def __new__(cls, func):
else:
logger.debug("datadog_lambda_wrapper already wrapped")
return _NoopDecorator(func)
except Exception:
traceback.print_exc()
except Exception as e:
logger.error(format_err_with_traceback(e))
return func

def __init__(self, func):
Expand Down Expand Up @@ -204,8 +204,8 @@ def __init__(self, func):
patch_all()

logger.debug("datadog_lambda_wrapper initialized")
except Exception:
traceback.print_exc()
except Exception as e:
logger.error(format_err_with_traceback(e))

def __call__(self, event, context, **kwargs):
"""Executes when the wrapped function gets called"""
Expand Down Expand Up @@ -291,8 +291,8 @@ def _before(self, event, context):
if profiling_env_var and is_new_sandbox():
self.prof.start(stop_on_exit=False, profile_children=True)
logger.debug("datadog_lambda_wrapper _before() done")
except Exception:
traceback.print_exc()
except Exception as e:
logger.error(format_err_with_traceback(e))

def _after(self, event, context):
try:
Expand Down Expand Up @@ -358,8 +358,14 @@ def _after(self, event, context):
event.get("requestContext", {}).get("requestId")
)
logger.debug("datadog_lambda_wrapper _after() done")
except Exception:
traceback.print_exc()
except Exception as e:
logger.error(format_err_with_traceback(e))


def format_err_with_traceback(e):
return "Error {}. Traceback: {}".format(
e, traceback.format_exc().replace("\n", "\r")
)


datadog_lambda_wrapper = _LambdaDecorator