|
26 | 26 | import org.springframework.ai.chat.client.advisor.observation.AdvisorObservationContext;
|
27 | 27 | import org.springframework.ai.chat.client.observation.ChatClientObservationContext;
|
28 | 28 | import org.springframework.ai.chat.model.ChatModel;
|
29 |
| -import org.springframework.ai.chat.observation.ChatModelCompletionObservationHandler; |
30 |
| -import org.springframework.ai.chat.observation.ChatModelMeterObservationHandler; |
31 |
| -import org.springframework.ai.chat.observation.ChatModelObservationContext; |
32 |
| -import org.springframework.ai.chat.observation.ChatModelPromptContentObservationHandler; |
| 29 | +import org.springframework.ai.chat.observation.*; |
33 | 30 | import org.springframework.ai.embedding.observation.EmbeddingModelObservationContext;
|
34 | 31 | import org.springframework.ai.image.observation.ImageModelObservationContext;
|
35 | 32 | import org.springframework.ai.model.observation.ErrorLoggingObservationHandler;
|
@@ -70,6 +67,16 @@ private static void logCompletionWarning() {
|
70 | 67 | "You have enabled logging out the completion content with the risk of exposing sensitive or private information. Please, be careful!");
|
71 | 68 | }
|
72 | 69 |
|
| 70 | + private static void tracePromptContentWarning() { |
| 71 | + logger.warn( |
| 72 | + "You have enabled tracing out the prompt content with the risk of exposing sensitive or private information. Please, be careful!"); |
| 73 | + } |
| 74 | + |
| 75 | + private static void traceCompletionWarning() { |
| 76 | + logger.warn( |
| 77 | + "You have enabled tracing out the completion content with the risk of exposing sensitive or private information. Please, be careful!"); |
| 78 | + } |
| 79 | + |
73 | 80 | @Bean
|
74 | 81 | @ConditionalOnMissingBean
|
75 | 82 | @ConditionalOnBean(MeterRegistry.class)
|
@@ -104,6 +111,30 @@ TracingAwareLoggingObservationHandler<ChatModelObservationContext> chatModelComp
|
104 | 111 | return new TracingAwareLoggingObservationHandler<>(new ChatModelCompletionObservationHandler(), tracer);
|
105 | 112 | }
|
106 | 113 |
|
| 114 | + @Bean |
| 115 | + @ConditionalOnMissingBean(value = ChatModelPromptContentObservationTraceHandler.class, |
| 116 | + name = "chatModelPromptContentObservationTraceHandler") |
| 117 | + @ConditionalOnProperty(prefix = ChatObservationProperties.CONFIG_PREFIX, name = "trace-prompt", |
| 118 | + havingValue = "true") |
| 119 | + TracingAwareLoggingObservationHandler<ChatModelObservationContext> chatModelPromptContentObservationTraceHandler( |
| 120 | + ChatObservationProperties properties, Tracer tracer) { |
| 121 | + tracePromptContentWarning(); |
| 122 | + return new TracingAwareLoggingObservationHandler<>(new ChatModelPromptContentObservationTraceHandler( |
| 123 | + properties.getContentFormatter(), properties.getTracePromptSize()), tracer); |
| 124 | + } |
| 125 | + |
| 126 | + @Bean |
| 127 | + @ConditionalOnMissingBean(value = ChatModelCompletionObservationTraceHandler.class, |
| 128 | + name = "chatModelCompletionObservationTraceHandler") |
| 129 | + @ConditionalOnProperty(prefix = ChatObservationProperties.CONFIG_PREFIX, name = "trace-completion", |
| 130 | + havingValue = "true") |
| 131 | + TracingAwareLoggingObservationHandler<ChatModelObservationContext> chatModelCompletionObservationTraceHandler( |
| 132 | + ChatObservationProperties properties, Tracer tracer) { |
| 133 | + traceCompletionWarning(); |
| 134 | + return new TracingAwareLoggingObservationHandler<>( |
| 135 | + new ChatModelCompletionObservationTraceHandler(properties.getContentFormatter()), tracer); |
| 136 | + } |
| 137 | + |
107 | 138 | @Bean
|
108 | 139 | @ConditionalOnMissingBean
|
109 | 140 | @ConditionalOnProperty(prefix = ChatObservationProperties.CONFIG_PREFIX, name = "include-error-logging",
|
@@ -139,6 +170,27 @@ ChatModelCompletionObservationHandler chatModelCompletionObservationHandler() {
|
139 | 170 | return new ChatModelCompletionObservationHandler();
|
140 | 171 | }
|
141 | 172 |
|
| 173 | + @Bean |
| 174 | + @ConditionalOnMissingBean() |
| 175 | + @ConditionalOnProperty(prefix = ChatObservationProperties.CONFIG_PREFIX, name = "trace-prompt", |
| 176 | + havingValue = "true") |
| 177 | + ChatModelPromptContentObservationTraceHandler chatModelPromptContentObservationTraceHandler( |
| 178 | + ChatObservationProperties properties) { |
| 179 | + tracePromptContentWarning(); |
| 180 | + return new ChatModelPromptContentObservationTraceHandler(properties.getContentFormatter(), |
| 181 | + properties.getTracePromptSize()); |
| 182 | + } |
| 183 | + |
| 184 | + @Bean |
| 185 | + @ConditionalOnMissingBean() |
| 186 | + @ConditionalOnProperty(prefix = ChatObservationProperties.CONFIG_PREFIX, name = "trace-completion", |
| 187 | + havingValue = "true") |
| 188 | + ChatModelCompletionObservationTraceHandler chatModelCompletionObservationTraceHandler( |
| 189 | + ChatObservationProperties properties) { |
| 190 | + traceCompletionWarning(); |
| 191 | + return new ChatModelCompletionObservationTraceHandler(properties.getContentFormatter()); |
| 192 | + } |
| 193 | + |
142 | 194 | }
|
143 | 195 |
|
144 | 196 | }
|
0 commit comments