Lens Web SDK
The public frontend SDK is@lens/web.
Use it when you want to instrument a browser app and start sending telemetry to Lens with minimal setup.
Before you start
Make sure you have:- a Lens account
- a project in Lens
- a project API key
- a frontend app you can deploy
1. Create or find your API key
In Lens:- Open your project.
- Go to the API keys page.
- Create a key for your frontend app.
- Copy the secret value somewhere safe. You will use it in your frontend environment.
2. Install the SDK
3. Add frontend runtime configuration
Your browser app needs to expose three values to client-side code:- a Lens collector endpoint
- a Lens API key
- a stable service name
VITE_LENS_SERVICE_NAME should be stable and descriptive. Treat it as the service identity that will show up in Lens queries and dashboards.
4. Initialize Lens once at startup
5. Attach user identity after auth loads
Use an opaque internal ID, not email.6. Deploy and verify
After deploying:- Load the app in a browser.
- Navigate across a few routes.
- Trigger a handled or unhandled frontend error.
- Open Lens and confirm you see incoming page views, errors, and Web Vitals.
What is automatic
With@lens/web, Lens automatically captures:
- page views
- session start
- unhandled errors
- unhandled promise rejections
- Web Vitals
Troubleshooting
If you do not see data:- Confirm your deployed frontend environment exposes the Lens API key used by the SDK.
- Confirm your deployed frontend environment exposes the Lens OTLP endpoint and that it resolves to
https://collector.lens.sh. - Confirm the SDK is initialized exactly once.
- Confirm the browser network tab shows requests to
/v1/logs. - Confirm you are looking at the correct Lens project for that API key.
VITE_LENS_API_KEYVITE_LENS_OTLP_ENDPOINTVITE_LENS_SERVICE_NAME