private synchronized void endSpan()

in instrumentation/openai-client-instrumentation/instrumentation-1.1/src/main/java/co/elastic/otel/openai/v1_1/wrappers/TracingStreamedResponse.java [71:94]


  private synchronized void endSpan() {
    if (hasEnded) {
      return;
    }
    hasEnded = true;

    List<String> finishReasons =
        choiceFinishReasons.entrySet().stream()
            .sorted(Map.Entry.comparingByKey())
            .map(Map.Entry::getValue)
            .collect(Collectors.toList());

    Long inputTokens = null;
    Long completionTokens = null;
    if (usage != null) {
      inputTokens = usage.promptTokens();
      completionTokens = usage.completionTokens();
    }

    InstrumentedChatCompletionService.ChatCompletionResult result =
        new InstrumentedChatCompletionService.ChatCompletionResult(
            model, responseId, finishReasons, inputTokens, completionTokens);
    InstrumentedChatCompletionService.INSTRUMENTER.end(spanContext, requestHolder, result, null);
  }