Exceptions appear as multiple entries in Cloudwatch
- Dominant language
- Python
- Stars
- 11.1k
- Forks
- 1k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 2
Description
So I noticed that whenever I have an exception (or a multi-line log entry) it appears as multiple log entries in Cloudwatch. It makes it really hard to get useful information from cloudwatch if you are searching for example since you will only get the line that has the entry being searched for and not the entire exception.
I have hacked up a fix that seems to work, but I am not sure where to put a proper fix, or how I would go about writing a test for it.
Here is the fix:
```
class CustomFormatter(logging.Formatter):
def format(self, record):
out = super().format(record)
out = out.replace('\n', '\r')
return out
log = logging.getLogger('gtf')
handler = logging.StreamHandler(sys.stdout)
# Timestamp is handled by lambda itself so the
# default FORMAT_STRING doesn't need to include it.
formatter = CustomFormatter(Chalice.FORMAT_STRING)
handler.setFormatter(formatter)
log.propagate = False
log.addHandler(handler)
app = Chalice(app_name='gtf', configure_logs=False)
app.log.setLevel(logging.DEBUG)
```
Most of the code came from chalice/app.py where it does the log configuration.
I would be happy to turn this into a merge request if someone gives me an idea on how they want it handled.
Contributor guide
Research direction
Start in chalice/app.py, where the issue says logging is configured, and reproduce an exception or multiline log entry sent to CloudWatch. Identify the expected single-entry behavior and determine how a regression test can verify that the complete exception remains searchable as one log entry.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, python
- Domain
- cloud, observability-sre
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100