code: public static Reference findPrimaryReference(List<Reference> references) {
          List<Reference> followsFrom = references.stream()
                  .filter(ref -> References.FOLLOWS_FROM.equals(ref.getReferenceType())
                          && ref.getReferredTo() instanceof APMSpan)
                  .collect(Collectors.toList());
  
          List<Reference> childOfSpan = references.stream()
                  .filter(ref -> References.CHILD_OF.equals(ref.getReferenceType())
                          && ref.getReferredTo() instanceof APMSpan)
                  .collect(Collectors.toList());
  
          List<Reference> extractedTraceState = references.stream()
                  .filter(ref -> ref.getReferredTo() instanceof APMSpanBuilder)
                  .collect(Collectors.toList());
  
          if (!extractedTraceState.isEmpty()) {
              if (extractedTraceState.size() == 1) {
                  return extractedTraceState.get(0);
              }
              return null;
          }
          if (!childOfSpan.isEmpty()) {
              if (childOfSpan.size() == 1) {
                  return childOfSpan.get(0);
              }
              return null;
          }
          if (followsFrom.size() == 1) {
              return followsFrom.get(0);
          }
          return null;
      }
docs: This method identifies the primary 'parent' reference that should be used
  to link the associated span to an existing trace instance.
  
  @param references The list of references
  @return The primary reference, or null if one could not be determined