Skip to main content

Lens with Docker Compose

Lens is the agent tracing and investigation service that pairs with the gateway. The gateway records traces of agent runs, with spans for each model call and tool use, and Lens stores them in ClickHouse, analyses them, and powers the Lens workspace embedded in the Admin UI. Lens runs as a separate worker so that analysis never slows the request path. This page runs it with Docker Compose next to a gateway.

A real-world scenario​

A developer wants to trace a new coding agent on one VM before asking the platform team for a cluster install. They add Lens and ClickHouse to the compose file that already runs the gateway, share two secrets through .env, and see the first trace in the Admin UI within minutes.

Steps​

  1. Generate the shared secrets into .env with the commands shown under Services, and add the Lens worker image from your preview access.

  2. Add the services shown in Services to your compose file next to the gateway, and set the gateway settings on the gateway service.

  3. Start everything.

    docker compose up -d
  4. Check the connection, then open Lens under Observability in the Admin UI and click Check setup on the Traces tab.

    curl http://localhost:4000/lens/service -H "Authorization: Bearer $SPANWAY_MASTER_KEY"

Expected result​

/lens/service reports the connection as configured and the worker as reachable, and the Admin UI's setup step reads "Trace storage is connected".

Services​

A Lens deployment has two containers: the Lens worker, and a ClickHouse database it writes traces to. The gateway reaches the worker over HTTP and authenticates with a shared gateway secret, and the worker calls back into the gateway with a service token.

services:
spanway:
image: registry.spanway.ai/spanway/spanway-ai:2.0.0
command: ["--config=/app/config.yaml"]
volumes:
- ./config.yaml:/app/config.yaml
ports:
- "4000:4000"
environment:
DATABASE_URL: "postgresql://llmproxy:dbpassword9090@db:5432/spanway"
SPANWAY_LENS_URL: "http://lens:4318"
SPANWAY_LENS_PUBLIC_URL: "http://localhost:4318"
env_file:
- .env
depends_on:
- db
- lens

lens:
image: ${LENS_IMAGE}
ports:
- "4318:4318"
environment:
CLICKHOUSE_HOST: clickhouse
CLICKHOUSE_PASSWORD: ${CLICKHOUSE_PASSWORD}
env_file:
- .env
depends_on:
- clickhouse

clickhouse:
image: clickhouse/clickhouse-server:26.9.6.6
environment:
CLICKHOUSE_PASSWORD: ${CLICKHOUSE_PASSWORD}
volumes:
- clickhouse_data:/var/lib/clickhouse

db:
image: postgres:16
environment:
POSTGRES_DB: spanway
POSTGRES_USER: llmproxy
POSTGRES_PASSWORD: dbpassword9090
volumes:
- postgres_data:/var/lib/postgresql/data

volumes:
clickhouse_data:
postgres_data:
Private preview

Spanway is in private preview. The container images and Helm charts will be published soon. To request access, write to sales@spanway.ai, and preview customers receive download instructions in their onboarding pack.

Put the shared secrets in .env, with the same values available to both containers. Docker Compose reads .env literally and never runs a command written inside it, so generate the values in your shell and append them, then add the image line by hand.

printf 'SPANWAY_MASTER_KEY=sk-%s\n' "$(openssl rand -hex 32)" >> .env
printf 'LENS_GATEWAY_SECRET=%s\n' "$(openssl rand -hex 32)" >> .env
printf 'SPANWAY_LENS_SERVICE_TOKEN=%s\n' "$(openssl rand -hex 32)" >> .env
printf 'LENS_ADMIN_TOKEN=%s\n' "$(openssl rand -hex 32)" >> .env
printf 'CLICKHOUSE_PASSWORD=%s\n' "$(openssl rand -hex 16)" >> .env
echo 'LENS_IMAGE=<the Lens worker image from your preview access>' >> .env

LENS_GATEWAY_SECRET must be 32 to 512 bytes and SPANWAY_LENS_SERVICE_TOKEN at least 32 characters, and the 64-character values above meet both.

LENS_ADMIN_TOKEN is required by the Lens worker, which stops with a configuration error when it is missing. The Lens worker listens on port 4318 unless SPANWAY_LENS_LISTEN says otherwise. The Lens worker image and its full list of settings are provided with your preview access. The ClickHouse version above matches the one the Helm chart bundles.

Gateway settings​

VariablePurpose
SPANWAY_LENS_URLInternal URL the gateway uses to reach the Lens worker.
SPANWAY_LENS_PUBLIC_URLURL the Admin UI uses to open Lens in the browser.
LENS_GATEWAY_SECRETShared secret that signs requests between the gateway and Lens. Both sides need the same value.
SPANWAY_LENS_SERVICE_TOKENToken the gateway presents to Lens when it exports request logs, reads traces and sends the span content policy. Both sides need the same value.
CLICKHOUSE_URLOptional. HTTP URL of the Lens ClickHouse server, for example http://lens_erase:<password>@clickhouse:8123. Without it, data subject erasure asks Lens to delete its copies through the service token. With it, the gateway deletes them directly, so the user must be allowed to delete from the Lens database.
CLICKHOUSE_DATABASEThe Lens database on that server. The gateway defaults to spanway while the Lens worker defaults to lens, so whenever you set CLICKHOUSE_URL in this setup, set CLICKHOUSE_DATABASE=lens on the gateway too, otherwise erasure looks in the wrong database.

With SPANWAY_LENS_SERVICE_TOKEN set, Lens keeps span inputs and outputs only as the gateway's content policy allows, which follows store_prompts_in_spend_logs and zero data retention, see What Spanway stores. A Lens started without it has no gateway connection and keeps span metadata only. Set LENS_KEEP_SPAN_CONTENT=true on such a Lens to keep span inputs and outputs. Lens refuses to start with that setting while SPANWAY_LENS_SERVICE_TOKEN is set, because the gateway's policy decides then.

Without a usable SPANWAY_LENS_URL, LENS_GATEWAY_SECRET and SPANWAY_LENS_SERVICE_TOKEN, the /lens routes return 503 with a message that names the setting to fix, and the Admin UI shows the setup panel instead of the workspace.

Verifying​

Start everything with docker compose up -d, open the Lens page in the Admin UI and use Check setup, or call the service endpoint.

curl http://localhost:4000/lens/service -H "Authorization: Bearer $SPANWAY_API_KEY"

The response reports whether the connection is configured and whether the worker answered. Run an agent request, then open the Lens workspace to see its trace. The agent trace endpoints under /v1/traces return the same data as JSON.

For Kubernetes, see Lens on Kubernetes.

Errors​

What you seeWhat it meansFix
/lens routes answer 503 naming a settingSPANWAY_LENS_URL is missing or not a URL, LENS_GATEWAY_SECRET is not 32 to 512 bytes, or SPANWAY_LENS_SERVICE_TOKEN is shorter than 32 characters.Fix the setting the message names on the gateway service.
.env holds the text $(openssl rand -hex 32)The secrets were written into .env by hand with the command inside.Generate them in the shell with the printf commands above.
Lens exits at startup with a configuration error naming LENS_ADMIN_TOKENThe token is missing from .env.Add LENS_ADMIN_TOKEN as shown above and start the stack again.
Lens refuses to startLENS_KEEP_SPAN_CONTENT=true is set together with SPANWAY_LENS_SERVICE_TOKEN.Remove LENS_KEEP_SPAN_CONTENT, the gateway's policy decides then.
The setup panel says the gateway does not reach Lens with the same service secretThe two sides hold different secrets.Use the same .env values for both containers.
Trace storage is unavailableClickHouse is not up or the password differs.Check the ClickHouse container log and CLICKHOUSE_PASSWORD.

Logs​

The gateway logs Lens content policy not sent, Lens keeps no span content: <error> at WARNING when it cannot reach the worker to send the content policy, and the Lens overview's Logs section explains both content policy lines. The worker logs to its own container output, so read it with docker compose logs lens.