[NO-TICKET] Update Laminar Usage (#5322)

This commit is contained in:
Aaron Perez 2026-04-01 21:05:45 -05:00 committed by GitHub
parent 57aaee99b4
commit 39fc16ae69
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 47 additions and 13 deletions

View file

@ -110,6 +110,13 @@ PORT=8000
# ANALYTICS_ID: Distinct analytics ID (a UUID is generated if left blank).
ANALYTICS_ID="anonymous"
# LAMINAR
# Skyvern's backend runs on port 8000 by default. Consider updating your self-hosted laminar to env vars to avoid conflicts
# LMNR_HTTP_PORT=8010
# LMNR_GRPC_PORT=8011
# LMNR_BASE_URL=http://localhost
# LMNR_PROJECT_API_KEY=<your-laminar-project-api-key>
# 1Password Integration
# OP_SERVICE_ACCOUNT_TOKEN: API token for 1Password integration
OP_SERVICE_ACCOUNT_TOKEN=""

View file

@ -184,9 +184,18 @@ If you're running Skyvern on your own infrastructure, add these to your server's
LMNR_PROJECT_API_KEY=your-laminar-api-key
```
Skyvern's server includes a built-in `LaminarTrace` integration that initializes Laminar with the LiteLLM callback, capturing every LLM call, token count, and cost. It disables the automatic Skyvern/Patchright instrumentors (to avoid conflicts) and uses Laminar's `@observe` decorator on internal methods instead.
Skyvern's server initializes Laminar at startup, which auto-instruments LiteLLM to capture every LLM call, token count, and cost. No manual callback setup is needed.
No code changes needed — once the env var is set, traces appear in your Laminar project automatically.
If you're running a self-hosted Laminar instance, also set the base URL and ports:
```bash .env
LMNR_PROJECT_API_KEY=your-laminar-api-key
LMNR_BASE_URL=http://localhost
LMNR_GRPC_PORT=8011
LMNR_HTTP_PORT=8010
```
No code changes needed — once the env vars are set, traces appear in your Laminar project automatically.
---

View file

@ -18,24 +18,18 @@ Copy of this guide is available in the [Laminar documentation](https://docs.lmnr
## Quickstart
To trace Skyvern workflows with Laminar, **initialize Laminar and configure LiteLLM callbacks at the top of your project**. This will automatically capture all LLM calls, browser session recordings, and workflow execution details.
To trace Skyvern workflows with Laminar, **initialize Laminar at the top of your project**. This will automatically instrument LiteLLM and capture all LLM calls, browser session recordings, and workflow execution details. No manual callback setup is needed.
```python {3-4} {8-12} {14-15}
```python {3} {7-8}
from skyvern import Skyvern
import asyncio
import litellm
from lmnr import Laminar, LaminarLiteLLMCallback, Instruments
from lmnr import Laminar
from dotenv import load_dotenv
load_dotenv()
# Initialize Laminar
# This will automatically trace all Skyvern functions
# Disable OpenAI to avoid double instrumentation of LLM calls
Laminar.initialize(disabled_instruments=set([Instruments.OPENAI]))
# Configure LiteLLM to trace all LLM calls made by Skyvern
litellm.callbacks = [LaminarLiteLLMCallback()]
# Initialize Laminar — automatically instruments LiteLLM
Laminar.initialize()
skyvern = Skyvern(api_key="YOUR_API_KEY")
@ -49,6 +43,10 @@ if __name__ == "__main__":
asyncio.run(main())
```
<Warning>
`LaminarLiteLLMCallback` and manually setting `litellm.callbacks` are deprecated. `Laminar.initialize()` handles LiteLLM instrumentation automatically.
</Warning>
## Viewing Traces
You can view traces in the Laminar UI by navigating to the traces tab in your project. When you select a trace, you can see:

View file

@ -1,3 +1,4 @@
import os
import uuid
from contextlib import asynccontextmanager
from datetime import datetime
@ -211,6 +212,25 @@ def create_api_app() -> FastAPI:
forge_app_instance = start_forge_app()
# Initialize Laminar tracing after ForgeApp so auto-instrumentation works.
lmnr_api_key = os.environ.get("LMNR_PROJECT_API_KEY")
if lmnr_api_key:
try:
from lmnr import Laminar # noqa: PLC0415
lmnr_base_url = os.environ.get("LMNR_BASE_URL", "http://localhost")
lmnr_grpc_port = int(os.environ.get("LMNR_GRPC_PORT", "8001"))
lmnr_http_port = int(os.environ.get("LMNR_HTTP_PORT", "8000"))
Laminar.initialize(
project_api_key=lmnr_api_key,
base_url=lmnr_base_url,
grpc_port=lmnr_grpc_port,
http_port=lmnr_http_port,
)
LOG.info("Laminar tracing initialized", base_url=lmnr_base_url, grpc_port=lmnr_grpc_port)
except Exception as e:
LOG.warning("Failed to initialize Laminar tracing", error=str(e))
fastapi_app = FastAPI(lifespan=lifespan)
# Add CORS middleware