import re


def _parse_trace_span(header):
    """Given an X_CLOUD_TRACE header, extract the trace and span ids.

    Args:
        header (str): the string extracted from the X_CLOUD_TRACE header
    Returns:
        Tuple[Optional[dict], Optional[str]]:
            The trace_id and span_id extracted from the header
            Each field will be None if not found.
    """
    trace_id = None
    span_id = None
    if header:
        try:
            split_header = header.split("/", 1)
            trace_id = split_header[0]
            header_suffix = split_header[1]
            # the span is the set of alphanumeric characters after the /
            span_id = re.findall(r"^\w+", header_suffix)[0]
        except IndexError:
            pass
    return trace_id, span_id