See
| # 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
| defstrip_string(value, max_length=None): |
| # type: (str, Optional[int]) -> Union[AnnotatedValue, str] |
| ifnotvalue: |
| returnvalue |
| |
| ifmax_lengthisNone: |
| max_length=DEFAULT_MAX_VALUE_LENGTH |
| |
| byte_size=_get_size_in_bytes(value) |
| text_size=len(value) |
| |
| ifbyte_sizeisnotNoneandbyte_size>max_length: |
| # truncate to max_length bytes, preserving code points |
| truncated_value=_truncate_by_bytes(value, max_length) |
| eliftext_sizeisnotNoneandtext_size>max_length: |
| # fallback to truncating by string length |
| truncated_value=value[: max_length-3] +"..." |
| else: |
| returnvalue |
| |
| returnAnnotatedValue( |
| value=truncated_value, |
| metadata={ |
| "len": byte_sizeortext_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.
See
sentry-python/sentry_sdk/consts.py
Lines 6 to 9 in e9738f6
which is used in
sentry-python/sentry_sdk/utils.py
Lines 1208 to 1234 in 2d49b74
The
strip_string()function is called insentry_sdk.utils.get_lines_from_file()for obtaining pre- and post context source lines; andsentry_sdk.serializer.serialize(), which is used to serialize events.