def from_header(self, binary):
        """Generate a SpanContext object using the trace context header.
        The value of enabled parsed from header is int. Need to convert to
        bool.

        :type binary: bytes
        :param binary: Trace context header which was extracted from the
                       request headers.

        :rtype: :class:`~opencensus.trace.span_context.SpanContext`
        :returns: SpanContext generated from the trace context header.
        """
        # If no binary provided, generate a new SpanContext
        if binary is None:
            return span_context_module.SpanContext(from_header=False)

        # If cannot parse, return a new SpanContext and ignore the context
        # from binary.
        try:
            data = Header._make(struct.unpack(BINARY_FORMAT, binary))
        except struct.error:
            logging.warning(
                'Cannot parse the incoming binary data {}, '
                'wrong format. Total bytes length should be {}.'.format(
                    binary, FORMAT_LENGTH
                )
            )
            return span_context_module.SpanContext(from_header=False)

        # data.trace_id is in bytes with length 16, hexlify it to hex bytes
        # with length 32, then decode it to hex string using utf-8.
        trace_id = str(binascii.hexlify(data.trace_id).decode(UTF8))
        span_id = str(binascii.hexlify(data.span_id).decode(UTF8))
        trace_options = TraceOptions(data.trace_option)

        span_context = span_context_module.SpanContext(
                trace_id=trace_id,
                span_id=span_id,
                trace_options=trace_options,
                from_header=True)

        return span_context
def from_header ( self , binary ) : if binary is None : return span_context_module . SpanContext ( from_header = False ) try : data = Header . _make ( struct . unpack ( BINARY_FORMAT , binary ) ) except struct . error : logging . warning ( 'Cannot parse the incoming binary data {}, ' 'wrong format. Total bytes length should be {}.' . format ( binary , FORMAT_LENGTH ) ) return span_context_module . SpanContext ( from_header = False ) trace_id = str ( binascii . hexlify ( data . trace_id ) . decode ( UTF8 ) ) span_id = str ( binascii . hexlify ( data . span_id ) . decode ( UTF8 ) ) trace_options = TraceOptions ( data . trace_option ) span_context = span_context_module . SpanContext ( trace_id = trace_id , span_id = span_id , trace_options = trace_options , from_header = True ) return span_context
Generate a SpanContext object using the trace context header.
        The value of enabled parsed from header is int. Need to convert to
        bool.

        :type binary: bytes
        :param binary: Trace context header which was extracted from the
                       request headers.

        :rtype: :class:`~opencensus.trace.span_context.SpanContext`
        :returns: SpanContext generated from the trace context header.