Python SDK for AI agent monitoring, LLM cost tracking, benchmarking, and more. Integrates with most LLMs and agent frameworks including CrewAI, Agno, OpenAI Agents SDK, Langchain, Autogen, AG2, and CamelAI
Python agentagentopsagents-sdkaianthropicautogencost-estimationcrewaievalsevaluation-metricsgroqlangchainllmmistralollamaopenaiopenai-agents
fix cors on local (#1234)
Alex Reibman68fba2b2d2c1
diff --git a/app/README.md b/app/README.mdindex 15c2d459..517c7815 100644--- a/app/README.md+++ b/app/README.md@@ -296,6 +296,24 @@ AgentOps requires several external services. Here's how to set them up:### Supabase (Required)+**Option A: Local Development (Recommended)**++1. Install Supabase CLI: `brew install supabase/tap/supabase` (or see [docs](https://supabase.com/docs/guides/cli))+2. Initialize and start Supabase locally:+ ```bash+ cd app # Make sure you're in the app directory+ supabase init+ supabase start+ ```+3. The local Supabase will provide connection details. Update your `.env` files with:+ ```+ SUPABASE_URL=http://127.0.0.1:54321+ SUPABASE_KEY=<anon-key-from-supabase-start-output>+ ```+4. Run migrations: `supabase db push`++**Option B: Cloud Supabase**+1. Create a new project at [supabase.com](https://supabase.com)2. Go to Settings → API to get your keys3. Update your `.env` files with:@@ -319,7 +337,25 @@ AgentOps requires several external services. Here's how to set them up:### PostgreSQL (Required)Configure direct PostgreSQL connection:-1. Use your Supabase PostgreSQL connection details++**For Local Supabase:**+```+POSTGRES_HOST=127.0.0.1+POSTGRES_PORT=54322 # Note: Different port than Supabase API+POSTGRES_USER=postgres+POSTGRES_PASSWORD=postgres+POSTGRES_DATABASE=postgres++# Also add these for SQLAlchemy connections:+SUPABASE_HOST=127.0.0.1+SUPABASE_PORT=54322+SUPABASE_USER=postgres+SUPABASE_PASSWORD=postgres+SUPABASE_DATABASE=postgres+```++**For Cloud Supabase:**+1. Use your Supabase PostgreSQL connection details from Settings → Database2. Update your `.env` files with:```POSTGRES_HOST=your-supabase-host@@ -391,6 +427,51 @@ bun run lintbun run format```+## 🔍 Troubleshooting++### Authentication Issues++**Problem: Login succeeds but immediately redirects back to login page**++This is usually caused by cookie configuration issues between the frontend and backend.++**Solutions:**++1. **Check your environment URLs**: Ensure `NEXT_PUBLIC_API_URL` in dashboard points to your API server:+ ```bash+ # dashboard/.env.local+ NEXT_PUBLIC_API_URL=http://localhost:8000 # For local development+ ```++2. **Verify JWT secret**: Make sure `JWT_SECRET_KEY` is set in your API `.env`:+ ```bash+ # api/.env+ JWT_SECRET_KEY=your-secret-key-at-least-32-chars+ ```++3. **For local development with different ports**: The API automatically adjusts cookie settings for localhost. No manual configuration needed.++4. **For production or custom domains**: Ensure your API and dashboard share the same root domain for cookies to work.++### Database Connection Issues++**Problem: SQLAlchemy connection errors**++Ensure all Supabase database variables are set in `api/.env`:+```bash+SUPABASE_HOST=127.0.0.1 # For local Supabase+SUPABASE_PORT=54322 # Note: Different from API port+SUPABASE_USER=postgres+SUPABASE_PASSWORD=postgres+SUPABASE_DATABASE=postgres+```++### Supabase Seed Data Issues++**Problem: Duplicate key or missing table errors during `supabase start`**++The seed.sql file may have issues. You can temporarily comment out problematic inserts or check if migrations are missing.+## 📦 Production Deployment### Using Docker Composediff --git a/app/api/agentops/app.py b/app/api/agentops/app.pyindex 5ff4a931..31664e50 100644--- a/app/api/agentops/app.py+++ b/app/api/agentops/app.py@@ -9,6 +9,7 @@ domain-specific middleware for each sub-app."""from fastapi import FastAPI+from fastapi.middleware.cors import CORSMiddlewareimport sentry_sdkfrom agentops.api.log_config import logger@@ -41,6 +42,17 @@ app = FastAPI(logger.info("⚡️FastAPI app initialized")logger.info(f"Docs available at: {app.docs_url}" if app.docs_url else "Docs disabled")+# Add CORS middleware for local development+if "localhost" in API_DOMAIN or "127.0.0.1" in API_DOMAIN:+ app.add_middleware(+ CORSMiddleware,+ allow_origins=["http://localhost:3000", "http://127.0.0.1:3000"],+ allow_credentials=True,+ allow_methods=["*"],+ allow_headers=["*"],+ )+ logger.info("CORS middleware enabled for local development")+# Configure the mounted apps# TODO this is redundant, but it's just for docsmounted_apps = {diff --git a/app/api/agentops/auth/views.py b/app/api/agentops/auth/views.pyindex fba7d2da..560043ad 100644--- a/app/api/agentops/auth/views.py+++ b/app/api/agentops/auth/views.py@@ -305,7 +305,10 @@ def _create_session_for_response(response: Response, access_token: str) -> Respocookie_value = _encode_session_cookie(session)cookie_domain = _get_api_domain()+ # Use secure cookies only with HTTPScookie_secure = 'https' in API_URL+ # Use 'lax' for HTTP (development) to allow cross-origin requests, 'strict' for HTTPS (production)+ cookie_samesite = "lax" if not cookie_secure else "strict"response.set_cookie(key=AUTH_COOKIE_NAME,@@ -314,7 +317,7 @@ def _create_session_for_response(response: Response, access_token: str) -> Resposecure=cookie_secure, # only send over https in productiondomain=cookie_domain, # set cookie for the api domainmax_age=AUTH_COOKIE_EXPIRY,- samesite="strict",+ samesite=cookie_samesite,path="/", # valid across all paths)diff --git a/app/api/uv.lock b/app/api/uv.lockindex 5b0782c0..31741984 100644--- a/app/api/uv.lock+++ b/app/api/uv.lock@@ -1,5 +1,5 @@version = 1-revision = 3+revision = 2requires-python = "==3.12.*"resolution-markers = ["platform_python_implementation != 'PyPy'",@@ -16,6 +16,7 @@ dependencies = [{ name = "clickhouse-driver" },{ name = "dotenv" },{ name = "fastapi" },+ { name = "gotrue" },{ name = "greenlet" },{ name = "httpcore" },{ name = "httpx" },@@ -66,6 +67,7 @@ requires-dist = [{ name = "clickhouse-driver", specifier = ">=0.2.9" },{ name = "dotenv", specifier = ">=0.9.9" },{ name = "fastapi", specifier = ">=0.110.0" },+ { name = "gotrue", specifier = ">=2.12.4" },{ name = "greenlet", specifier = ">=3.1.1" },{ name = "httpcore", specifier = ">=1.0.5" },{ name = "httpx", specifier = ">=0.27.0" },@@ -545,15 +547,16 @@ wheels = [[[package]]name = "gotrue"-version = "2.11.4"+version = "2.12.4"source = { registry = "https://pypi.org/simple" }dependencies = [{ name = "httpx", extra = ["http2"] },{ name = "pydantic" },+ { name = "pyjwt" },]-sdist = { url = "https://files.pythonhosted.org/packages/19/9c/62c3241731b59c1c403377abef17b5e3782f6385b0317f6d7083271db501/gotrue-2.11.4.tar.gz", hash = "sha256:a9ced242b16c6d6bedc43bca21bbefea1ba5fb35fcdaad7d529342099d3b1767", size = 35353, upload-time = "2025-02-20T09:02:37.346Z" }+sdist = { url = "https://files.pythonhosted.org/packages/aa/6c/fe920e91959bd211325860332be5898b6b53d6ccd873c053fc5cc829020c/gotrue-2.12.4.tar.gz", hash = "sha256:35d2e58e066486321f4dff0033b30a53d057c7f436c15287122fa0cb833029b1", size = 34817, upload-time = "2025-08-08T15:55:49.393Z" }wheels = [- { url = "https://files.pythonhosted.org/packages/47/3a/1a7cac16438f4e5319a0c879416d5e5032c98c3db2874e6e5300b3b475e6/gotrue-2.11.4-py3-none-any.whl", hash = "sha256:712e5018acc00d93cfc6d7bfddc3114eb3c420ab03b945757a8ba38c5fc3caa8", size = 41106, upload-time = "2025-02-20T09:02:34.653Z" },+ { url = "https://files.pythonhosted.org/packages/9a/2f/0e68d566d9339b8d320399d755704e17a94a123cf22f124b4ab2f686bcc3/gotrue-2.12.4-py3-none-any.whl", hash = "sha256:cf36dfcebc1da63b8d1e7b93eb1a35dfee3dcb1e1376833c256464010eb5fcd6", size = 42783, upload-time = "2025-08-08T15:55:48.289Z" },][[package]]diff --git a/app/supabase/seed.sql b/app/supabase/seed.sqlindex 18ed9dff..0ffa2db5 100644--- a/app/supabase/seed.sql+++ b/app/supabase/seed.sql@@ -112,14 +112,15 @@ INSERT INTO public.user_orgs ('owner');-INSERT INTO public.user_orgs (- user_id, org_id, user_email, role-) VALUES (- 'e043e8e0-504d-4e80-83ee-c42c47c63d8b',- 'c0000000-0000-0000-0000-000000000000',- '[email protected]',- 'business_user'-);+-- Commented out duplicate key constraint+-- INSERT INTO public.user_orgs (+-- user_id, org_id, user_email, role+-- ) VALUES (+-- 'e043e8e0-504d-4e80-83ee-c42c47c63d8b',+-- 'c0000000-0000-0000-0000-000000000000',+-- '[email protected]',+-- 'business_user'+-- );INSERT INTO public.projects (id,@@ -232,17 +233,18 @@ INSERT INTO public.errors ('2024-03-06 11:15:13.761+00');-INSERT INTO public.deployments (- id, project_id, created_at, shutdown_time, image_id, is_active, build_log-) VALUES (- 'd1e1f9df-8980-4afc-9041-2e116dc7ad0e',- '0e2bf9df-8980-4afc-9041-2e116dc7ad0e',- '2024-03-05T21:16:00Z',- NULL,- 'img-123',- TRUE,- NULL-);+-- Temporarily disabled: deployments table+-- INSERT INTO public.deployments (+-- id, project_id, created_at, shutdown_time, image_id, is_active, build_log+-- ) VALUES (+-- 'd1e1f9df-8980-4afc-9041-2e116dc7ad0e',+-- '0e2bf9df-8980-4afc-9041-2e116dc7ad0e',+-- '2024-03-05T21:16:00Z',+-- NULL,+-- 'img-123',+-- TRUE,+-- NULL+-- );INSERT INTO public.spans (id, session_id, agent_id, trace_id, span_id, parent_span_id, name, kind, start_time, end_time, attributes, span_type