public void sendOrBufferSpan()

in universal-profiling-integration/src/main/java/co/elastic/otel/SpanProfilingSamplesCorrelator.java [98:131]


  public void sendOrBufferSpan(ReadableSpan span) {
    boolean sampled = span.getSpanContext().getTraceFlags().isSampled();
    if (!sampled || LocalRootSpan.getFor(span) != span) {
      sendSpan.accept(span);
      return;
    }

    long criticalPhaseVal = shutdownPhaser.writerCriticalSectionEnter();
    try {
      if (spanBufferDurationNanos == 0 || shuttingDown) {
        correlateAndSendSpan(span);
        return;
      }

      boolean couldPublish =
          delayedSpans.tryPublishEvent(
              (event, idx, sp, timestamp) -> {
                event.span = sp;
                event.endNanoTimestamp = timestamp;
              },
              span,
              nanoClock.getAsLong());

      if (!couldPublish) {
        logger.log(
            Level.WARNING,
            "The following span could not be delayed for correlation due to a full buffer, it will be sent immediately, {0}",
            span);
        correlateAndSendSpan(span);
      }
    } finally {
      shutdownPhaser.writerCriticalSectionExit(criticalPhaseVal);
    }
  }