in instrumentation/openai-client-instrumentation/instrumentation-1.1/src/main/java/co/elastic/otel/openai/v1_1/wrappers/InstrumentedChatCompletionService.java [101:146]
public void onStart(
AttributesBuilder attributes,
Context parentContext,
RequestHolder requestHolder) {
ChatCompletionCreateParams request = requestHolder.request;
requestHolder.settings.putServerInfoIntoAttributes(attributes);
attributes.put(GEN_AI_SYSTEM, "openai");
attributes.put(GEN_AI_OPERATION_NAME, "chat");
attributes.put(GEN_AI_REQUEST_MODEL, request.model().toString());
request
.frequencyPenalty()
.ifPresent(val -> attributes.put(GEN_AI_REQUEST_FREQUENCY_PENALTY, val));
request
.maxTokens()
.ifPresent(val -> attributes.put(GEN_AI_REQUEST_MAX_TOKENS, val));
request
.presencePenalty()
.ifPresent(val -> attributes.put(GEN_AI_REQUEST_PRESENCE_PENALTY, val));
request
.temperature()
.ifPresent(val -> attributes.put(GEN_AI_REQUEST_TEMPERATURE, val));
request.topP().ifPresent(val -> attributes.put(GEN_AI_REQUEST_TOP_P, val));
request.seed().ifPresent(val -> attributes.put(GEN_AI_OPENAI_REQUEST_SEED, val));
request
.stop()
.ifPresent(
stop -> {
if (stop.isString()) {
attributes.put(
GEN_AI_REQUEST_STOP_SEQUENCES,
Collections.singletonList(stop.asString()));
} else if (stop.isStrings()) {
attributes.put(GEN_AI_REQUEST_STOP_SEQUENCES, stop.asStrings());
}
});
request
.responseFormat()
.ifPresent(
val -> {
String typeString = extractType(val);
if (typeString != null) {
attributes.put(GEN_AI_OPENAI_REQUEST_RESPONSE_FORMAT, typeString);
}
});
}