code: def inject_trace_header(headers, entity):
      
      if not entity:
          return
  
      if hasattr(entity, 'type') and entity.type == 'subsegment':
          header = entity.parent_segment.get_origin_trace_header()
      else:
          header = entity.get_origin_trace_header()
      data = header.data if header else None
  
      to_insert = TraceHeader(
          root=entity.trace_id,
          parent=entity.id,
          sampled=entity.sampled,
          data=data,
      )
  
      value = to_insert.to_header_str()
  
      headers[http.XRAY_HEADER] = value
docs: Extract trace id, entity id and sampling decision
      from the input entity and inject these information
      to headers.
  
      :param dict headers: http headers to inject
      :param Entity entity: trace entity that the trace header
          value generated from.