in instrumentation/openai-client-instrumentation/instrumentation-1.1/src/main/java/co/elastic/otel/openai/v1_1/wrappers/ChatCompletionEventsHelper.java [193:218]
public static void emitCompletionLogEvents(
ChatCompletion completion, InstrumentationSettings settings) {
if (!settings.emitEvents) {
return;
}
for (ChatCompletion.Choice choice : completion.choices()) {
ChatCompletionMessage choiceMsg = choice.message();
Map<String, Value<?>> message = new HashMap<>();
if (settings.captureMessageContent) {
choiceMsg.content().ifPresent(content -> message.put("content", Value.of(content)));
choiceMsg
.toolCalls()
.ifPresent(
toolCalls -> {
message.put(
"tool_calls",
Value.of(
toolCalls.stream()
.map(ChatCompletionEventsHelper::buildToolCallEventObject)
.collect(Collectors.toList())));
});
}
emitCompletionLogEvent(
choice.index(), choice.finishReason().toString(), Value.of(message), settings, null);
}
}