def METHOD_NAME(
    value,
    max_size=settings.SENTRY_MAX_VARIABLE_SIZE,
    max_depth=6,
    object_hook=None,
    _depth=0,
    _size=0,
    **kwargs,
):
    """
    Truncates a value to ```MAX_VARIABLE_SIZE```.
    The method of truncation depends on the type of value.
    """
    options = {
        "max_depth": max_depth,
        "max_size": max_size,
        "object_hook": object_hook,
        "_depth": _depth + 1,
    }
    if _depth > max_depth:
        if not isinstance(value, str):
            value = json.dumps(value)
        return METHOD_NAME(value, _size=_size, max_size=max_size)
    elif isinstance(value, dict):
        result: Any = {}
        _size += 2
        for k in sorted(value.keys(), key=lambda x: (len(force_str(value[x])), x)):
            v = value[k]
            trim_v = METHOD_NAME(v, _size=_size, **options)
            result[k] = trim_v
            _size += len(force_str(trim_v)) + 1
            if _size >= max_size:
                break
    elif isinstance(value, (list, tuple)):
        result = []
        _size += 2
        for v in value:
            trim_v = METHOD_NAME(v, _size=_size, **options)
            result.append(trim_v)
            _size += len(force_str(trim_v))
            if _size >= max_size:
                break
        if isinstance(value, tuple):
            result = tuple(result)
    elif isinstance(value, str):
        result = truncatechars(value, max_size - _size)
    else:
        result = value
    if object_hook is None:
        return result
    return object_hook(result)