Aviary
Dashboard

Organizations

Show each console viewer only the data of the organizations they may see, when your app uses @dudousxd/nestjs-context tenancy.

When your app makes the request's organization its tenant with @dudousxd/nestjs-context tenancy, Telescope tags what each organization's requests record and shows each console viewer only the organizations they may see. Without tenancy, nothing on this page applies and the console shows everything.

Turn it on

Turn tenancy on in the context and set the tenant of each request (see Tenancy). Telescope follows it:

ContextModule.forRoot({ tenancy: { enabled: true, kinds: ['organization'] } }),
TelescopeModule.forRoot({
  authorize: (ctx) => ctx.switchToHttp().getRequest().user?.isStaff === true,
}),
tenancy optionDefaultWhat it does
'inherit'yesFollows ContextModule's tenancy.enabled.
falseKeeps Telescope out of tenancy: entries keep the plain tenant:<tenantId> tag and the console shows everything.
{ enabled, kinds, family, required, nullRows, tag }enabled ('inherit' or a boolean), kinds (the tenant kinds Telescope honours: with nested tenants, the most specific level of the chain whose kind is listed), family (scope by a secondary tenant family instead of the primary tenant), required (overrides ContextModule's tenancy.required for the console), nullRows: 'shared' (organizations also see entries recorded with no organization), tag (the tag prefix, default 'tenant').

What gets recorded

Every entry recorded for a request with a tenant is tagged tenant:<id>. With nested tenants (@dudousxd/nestjs-context 2.1 and later), it gets one tag per level of the chain: an entry recorded in unit U of clinic C is tagged tenant:C and tenant:U. A viewer of the clinic then sees its units' entries too, and a viewer of the unit sees only the unit's. Work run inside Context.allTenants() is tagged tenant:*. A request with no tenant records untagged entries.

Recording never fails for a missing tenant, even when the tenancy is required.

Exception families stay global: the same error in two organizations is one family, and each organization sees only its own occurrences.

AI diagnoses are kept per organization: a viewer of one organization gets a diagnosis built only from that organization's occurrences, never another organization's. A viewer with tenants: '*' and All organizations selected gets the family's latest diagnosis from any organization.

The dashboard's live updates follow the same rule: a viewer of one organization is only told about that organization's new entries.

Who sees what

authorize decides which organizations a viewer sees, by what it returns:

TelescopeModule.forRoot({
  authorize: (ctx) => {
    const user = ctx.switchToHttp().getRequest().user;
    if (user?.isSupport) return { allowed: true, tenants: '*' };          // every organization
    if (user?.isPartner) return { allowed: true, tenants: user.orgIds }; // these organizations
    return user?.isOrgAdmin === true;                                     // their own organization
  },
}),
authorize returnsThe viewer sees
true or { allowed: true }Their own organization: the tenant of their request (the level kinds picks, with nested tenants). With none, an empty console that says "Choose an organization to see its data", or a 403 (E_TENANT_REQUIRED) when the tenancy is required.
{ allowed: true, tenants: ['org_1', 'org_2'] }Those organizations.
{ allowed: true, tenants: '*' }Every organization, plus entries recorded with no organization. A list containing '*' means the same.

The same rule applies to the API and Telescope's tools on the Aviary dev MCP endpoint.

A caller signed in with authorizeByToken has no organization of its own, so it sees an empty console. Grant it organizations explicitly:

const byToken = authorizeByToken({ token: process.env.TELESCOPE_TOKEN });

TelescopeModule.forRoot({
  authorize: (ctx) => (byToken(ctx) === true ? { allowed: true, tenants: '*' } : byToken(ctx)),
}),

The Organization control

With tenancy on, the dashboard header shows an Organization control: a fixed chip when the viewer sees one organization, a searchable picker when they see several or all of them (All organizations first). The choice lives in the page URL as ?tenant=<id>, so it survives a reload and can be shared.

Organizations are labelled by ContextModule's tenancy.label(tenant) (for example the organization's name), else the tenant's slug, else its id. The picker searches the labels of the granted organizations too.

ContextModule.forRoot({
  tenancy: {
    enabled: true,
    label: async (tenant) => (await orgs.findById(tenant.id))?.name ?? tenant.id,
  },
}),

Every API call carries ?tenant=<id>, and the server keeps it within what authorize granted. A tenant outside the viewer's organizations answers with no data and logs a warning. ?tenant=* means All organizations.

Clearing entries, Prune now, live queues and schedules, and extension panels span every organization. A viewer limited to some organizations does not get them; a viewer with tenants: '*' and All organizations selected does.

Your own client

createTelescopeClient sends the page's ?tenant= on every call. Pass tenant to choose it yourself, and read the viewer's organizations with client.tenancy():

const client = createTelescopeClient({ tenant: () => currentOrgId });
const scope = await client.tenancy(); // { enabled: true, tenants, selected, options }

On this page