code: def to_header(self, span_context):
          
          trace_id = span_context.trace_id
          span_id = span_context.span_id
          trace_options = int(span_context.trace_options.trace_options_byte)
  
          # If there is no span_id in this context, set it to 0, which is
          # considered invalid and won't be set as the downstream parent span_id.
          if span_id is None:
              span_id = span_context_module.INVALID_SPAN_ID
  
          # Convert trace_id to bytes with length 16, treat span_id as 64 bit
          # integer which is unsigned long long type and convert it to bytes with
          # length 8, trace_option is integer with length 1.
          return struct.pack(
              BINARY_FORMAT,
              VERSION_ID,
              TRACE_ID_FIELD_ID,
              binascii.unhexlify(trace_id),
              SPAN_ID_FIELD_ID,
              binascii.unhexlify(span_id),
              TRACE_OPTION_FIELD_ID,
              trace_options)
docs: Convert a SpanContext object to header in binary format.
  
          :type span_context:
              :class:`~opencensus.trace.span_context.SpanContext`
          :param span_context: SpanContext object.
  
          :rtype: bytes
          :returns: A trace context header in binary format.