code: func newSegment(name string, r *http.Request) *awsxray.Segment {
  	// attempt to get IDs first
  	parentId := getParentId(r.Header)
  	traceId := getTraceId(r.Header)
  
  	// now set the trace ID
  	traceHdr := r.Header.Get(awsxray.TraceHeader)
  	traceHdr = awsxray.SetTraceId(traceHdr, traceId)
  
  	// create segment
  	s := &awsxray.Segment{
  		Id:        getRandom(8),
  		HTTP:      newHTTP(r),
  		Name:      name,
  		TraceId:   traceId,
  		StartTime: float64(time.Now().Truncate(time.Millisecond).UnixNano()) / 1e9,
  	}
  
  	// if we have a parent then we are a subsegment
  	if len(parentId) > 0 {
  		s.ParentId = parentId
  		s.Type = "subsegment"
  	} else {
  		// set a new parent Id
  		traceHdr = awsxray.SetParentId(traceHdr, s.Id)
  	}
  
  	// now save the header for the future context
  	r.Header.Set(awsxray.TraceHeader, traceHdr)
  
  	return s
  }
docs: // newSegment creates a new segment based on whether we're part of an existing flow