Add observability module: Spring AI built-in meters and spans, cost per endpoint from token usage, Prometheus and Grafana dashboard

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JXVi2GMQ7bR5EmbUFdDj7N
This commit is contained in:
Claude
2026-10-09 06:39:21 +00:00
parent 65f580c5bc
commit cc2a1b8bcb
45 changed files with 1731 additions and 0 deletions
@@ -0,0 +1,11 @@
# Profile used by scripts/stack-up.sh: adds the latency histogram Grafana needs for percentiles.
management:
metrics:
distribution:
percentiles-histogram:
gen_ai.client.operation: true
spring.ai.chat.client: true
minimum-expected-value:
gen_ai.client.operation: 50ms
maximum-expected-value:
gen_ai.client.operation: 30s
@@ -0,0 +1,31 @@
spring:
application:
name: spring-ai-observability
ai:
openai:
api-key: test-key-not-a-secret
base-url: ${FAKE_OPENAI_URL:http://localhost:8099}
chat:
options:
model: gpt-4o-mini
management:
endpoints:
web:
exposure:
include: health,prometheus,metrics
tracing:
sampling:
probability: 1.0
export:
otlp:
enabled: false # set true (and management.opentelemetry.tracing.export.otlp.endpoint) to ship spans to a Collector
otlp:
metrics:
export:
enabled: false # Prometheus scrapes /actuator/prometheus instead
ai:
# Illustrative prices in USD per million tokens. They are example numbers for the demo, not a current price list.
pricing:
models:
gpt-4o-mini: { input-per-million: 0.15, output-per-million: 0.60 }
gpt-4o: { input-per-million: 2.50, output-per-million: 10.00 }