Please do a quick search on GitHub issues first, the feature you are about to request might have already been requested.
Expected Behavior
I hope that Observation
can distinguish between different ChatModel
or ChatClient
instances.
Because in production, different API keys may have different QPM limits, yet the same model is used. I hope the Observation
can be refined down to the BeanName
level.
Another case is when different model providers give us the same model. I’d like to be able to tell them apart.
Current Behavior
Currently, it can only distinguish at the model
level.
Context
If we have ChatClient
and ChatModel
implement BeanNameAware
, then Observation
should be able to get the BeanName
— should be able to achieve this goal
Comment From: YunKuiLu
@ThomasVitale Hi, what do you think about this idea?
Comment From: YunKuiLu
I found gen_ai.agent.name
in open-telemetry#gen-ai, and it would be great if we could support this attribute.
Comment From: YunKuiLu
Found a solution, closing this issue.
Just for reference:
@Configuration
public class ChatClientObservationConfig {
@Bean
public ChatClientObservationConvention chatClientObservationConvention() {
return new MyChatClientObservationConvention();
}
}
public class MyChatClientObservationConvention extends DefaultChatClientObservationConvention {
public MyChatClientObservationConvention() {
super();
}
@Override
public KeyValues getLowCardinalityKeyValues(ChatClientObservationContext context) {
KeyValues lowCardinalityKeyValues = super.getLowCardinalityKeyValues(context);
lowCardinalityKeyValues = lowCardinalityKeyValues.and(agentName(context));
return lowCardinalityKeyValues;
}
protected KeyValue agentName(ChatClientObservationContext context) {
return KeyValue.of("agent.name", Objects.toString(context.getRequest().context().get(DEFAULT_CHAT_CLIENT_NAME), "Undefined"));
}
}