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 messages based on bytes, not unicode characters #181

Merged
merged 1 commit into from
Jan 28, 2023

Conversation

tomkins
Copy link
Contributor

@tomkins tomkins commented Jan 27, 2023

We've been getting this message quite a bit in one of our apps:

site-packages/watchtower/__init__.py:339: WatchtowerWarning: Failed to deliver logs: An error occurred (InvalidParameterException) when calling the PutLogEvents operation: Upload too large: 1048681 bytes exceeds limit of 1048576

Some of the messages we're sending contain unicode characters, and we're sending a lot of messages in the batches. However as the message size calculation is counting the length of strings, instead of the number of bytes - we're getting warnings originating from boto3.

Temporary workaround is to drop the message/batch size - however the better fix is to change the size checking and truncation to look at the bytes of the messages.

Copy link
Owner

@kislyuk kislyuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution and for chasing down the bug! I just have two minor suggestions, it looks great otherwise.

@@ -45,6 +45,20 @@ def _boto_filter(record):
return True


def _size(msg):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move _size to be a method of CloudWatchLogHandler to simplify customization by subclassing?

) + CloudWatchLogHandler.EXTRA_MSG_PAYLOAD_SIZE


def _truncate(msg, max_size):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here - Can you move _truncate to be a method of CloudWatchLogHandler to simplify customization by subclassing?

@tomkins
Copy link
Contributor Author

tomkins commented Jan 28, 2023

Updated, and hopefully found an okay place to put them.

Kept them as _ methods, but can change that back if needed.

@kislyuk kislyuk merged commit 373ee82 into kislyuk:develop Jan 28, 2023
@tomkins tomkins deleted the fix-unicode-truncation branch January 28, 2023 16:17
@kislyuk
Copy link
Owner

kislyuk commented Jan 29, 2023

Released in v3.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants