@classmethod
def from_upstream(cls, trace_id, parent_id, span_id, sampled, flags):
    """Build a TraceInfo from individual headers.

        :param int trace_id: The ID of the trace.
        :param int parent_id: The ID of the parent span.
        :param int span_id: The ID of this span within the tree.
        :param bool sampled: Boolean flag to determine request sampling.
        :param int flags: Bit flags for communicating feature flags downstream

        :raises: :py:exc:`ValueError` if any of the values are inappropriate.

        """
    if trace_id is None or not 0 <= trace_id < 2 ** 64:
        raise ValueError('invalid trace_id')
    if span_id is None or not 0 <= span_id < 2 ** 64:
        raise ValueError('invalid span_id')
    if parent_id is None or not 0 <= parent_id < 2 ** 64:
        raise ValueError('invalid parent_id')
    if sampled is not None and not isinstance(sampled, bool):
        raise ValueError('invalid sampled value')
    if flags is not None:
        if not 0 <= flags < 2 ** 64:
            raise ValueError('invalid flags value')
    return cls(trace_id, parent_id, span_id, sampled, flags)
