def format_legacy_trace_json(span_datas):
    """Formats a list of SpanData tuples into the legacy 'trace' dictionary
    format for backwards compatibility
    :type span_datas: list of :class:
            `~opencensus.trace.span_data.SpanData`
    :param list of opencensus.trace.span_data.SpanData span_datas:
        SpanData tuples to emit
    :rtype: dict
    :return: Legacy 'trace' dictionary representing given SpanData tuples
    """
    if not span_datas:
        return {}
    top_span = span_datas[0]
    assert isinstance(top_span, SpanData)
    trace_id = top_span.context.trace_id if top_span.context is not None \
        else None
    assert trace_id is not None
    return {
        'traceId': trace_id,
        'spans': [_format_legacy_span_json(sd) for sd in span_datas],
    }