Anvia SDK
@anvia/lens connects an Anvia agent directly to a Lens project. It turns agent runs, model generations, and tool calls into traces without requiring you to configure an OpenTelemetry SDK.
What the integration provides
Attach one Lens observer to an agent and Lens can show:
- The complete run from prompt to final response.
- A generation for every model turn, including model, duration, status, and usage.
- Tool calls nested under the generation that requested them.
- Errors on the run, generation, or tool where they occurred.
- User, session, tag, version, and custom metadata supplied for the request.
The integration creates its own isolated OpenTelemetry trace and log providers. It does not replace the application's global provider or collect unrelated application spans.
Connection flow
Anvia agent
-> Lens observer
-> authenticated OTLP export
-> Lens project
-> Traces, Sessions, and UsersThe public and secret ingestion keys select the destination project. Keep the integration in the server process that runs the agent; never expose the secret key in browser code.
Minimal connection
Install the package alongside Anvia Core:
pnpm add @anvia/lens @anvia/coreAdd the connection details shown on the Lens project's Connect page:
ANVIA_LENS_BASE_URL=https://lens.example.com
ANVIA_LENS_PUBLIC_KEY=pk-lens-...
ANVIA_LENS_SECRET_KEY=sk-lens-...
ANVIA_LENS_SERVICE_NAME=support-api
ANVIA_LENS_ENVIRONMENT=productionCreate the observer once, then reuse it across agents in the process:
import { AgentBuilder } from '@anvia/core'
import { lens } from '@anvia/lens'
const tracing = lens.create()
const supportAgent = new AgentBuilder('support', model)
.name('Support agent')
.observe(tracing)
.build()
const response = await supportAgent
.prompt('Summarize the latest support request.')
.send()
console.log(response.trace?.traceId)The request succeeds independently of when the batch exporter delivers its trace. Flush pending telemetry at the appropriate process boundary; see Flush and shutdown.
Where to go next
| Goal | Guide |
|---|---|
| Set credentials, service identity, and deployment context | Configure tracing |
| Group requests into users and sessions | Trace context |
| Control whether payloads leave the application | Capture and privacy |
| Deliver buffered telemetry reliably | Flush and shutdown |
Evaluation reporting and managed datasets use the same project connection, but they have their own workflow. Continue to Evaluations when the goal is measuring quality rather than observing live traffic.