SvelteKit chatbot with Coralogix RUM (Real User Monitoring), OpenTelemetry tracing, and Google Gemini 2.5 Flash Lite. Includes session replay, trace propagation from frontend to backend, and AI span tracing for observability in Coralogix.
/sourcenpm install
cd backend && python -m venv .venv && .venv/bin/pip install -r requirements.txt
Copy the env template and add your keys (backend also reads from project root .env):
cp .env.template .env
Edit .env with your values:
| Variable | Description |
|---|---|
OTEL_EXPORTER_OTLP_ENDPOINT |
OTLP gRPC address for the Python API and Node build (default http://localhost:4317); targets your OpenTelemetry Collector. |
CORALOGIX_PRIVATE_KEY |
Send-Your-Data key for otel-collector-config.yaml so the collector exports to Coralogix (not used by the app process for OTLP). |
CORALOGIX_GUARDRAILS_KEY |
Optional. Separate Guardrails API key for /api/chat checks — do not reuse the OTLP ingestion key (OTLP keys do not work on the Guardrails HTTP API). |
GUARDRAILS_ENABLED |
Optional. true to enforce blocking on policy hits; false for observe-only (default). |
VITE_CORALOGIX_RUM_KEY |
Coralogix RUM key (browser monitoring) |
GEMINI_API_KEY |
Google AI Studio API key |
VITE_CHAT_API_URL |
Backend API URL (default: http://localhost:8000) |
Terminal 1 – Backend
npm run api
Terminal 2 – Frontend
npm run dev
| Script | Description |
|---|---|
npm run dev |
Start Svelte dev server (port 5173) |
npm run api |
Start Python FastAPI backend (port 8000) |
npm run build |
Build frontend for production |
npm run start |
Run production frontend (port 3000) |
npm run test:rum |
Run RUM test harness once (BASE_URL default localhost:5173) |
npm run test:rum:both |
Run harness against BASE_URL_TEAM_A then BASE_URL_TEAM_B (dual RUM stacks; see .env.template) |
npm run test:rum:loop |
Run RUM harness every 5 minutes |
├── backend/ # Python FastAPI + Gemini
│ ├── main.py # Chat API, OTLP traces/logs + GenAI instrumentation → collector
│ └── requirements.txt
├── src/
│ ├── lib/
│ │ ├── coralogix-rum.ts # RUM init, session replay, user context
│ │ └── app.css
│ └── routes/
│ ├── +layout.svelte # RUM init on mount
│ ├── +page.svelte # Chat UI
│ └── source/ # Source code viewer
├── tests/
│ ├── rum-harness.mjs # Puppeteer RUM tests
│ ├── run-rum-both.mjs # Sequential runs for two stacks (dual RUM keys)
│ └── rum-harness-loop.mjs # Loop harness every 5 min
└── instrumentation.cjs # OpenTelemetry (production)
The test harness sends duck, egg, and chocolate questions to generate data for the following Policy Catalog evaluators. Configure these in the Coralogix UI under AI Center → Policy Catalog:
| Evaluator type | Value | Effect |
|---|---|---|
| Restricted topic | duck |
Flags duck-related conversations as off-topic |
| Allowed topic | egg |
Egg-related content passes the topic check |
| Competitor | chocolate |
Flags chocolate references as a competitor mention |
The harness (tests/rum-harness.mjs) sends questions covering all three topics plus the guardrail probes (PII, prompt injection, toxicity) in every run. After ~5 minutes the AI Center will show evaluator hits for duck conversations (restricted) and chocolate mentions (competitor).
Call setCoralogixUserContext() after login to associate RUM sessions with users:
import { setCoralogixUserContext } from '$lib/coralogix-rum';
setCoralogixUserContext({
userId: 'user-123',
userName: 'Jane Doe',
userEmail: '[email protected]'
});
MIT