Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexcheng1982/java-ai-app-observation
Java AI App Observability
https://github.com/alexcheng1982/java-ai-app-observation
ai java opentelemetry spring spring-ai
Last synced: 19 days ago
JSON representation
Java AI App Observability
- Host: GitHub
- URL: https://github.com/alexcheng1982/java-ai-app-observation
- Owner: alexcheng1982
- License: apache-2.0
- Created: 2024-03-28T00:59:57.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-04-03T14:31:52.000Z (8 months ago)
- Last Synced: 2024-10-10T19:23:42.537Z (about 1 month ago)
- Topics: ai, java, opentelemetry, spring, spring-ai
- Language: Java
- Homepage:
- Size: 28.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Java AI App Observation
## Spring AI
### OpenTelemetry
See the example app in [examples/spring-ai-example](examples/spring-ai-example).
#### Metrics
| Name | Type | Description |
|---------------------------------------|-----------|---------------------------------------|
| `chat.client.call.duration` | Histogram | Duration of ChatClient call requests |
| `chat.client.prompt.tokens.count` | Counter | Count of ChatClient prompt tokens |
| `chat.client.generation.tokens.count` | Counter | Count of ChatClient generation tokens |
| `chat.client.total.tokens.count` | Counter | Count of ChatClient total tokens |For `ChatClient`s, using `ChatClientTelemetry` to wrap an existing `ChatClient`.
```java
@Configuration
public class ApplicationConfiguration {@Bean
@Primary
public ChatClient chatClient(OllamaChatClient ollamaChatClient,
OpenTelemetry openTelemetry) {
return ChatClientTelemetry.builder(openTelemetry)
.tracePromptContent(true) // Trace prompt content
.traceChatResponseContent(true) // Trace chat response content
.build()
.newChatClient(ollamaChatClient);
}@Bean
public OpenTelemetry openTelemetry(ApplicationContext applicationContext) {
return AutoConfiguredOpenTelemetrySdk.builder()
.addResourceCustomizer(
((resource, configProperties) -> resource.toBuilder()
.put(AttributeKey.stringKey("service.name"),
Optional.ofNullable(applicationContext.getId())
.orElseGet(applicationContext::getDisplayName))
.build()))
.setResultAsGlobal()
.build()
.getOpenTelemetrySdk();
}
}
```