-
Notifications
You must be signed in to change notification settings - Fork 569
Open
Description
See
sentry-python/sentry_sdk/consts.py
Lines 6 to 9 in e9738f6
| # This is more or less an arbitrary large-ish value for now, so that we allow | |
| # pretty long strings (like LLM prompts), but still have *some* upper limit | |
| # until we verify that removing the trimming completely is safe. | |
| DEFAULT_MAX_VALUE_LENGTH = 100_000 |
which is used in
sentry-python/sentry_sdk/utils.py
Lines 1208 to 1234 in 2d49b74
| def strip_string(value, max_length=None): | |
| # type: (str, Optional[int]) -> Union[AnnotatedValue, str] | |
| if not value: | |
| return value | |
| if max_length is None: | |
| max_length = DEFAULT_MAX_VALUE_LENGTH | |
| byte_size = _get_size_in_bytes(value) | |
| text_size = len(value) | |
| if byte_size is not None and byte_size > max_length: | |
| # truncate to max_length bytes, preserving code points | |
| truncated_value = _truncate_by_bytes(value, max_length) | |
| elif text_size is not None and text_size > max_length: | |
| # fallback to truncating by string length | |
| truncated_value = value[: max_length - 3] + "..." | |
| else: | |
| return value | |
| return AnnotatedValue( | |
| value=truncated_value, | |
| metadata={ | |
| "len": byte_size or text_size, | |
| "rem": [["!limit", "x", max_length - 3, max_length]], | |
| }, | |
| ) |
The strip_string() function is called in
sentry_sdk.utils.get_lines_from_file()for obtaining pre- and post context source lines; andsentry_sdk.serializer.serialize(), which is used to serialize events.
Metadata
Metadata
Assignees
Labels
No labels