def _handle_span_output(span, res, cls=None):
    """Handles entity output logging in JSON for both sync and async functions"""
    try:
        if _should_send_prompts():
            json_output = json.dumps(res, **({"cls": cls} if cls else {}))
            if _is_json_size_valid(json_output):
                span.set_attribute(
                    SpanAttributes.TRACELOOP_ENTITY_OUTPUT,
                    json_output,
                )
    except TypeError as e:
        Telemetry().log_exception(e)
Handles entity output logging in JSON for both sync and async functions
packages/traceloop-sdk/traceloop/sdk/decorators/base.py