A React + Vite application deployed on Cloudflare Pages using only braintrust/browser for tracing. No OpenTelemetry or other telemetry setup required.
- Uses
tracedfrombraintrust/browserfor function tracing - Uses
initLoggerfrombraintrust/browserfor logging - Uses
wrapAiSdkfrombraintrust/browserto wrap the Vercel AI SDK - Simple weather chat assistant with React UI
- Runs on Cloudflare Pages with Functions
- Install mise (if not already installed):
curl https://mise.run | sh
# or
brew install mise- Install Node.js and npm via mise:
mise install- Install dependencies:
npm install-
Set up environment variables:
Non-secret variables are already configured in
wrangler.tomlunder[vars].For secrets (API keys), you have two options:
Option A: Local development - Create a
.dev.varsfile in the root directory:BRAINTRUST_API_KEY=your-key-here OPENAI_API_KEY=your-key-here(Note:
BRAINTRUST_PROJECT_NAMEis already inwrangler.toml, so you don't need it here)Option B: Production deployment - Use Cloudflare Pages secrets:
wrangler pages secret put BRAINTRUST_API_KEY wrangler pages secret put OPENAI_API_KEY
Or set them via the Cloudflare Dashboard:
- Go to your Pages project
- Settings → Environment Variables
- Add secrets for production/preview environments
-
Build the project:
npm run build- Run locally:
npm run dev- Deploy to Cloudflare Pages:
npm run deployNote: wrangler pages deploy creates a preview deployment by default. To deploy to production:
- Option A: Promote the preview in Cloudflare Dashboard (Settings → Deployments → Promote to production)
- Option B: Use Git integration - connect your repo to Cloudflare Pages for automatic production deployments from your main branch
- Option C: After deploying, promote via CLI:
wrangler pages deployment promote <deployment-id> --project-name=simple-span-example
Visit the app in your browser and use the chat interface to ask about weather in any location. For example:
- "What's the weather in San Francisco?"
- "Tell me about the weather in Tokyo"
- "How's the weather in New York?"
The assistant will use the getWeather tool to fetch weather data and respond with the current weather in Fahrenheit.
src/- React application (Vite)functions/api/chat.ts- Cloudflare Pages Function for chat API usingtraced,initLogger, andwrapAiSdksrc/tools.ts- Weather tool usingtracedfor Braintrust spans
No OpenTelemetry or other telemetry libraries are used - everything goes through Braintrust.