Skip to content

Cratis Lens — inspect and exercise Arc apps

Last released · v1.2.0

Cratis Lens is a browser extension for exercising a running Cratis Arc app’s commands and queries with development users and tenants. Use it when you need to send a specific payload or compare query results between tenants without building a throwaway page. Commands run against the connected backend and can change its data, so choose an app and test identities you intend to use for development.

Lens opens as a popup with five tabs. When the current tab is a running Arc application, Lens detects it and enables the command, query, and diagnostics tabs; on any other page only Context and Settings are available.

Choose a user and tenant in Context, then open Commands or Queries. Both group the app’s operations by namespace. Commands use a form built from the command’s schema and show the result or validation errors. Queries accept parameters and show returned data in a table. Lens discovers these operations through /.cratis/commands and /.cratis/queries on the detected backend.

If an observable query stops updating, open Query Diagnostics to inspect its connection health, transport, shared connection (the multiplexer), and cache state. Use Settings to add development identities or refresh the users and tenants supplied by the app.

Lens detects the backend address from the running page’s Arc context and saves it with the page origin. Open the popup on the intended app before running an operation; if detection fails, the command, query, and diagnostics tabs stay disabled. Lens does not read Chronicle CLI connection contexts.

Current Arc derives the identity from each request’s authentication and exposes it through the /.cratis/me endpoint, so the headers below are what changes the identity. When you switch user or tenant, Lens also clears the .cratis-identity cookie for the detected backend and page origins and reloads matching tabs. That cookie is only written by older Arc backends; current Arc neither reads nor writes it, and clearing it is compatibility behavior for those older backends. Lens sends the tenant in x-cratis-tenant-id by default and the selected user’s identity in x-ms-client-principal, x-ms-client-principal-id, and x-ms-client-principal-name headers.

Where the tenant and user roster comes from

Section titled “Where the tenant and user roster comes from”

Lens requests GET /.cratis/tenants and GET /.cratis/users from the detected backend. In C#, supply their data through ICanProvideTenants and ICanProvideUsers. The Kotlin/Java Spring Boot integration uses TenantsProvider and UsersProvider, including adapters for asynchronous Java providers. Each host can combine multiple providers. A successful response with no registered providers is an empty array, so there are no backend-supplied entries to select.

When you open the Lens popup on a page it recognizes as a running Arc application, it fetches both endpoints and merges the result into its own roster (each entry tagged Arc). You can also add entries by hand from Lens itself. Those are tagged Custom and survive even when the backend’s own list changes or is temporarily unreachable.

The screenshots show a roster with three demo users and two demo tenants.

Lens Context tab showing the active user, Alice Developer, and the active tenant, ACME Corporation

The Context tab shows the active user and tenant for this browser profile. Choose either from the merged roster, or clear a selection to stop Lens adding its headers. Switching reloads matching tabs, so save any unfinished work in the app first. The backend still decides how to authenticate the request and which tenant’s data it can access; a roster entry alone grants no access.

Lens Settings tab, Users pane, listing Alice Developer, Bob Tester and Priya Singh, each tagged Arc

Lens Settings tab, Tenants pane, listing ACME Corporation and Widget Inc, each tagged Arc

The Settings tab lists every known user and tenant, each with an Arc or Custom badge so you can tell whether an entry came from the backend’s providers or was added locally. The green Active badge marks the selection currently in effect. Use the eye icon to inspect the full identity or tenant payload the backend returned, the + to add a custom entry, and the refresh icon to fetch again from the backend without reopening the popup.

See Development users and tenants (C#) or Development users and tenants (Kotlin and Java) for how to implement a provider, and Tenancy in Arc for how this discovery seam relates to actual tenant resolution at request time.

Open the Chrome Web Store listing and choose Add to Chrome. Then navigate to your running Arc app and open the Lens popup so it can detect the backend and load its development roster. Check the active user and tenant in Context before executing a command.

To work on Lens itself or use a source change, build and load it as an unpacked Chrome extension. You need Node.js 20 or later, Yarn, and Chrome. The source is at github.com/Cratis/Lens.

  1. Clone the repo, then from the Source folder install and build:

    Terminal window
    cd Source
    yarn install
    yarn build

    This produces Source/dist/ (including manifest.json).

  2. Open chrome://extensions, enable Developer mode, choose Load unpacked, and select the Source/dist folder. Lens appears as Cratis Lens.

  3. Navigate to your running Arc app and open the Lens popup once so it detects the app. The Commands, Queries, and Query Diagnostics tabs become available.

For an active edit loop, run yarn dev to rebuild on change, and reload the extension from chrome://extensions after each rebuild.

To populate the roster, follow Provide tenants and users (C#) or Provide tenants and users (Kotlin/Java). Then use Tenancy in Arc to connect the selected tenant to your backend’s resolution and isolation rules.

For the operations Lens discovers, read Queries in Arc. If you need to inspect the events recorded in Cratis Chronicle instead, use the Narrator VS Code extension.