in instrumentation/openai-client-instrumentation/instrumentation-1.1/src/main/java/co/elastic/otel/openai/v1_1/wrappers/InstrumentedChatCompletionService.java [149:173]
public void onEnd(
AttributesBuilder attributes,
Context context,
RequestHolder request,
ChatCompletionResult result,
Throwable error) {
if (error != null) {
attributes.put(ERROR_TYPE, error.getClass().getCanonicalName());
} else {
attributes.put(GEN_AI_RESPONSE_MODEL, result.responseModel);
attributes.put(GEN_AI_RESPONSE_ID, result.responseId);
List<String> finishReasons = result.finishReasons;
if (finishReasons != null && !finishReasons.isEmpty()) {
attributes.put(GEN_AI_RESPONSE_FINISH_REASONS, finishReasons);
}
if (result.inputTokens != null) {
attributes.put(GEN_AI_USAGE_INPUT_TOKENS, result.inputTokens);
}
if (result.completionTokens != null) {
attributes.put(GEN_AI_USAGE_OUTPUT_TOKENS, result.completionTokens);
}
}
}