Skip to content

Commit 3234826

Browse files
committed
fix: add production support for demo script and correlation ID tracing
- Add environment detection (dev vs prod) in demo script - Handle webhook signature verification gracefully in production - Add make trace-recent: show recent correlation IDs from logs - Add make trace-id ID=<id>: trace specific request E2E - Auto-detect container names (-prod suffix in production) - Simplify demo script to use new trace commands - Update observability guide with production tracing instructions Fixes demo command in production where signature verification blocks test webhooks
1 parent 6b0ba87 commit 3234826

3 files changed

Lines changed: 129 additions & 15 deletions

File tree

Makefile

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# DispatchAI Development Makefile
22
# Provides targets for development, testing, linting, and deployment
33

4-
.PHONY: help dev dev-up dev-down dev-logs dev-clean test test-docker test-ingress test-classifier test-gateway test-dashboard test-classifier-docker test-gateway-docker test-dashboard-docker lint lint-python lint-python-docker lint-js clean build setup-env check-env check-containers test-webhook-manual demo kafka-tail health health-ingress health-classifier health-gateway metrics metrics-ingress metrics-classifier metrics-gateway metrics-summary watch-metrics system-status
4+
.PHONY: help dev dev-up dev-down dev-logs dev-clean test test-docker test-ingress test-classifier test-gateway test-dashboard test-classifier-docker test-gateway-docker test-dashboard-docker lint lint-python lint-python-docker lint-js clean build setup-env check-env check-containers test-webhook-manual demo trace-recent trace-id kafka-tail health health-ingress health-classifier health-gateway metrics metrics-ingress metrics-classifier metrics-gateway metrics-summary watch-metrics system-status
55

66
# Default target
77
help: ## Show this help message
@@ -276,6 +276,50 @@ demo: ## Run comprehensive system showcase demo (perfect for interviews!)
276276
echo "❌ Demo script not found at scripts/demo-system-showcase.sh"; \
277277
fi
278278

279+
trace-recent: ## Show recent correlation IDs and trace one (for production demos)
280+
@echo "Recent Correlation IDs:"
281+
@echo "======================="
282+
@if docker ps --format "{{.Names}}" | grep -q "dispatchai-ingress-prod"; then \
283+
docker logs dispatchai-ingress-prod 2>&1 | grep "correlation_id" | grep "Webhook processed successfully" | tail -10 | sed 's/.*correlation_id"://' | sed 's/,.*//' | sed 's/"//g'; \
284+
echo ""; \
285+
echo "To trace a specific ID, run:"; \
286+
echo " make trace-id ID=<correlation-id-from-above>"; \
287+
else \
288+
docker logs dispatchai-ingress 2>&1 | grep "correlation_id" | grep "Webhook processed successfully" | tail -10 | sed 's/.*correlation_id"://' | sed 's/,.*//' | sed 's/"//g'; \
289+
echo ""; \
290+
echo "To trace a specific ID, run:"; \
291+
echo " make trace-id ID=<correlation-id-from-above>"; \
292+
fi
293+
294+
trace-id: ## Trace a specific correlation ID through all services (usage: make trace-id ID=abc-123)
295+
@if [ -z "$(ID)" ]; then \
296+
echo "❌ Usage: make trace-id ID=<correlation-id>"; \
297+
echo "Get recent IDs with: make trace-recent"; \
298+
exit 1; \
299+
fi
300+
@echo "Tracing correlation_id: $(ID)"
301+
@echo "======================================"
302+
@echo ""
303+
@if docker ps --format "{{.Names}}" | grep -q "dispatchai-ingress-prod"; then \
304+
echo "📊 Ingress Service:"; \
305+
docker logs dispatchai-ingress-prod 2>&1 | grep "$(ID)" | head -10; \
306+
echo ""; \
307+
echo "🤖 Classifier Service:"; \
308+
docker logs dispatchai-classifier-prod 2>&1 | grep "$(ID)" | head -10; \
309+
echo ""; \
310+
echo "🔗 Gateway Service:"; \
311+
docker logs dispatchai-gateway-prod 2>&1 | grep "$(ID)" | head -10; \
312+
else \
313+
echo "📊 Ingress Service:"; \
314+
docker logs dispatchai-ingress 2>&1 | grep "$(ID)" | head -10; \
315+
echo ""; \
316+
echo "🤖 Classifier Service:"; \
317+
docker logs dispatchai-classifier 2>&1 | grep "$(ID)" | head -10; \
318+
echo ""; \
319+
echo "🔗 Gateway Service:"; \
320+
docker logs dispatchai-gateway 2>&1 | grep "$(ID)" | head -10; \
321+
fi
322+
279323
# Linting
280324
lint: ## Run all linters
281325
@echo "Running all linters..."

docs/OBSERVABILITY_GUIDE.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,22 @@ Automatically:
153153
- Searches all service logs
154154
- Verifies E2E tracing works
155155

156+
### Production Tracing (with Signature Verification)
157+
158+
In production, webhook signature verification is enabled. To trace issues:
159+
160+
**View recent correlation IDs:**
161+
```bash
162+
make trace-recent
163+
```
164+
165+
**Trace a specific ID:**
166+
```bash
167+
make trace-id ID=abc-123-def-456
168+
```
169+
170+
This works in both dev and production environments, automatically detecting the correct container names.
171+
156172
---
157173

158174
## Kafka Consumer Monitoring
@@ -408,6 +424,8 @@ Target: Classification >95% → Current: Issues processed without errors ✅ On
408424
| `make metrics-summary` | Quick metrics view | Live presentations |
409425
| `make watch-metrics` | Real-time monitoring | Show system under load |
410426
| `make health` | Service health checks | Verify dependencies |
427+
| `make trace-recent` | Show recent correlation IDs | Production tracing |
428+
| `make trace-id ID=<id>` | Trace specific request | E2E debugging |
411429
| `make kafka-describe-group` | Consumer lag details | Debug backpressure |
412430
| `./scripts/demo-system-showcase.sh` | Automated demo script | E2E demonstration |
413431

scripts/demo-system-showcase.sh

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ echo "This script demonstrates the complete observability"
99
echo "and monitoring capabilities of the DispatchAI system."
1010
echo ""
1111

12+
# Detect environment (dev or production)
13+
if docker ps --format "{{.Names}}" | grep -q "dispatchai-ingress-prod"; then
14+
ENV="prod"
15+
CONTAINER_SUFFIX="-prod"
16+
echo "🔍 Detected: Production environment"
17+
else
18+
ENV="dev"
19+
CONTAINER_SUFFIX=""
20+
echo "🔍 Detected: Development environment"
21+
fi
22+
echo ""
23+
1224
echo "Step 1: Verify all services are running..."
1325
echo "==========================================="
1426
make check-containers
@@ -80,15 +92,37 @@ EOF
8092
)
8193

8294
echo "Sending webhook to http://localhost:8000/webhook/github..."
95+
96+
# Generate HMAC signature if in production (signature verification enabled)
97+
if [ "$ENV" = "prod" ]; then
98+
# In production, we need a valid signature
99+
# For demo purposes, we'll note that signature verification would need the secret
100+
echo "⚠️ Note: Production requires valid GitHub webhook signature"
101+
echo "For demo purposes, sending without signature (will be rejected by security)"
102+
echo ""
103+
fi
104+
83105
RESPONSE=$(curl -s -X POST http://localhost:8000/webhook/github \
84106
-H "Content-Type: application/json" \
85107
-H "X-GitHub-Event: issues" \
108+
-H "X-Hub-Signature-256: sha256=demo" \
86109
-d "$WEBHOOK_PAYLOAD")
87110

88111
echo "$RESPONSE" | python3 -m json.tool 2>/dev/null || echo "$RESPONSE"
89-
CORRELATION_ID=$(echo "$RESPONSE" | python3 -c "import sys, json; print(json.load(sys.stdin).get('correlation_id', 'N/A'))" 2>/dev/null || echo "N/A")
112+
113+
# Check if we got an error response
114+
if echo "$RESPONSE" | grep -q "Invalid signature"; then
115+
echo ""
116+
echo "⚠️ Webhook rejected: Invalid signature (expected in production)"
117+
echo "📝 In production, webhooks must come from GitHub with valid signatures"
118+
echo "📝 For testing, you can temporarily disable signature verification or use the actual webhook endpoint"
119+
CORRELATION_ID="N/A"
120+
else
121+
CORRELATION_ID=$(echo "$RESPONSE" | python3 -c "import sys, json; print(json.load(sys.stdin).get('correlation_id', 'N/A'))" 2>/dev/null || echo "N/A")
122+
fi
123+
90124
echo ""
91-
echo "Webhook sent with correlation_id: $CORRELATION_ID"
125+
echo "Webhook result: correlation_id=$CORRELATION_ID"
92126
echo ""
93127
sleep 2
94128

@@ -113,23 +147,18 @@ echo "Step 7: Trace the issue through all services using correlation ID..."
113147
echo "===================================================================="
114148
echo ""
115149
echo "This demonstrates E2E distributed tracing capability."
116-
echo "Searching logs for correlation_id: $CORRELATION_ID"
117150
echo ""
118151

119152
if [ "$CORRELATION_ID" != "N/A" ]; then
120-
echo "--- Ingress Service Logs ---"
121-
docker logs dispatchai-ingress 2>&1 | grep "$CORRELATION_ID" | tail -5 || echo "No logs found"
153+
echo "Using make trace-id to trace correlation_id: $CORRELATION_ID"
122154
echo ""
123-
124-
echo "--- Classifier Service Logs ---"
125-
docker logs dispatchai-classifier 2>&1 | grep "$CORRELATION_ID" | tail -5 || echo "Processing may still be in progress or logs not yet available"
155+
make trace-id ID="$CORRELATION_ID"
156+
else
157+
echo "⚠️ Could not extract correlation ID from test webhook"
126158
echo ""
127-
128-
echo "--- Gateway Service Logs ---"
129-
docker logs dispatchai-gateway 2>&1 | grep "$CORRELATION_ID" | tail -5 || echo "Processing may still be in progress or logs not yet available"
159+
echo "💡 Demonstrating with a recent real webhook instead:"
130160
echo ""
131-
else
132-
echo "⚠️ Could not extract correlation ID from response"
161+
make trace-recent
133162
fi
134163

135164
sleep 2
@@ -138,14 +167,33 @@ echo "======================================"
138167
echo "✅ Demo Complete!"
139168
echo "======================================"
140169
echo ""
170+
echo "Environment: $ENV"
171+
echo ""
141172
echo "Key Takeaways:"
142173
echo "-------------"
143174
echo "1. ✅ All services expose /health endpoints with dependency verification"
144175
echo "2. ✅ All services expose /metrics endpoints with p50/p95/p99 latencies"
145-
echo "3. ✅ Correlation IDs enable E2E tracing in <1 minute"
176+
if [ "$CORRELATION_ID" != "N/A" ]; then
177+
echo "3. ✅ Correlation IDs enable E2E tracing in <1 minute"
178+
else
179+
echo "3. ⚠️ Correlation ID tracing (blocked by signature verification in production)"
180+
fi
146181
echo "4. ✅ System processes webhooks in 3-5 seconds end-to-end"
147182
echo "5. ✅ Consumer lag monitoring shows classifier keeping up with load"
148183
echo ""
184+
185+
if [ "$ENV" = "prod" ]; then
186+
echo "🔒 Production Security Note:"
187+
echo "----------------------------"
188+
echo "Webhook signature verification is enabled (as it should be!)"
189+
echo "Test webhooks are rejected, but real GitHub webhooks work perfectly."
190+
echo ""
191+
echo "To trace real production webhooks:"
192+
echo " make trace-recent # View recent correlation IDs"
193+
echo " make trace-id ID=<id> # Trace a specific request"
194+
echo ""
195+
fi
196+
149197
echo "Available Commands:"
150198
echo "------------------"
151199
echo " make health - View all service health checks"
@@ -154,6 +202,10 @@ echo " make metrics-summary - View quick metrics summary"
154202
echo " make system-status - View complete system status"
155203
echo " make watch-metrics - Watch metrics in real-time"
156204
echo ""
205+
echo "Correlation ID Tracing:"
206+
echo " make trace-recent - Show recent correlation IDs"
207+
echo " make trace-id ID=<id> - Trace specific request E2E"
208+
echo ""
157209
echo "For detailed analysis:"
158210
echo " make health-ingress - Ingress service health only"
159211
echo " make metrics-classifier - Classifier service metrics only"

0 commit comments

Comments
 (0)