Skip to content

Commit 4e65f5f

Browse files
authored
Merge pull request #9 from ajeetraina/add-observability
Add comprehensive observability features
2 parents 9f088b9 + 6a26ddf commit 4e65f5f

File tree

16 files changed

+2007
-28
lines changed

16 files changed

+2007
-28
lines changed

README.md

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This project showcases a complete Generative AI interface that includes:
88
- React/TypeScript frontend with a responsive chat UI
99
- Go backend server for API handling
1010
- Integration with Docker's Model Runner to run Llama 3.2 locally
11+
- Comprehensive observability with metrics, logging, and tracing
1112

1213
## Features
1314

@@ -18,17 +19,27 @@ This project showcases a complete Generative AI interface that includes:
1819
- 🏠 Run AI models locally without cloud API dependencies
1920
- 🔒 Cross-origin resource sharing (CORS) enabled
2021
- 🧪 Integration testing using Testcontainers
22+
- 📊 Metrics and performance monitoring
23+
- 📝 Structured logging with zerolog
24+
- 🔍 Distributed tracing with OpenTelemetry
25+
- 📈 Grafana dashboards for visualization
2126

2227
## Architecture
2328

24-
The application consists of three main components:
29+
The application consists of these main components:
2530

2631
```
2732
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
2833
│ Frontend │ >>> │ Backend │ >>> │ Model Runner│
2934
│ (React/TS) │ │ (Go) │ │ (Llama 3.2) │
3035
└─────────────┘ └─────────────┘ └─────────────┘
3136
:3000 :8080 :12434
37+
│ │
38+
┌─────────────┐ ┌─────┘ └─────┐ ┌─────────────┐
39+
│ Grafana │ <<< │ Prometheus │ │ Jaeger │
40+
│ Dashboards │ │ Metrics │ │ Tracing │
41+
└─────────────┘ └─────────────┘ └─────────────┘
42+
:3001 :9091 :16686
3243
```
3344

3445
## Connection Methods
@@ -75,6 +86,11 @@ docker model pull ignaciolopezluna020/llama3.2:1B
7586

7687
3. Access the frontend at [http://localhost:3000](http://localhost:3000)
7788

89+
4. Access observability dashboards:
90+
- Grafana: [http://localhost:3001](http://localhost:3001) (admin/admin)
91+
- Jaeger UI: [http://localhost:16686](http://localhost:16686)
92+
- Prometheus: [http://localhost:9091](http://localhost:9091)
93+
7894
## Development Setup
7995

8096
### Frontend
@@ -102,6 +118,10 @@ Make sure to set the required environment variables from `backend.env`:
102118
- `BASE_URL`: URL for the model runner
103119
- `MODEL`: Model identifier to use
104120
- `API_KEY`: API key for authentication (defaults to "ollama")
121+
- `LOG_LEVEL`: Logging level (debug, info, warn, error)
122+
- `LOG_PRETTY`: Whether to output pretty-printed logs
123+
- `TRACING_ENABLED`: Enable OpenTelemetry tracing
124+
- `OTLP_ENDPOINT`: OpenTelemetry collector endpoint
105125

106126
## How It Works
107127

@@ -110,6 +130,7 @@ Make sure to set the required environment variables from `backend.env`:
110130
3. The LLM processes the input and generates a response
111131
4. The backend streams the tokens back to the frontend as they're generated
112132
5. The frontend displays the incoming tokens in real-time
133+
6. Observability components collect metrics, logs, and traces throughout the process
113134

114135
## Project Structure
115136

@@ -122,17 +143,51 @@ Make sure to set the required environment variables from `backend.env`:
122143
│ │ ├── components/ # React components
123144
│ │ ├── App.tsx # Main application component
124145
│ │ └── ...
125-
│ ├── package.json # NPM dependencies
126-
│ └── ...
146+
├── pkg/ # Go packages
147+
│ ├── logger/ # Structured logging
148+
│ ├── metrics/ # Prometheus metrics
149+
│ ├── middleware/ # HTTP middleware
150+
│ ├── tracing/ # OpenTelemetry tracing
151+
│ └── health/ # Health check endpoints
152+
├── prometheus/ # Prometheus configuration
153+
├── grafana/ # Grafana dashboards and configuration
154+
├── observability/ # Observability documentation
127155
└── ...
128156
```
129157

158+
## Observability Features
159+
160+
The project includes comprehensive observability features:
161+
162+
### Metrics
163+
164+
- Model performance (latency, time to first token)
165+
- Token usage (input and output counts)
166+
- Request rates and error rates
167+
- Active request monitoring
168+
169+
### Logging
170+
171+
- Structured JSON logs with zerolog
172+
- Log levels (debug, info, warn, error, fatal)
173+
- Request logging middleware
174+
- Error tracking
175+
176+
### Tracing
177+
178+
- Request flow tracing with OpenTelemetry
179+
- Integration with Jaeger for visualization
180+
- Span context propagation
181+
182+
For more information, see [Observability Documentation](./observability/README.md).
183+
130184
## Customization
131185

132186
You can customize the application by:
133187
1. Changing the model in `backend.env` to use a different LLM
134188
2. Modifying the frontend components for a different UI experience
135189
3. Extending the backend API with additional functionality
190+
4. Customizing the Grafana dashboards for different metrics
136191

137192
## Testing
138193

@@ -148,6 +203,7 @@ go test -v
148203
- **Model not loading**: Ensure you've pulled the model with `docker model pull`
149204
- **Connection errors**: Verify Docker network settings and that Model Runner is running
150205
- **Streaming issues**: Check CORS settings in the backend code
206+
- **Metrics not showing**: Verify that Prometheus can reach the backend metrics endpoint
151207

152208
## License
153209

backend.env

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
BASE_URL: http://model-runner.docker.internal/engines/llama.cpp/v1/
22
MODEL: ai/llama3.2:1B-Q8_0
33
API_KEY: ${API_KEY:-dockermodelrunner}
4+
5+
# Observability configuration
6+
LOG_LEVEL: info
7+
LOG_PRETTY: true
8+
TRACING_ENABLED: true
9+
OTLP_ENDPOINT: jaeger:4318

compose.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ services:
66
target: backend
77
ports:
88
- '8080:8080'
9+
- '9090:9090' # Metrics port
910
healthcheck:
1011
test: ['CMD', 'wget', '-qO-', 'http://localhost:8080/health']
1112
interval: 3s
1213
timeout: 3s
1314
retries: 3
15+
networks:
16+
- app-network
1417

1518
frontend:
1619
build:
@@ -20,3 +23,54 @@ services:
2023
depends_on:
2124
backend:
2225
condition: service_healthy
26+
networks:
27+
- app-network
28+
29+
prometheus:
30+
image: prom/prometheus:v2.45.0
31+
volumes:
32+
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
33+
command:
34+
- '--config.file=/etc/prometheus/prometheus.yml'
35+
- '--storage.tsdb.path=/prometheus'
36+
- '--web.console.libraries=/etc/prometheus/console_libraries'
37+
- '--web.console.templates=/etc/prometheus/consoles'
38+
- '--web.enable-lifecycle'
39+
ports:
40+
- '9091:9090'
41+
networks:
42+
- app-network
43+
44+
grafana:
45+
image: grafana/grafana:10.1.0
46+
volumes:
47+
- ./grafana/provisioning:/etc/grafana/provisioning
48+
- grafana-data:/var/lib/grafana
49+
environment:
50+
- GF_SECURITY_ADMIN_PASSWORD=admin
51+
- GF_USERS_ALLOW_SIGN_UP=false
52+
- GF_SERVER_DOMAIN=localhost
53+
ports:
54+
- '3001:3000'
55+
depends_on:
56+
- prometheus
57+
networks:
58+
- app-network
59+
60+
jaeger:
61+
image: jaegertracing/all-in-one:1.46
62+
environment:
63+
- COLLECTOR_ZIPKIN_HOST_PORT=:9411
64+
ports:
65+
- '16686:16686' # UI
66+
- '4317:4317' # OTLP gRPC
67+
- '4318:4318' # OTLP HTTP
68+
networks:
69+
- app-network
70+
71+
volumes:
72+
grafana-data:
73+
74+
networks:
75+
app-network:
76+
driver: bridge

0 commit comments

Comments
 (0)