Aviary
Concepts

Deployment topologies

Run one Telescope for many apps. Tenant apps send their entries to a central control plane, whose console shows each viewer the apps they may see.

By default every app runs its own Telescope: it records, stores and shows its own entries. With topology you can instead run one Telescope for several apps: each app (a tenant) sends its entries to a central app (the control plane), and the control plane's console shows them all, with an App picker.

topologyWhat the app does
'standalone' (default)Stores and shows its own entries, exactly as without this option.
'control-plane'Stores its own entries and the ones tenant apps send it. Its console gets the App picker. Needs verifyTenant.
'tenant'Sends its entries to a control plane. Keeps a local copy only with tenant.local.

Apps that keep their own store

To get one console without moving any entry, let each app keep its standalone Telescope and have a central app read their stores in place with federation. It composes with a control plane: some apps ship, some are read in place. See Federated console.

The control plane

import { TelescopeModule, hmacTenantVerifier } from '@dudousxd/nestjs-telescope';

TelescopeModule.forRoot({
  topology: 'control-plane',
  verifyTenant: hmacTenantVerifier(process.env.TELESCOPE_TENANT_SECRET!),
  authorize: (ctx) => ctx.switchToHttp().getRequest().user?.isStaff === true,
  apps: { labels: { shop: 'Shop', billing: 'Billing' } },
});

Tenant apps send to POST <path>/api/ingest (/telescope/api/ingest by default). That route is not behind authorize or decorators: the tenant's token is its credential, checked by verifyTenant. On any other topology the route answers 404.

Each entry the control plane receives is tagged app:<partition>, where the partition comes from the verified token, never from the request. A tenant cannot write as another app: an app: tag it sets itself is dropped.

The control plane keeps each entry's own id and time (a time more than 5 minutes in the future becomes the arrival time). A redelivered batch, or an entry id the store already holds, stores nothing new, and an existing entry is never overwritten.

A tenant app

import { TelescopeModule } from '@dudousxd/nestjs-telescope';

TelescopeModule.forRoot({
  topology: 'tenant',
  tenant: {
    url: process.env.TELESCOPE_URL!, // the control plane's console URL, e.g. https://ops.example.com/telescope
    partition: 'shop',
    token: process.env.TELESCOPE_TENANT_TOKEN!, // signTenantToken('shop', secret), minted once
  },
});

Watchers, redaction, sampling, filters and tags run in the tenant as usual, so the control plane only receives what the tenant would have stored. Entries are buffered and sent in batches every second (every 5 seconds with transports.redis), and a full batch goes at once:

tenant optionDefaultWhat it does
urlThe control plane's console URL, or a function returning it (see Finding the control plane lazily). Shorthand for transport: transports.http({ url }).
transportHTTP to urlHow batches reach the control plane. See Transports.
partitionThe app this tenant is. The token must be minted for it.
tokenA string, or a function called before each send (to re-mint a short-lived token).
localnoneAlso keep entries in this store, for the app's own console. Without it, the tenant's console is empty.
bufferSize10000Entries waiting to be sent. Beyond it the oldest is dropped.
batchSize200Entries per batch.
maxBatchBytes64000A larger batch is split; a single larger entry is dropped.
intervalMs1000 (5000 with transports.redis)How often waiting entries are sent. Overrides the transport's default.
relayfalseThis app sends entries for other apps. See Relaying for other apps.

A failed send is retried with the same batch (backoff up to 30 s), so a control plane that was down receives everything once it is back, up to bufferSize. On shutdown the tenant keeps sending for up to 5 seconds.

Express parses JSON bodies up to 100 KB by default, which is why maxBatchBytes defaults to 64 000. If you raise maxBatchBytes, raise the control plane's body limit too.

Finding the control plane lazily

url can be a function, for a control plane found through a discovery source rather than set in the environment. It is called on the first send, not at boot, and the result is cached:

const lookup = Object.assign(async () => (await registry.find('telescope')).url, {
  // Optional: called instead when the URL stops answering.
  refresh: async () => (await registry.find('telescope', { fresh: true })).url,
});

TelescopeModule.forRoot({
  topology: 'tenant',
  tenant: { url: lookup, partition: 'shop', token: process.env.TELESCOPE_TENANT_TOKEN! },
});
  • A lookup that throws, or returns something other than an absolute http(s) URL, fails that send: the entries stay buffered and the next send looks it up again.
  • A send that cannot connect, or gets a 404, looks the URL up again (refresh(), else the function). When it moved, the batch is sent once more to the new URL right away.
  • Service discovery (/api/discovery) shares the same lookup.

Relaying for other apps

Some apps record events about other apps: a workflow server running jobs for shop and billing, a gateway. With relay: true on that tenant, and a token allowed to relay, the control plane stores each such entry as the app it is about:

TelescopeModule.forRoot({
  topology: 'tenant',
  tenant: { url, partition: 'durable', token: process.env.TELESCOPE_TENANT_TOKEN!, relay: true },
});
  • An entry tagged app:<name> (for instance by a watcher reading the app of a diagnostics event) is stored as <name>'s and tagged via:durable. The relayer's own entries are tagged app:durable, both on the wire and in local, so its own console's App picker lists itself and the apps it relays for.
  • The token decides. Only a token whose capabilities include telescope:ingest:relay (every app), telescope:ingest:relay:<app> (that app, repeatable) or telescope:* may relay; each implies telescope:ingest. A token without capabilities never relays. Without the capability, every entry stays the sender's app, as before: an app: tag never lets a sender write as another app.
  • An entry a relayer may not relay (an app outside its scope, an invalid name, several app: tags) is refused on its own and counted; the rest of the batch is stored. The ingest answer then carries relayed and rejected counts, and the control plane logs the refusal.
  • A relayed entry is deduped under its relayer and app, so a relay's retry is stored once, and an id the store already holds (the app's own, or another relay's) is never overwritten. via: is reserved: a sender's own via: tags are dropped.

Tokens

hmacTenantVerifier(secret) checks tokens made by signTenantToken(partition, secret), a shared secret with no identity provider. Mint one token per app and give each app only its own:

import { signTenantToken } from '@dudousxd/nestjs-telescope';

signTenantToken('shop', secret); // never expires
signTenantToken('shop', secret, { ttlMs: 24 * 3600_000 }); // expires in a day

Pass a list (hmacTenantVerifier([next, current])) to rotate the secret without downtime. The format is the same as @dudousxd/nestjs-durable's tenant tokens.

With an identity provider, write your own verifyTenant: it gets { token } and returns { tenant: '<partition>' }, or null to refuse. If it returns capabilities, they must include telescope:ingest (or a relay capability, see Relaying for other apps). A verifier that throws (the provider is down) makes the tenant retry.

verifyTenant: async ({ token }) => {
  const claims = await verifyJwt(token); // your IdP
  return claims ? { tenant: claims.client_id, capabilities: claims.scope.split(' ') } : null;
},

Transports

HTTP is the default. A fleet that already runs Redis can send batches through a broker instead. Set the same driver on the tenant (tenant.transport) and on the control plane (transport):

import { TelescopeModule, transports } from '@dudousxd/nestjs-telescope';

const broker = transports.bullmq({ connection: { host: 'redis', port: 6379, maxRetriesPerRequest: null } });

// control plane
TelescopeModule.forRoot({ topology: 'control-plane', verifyTenant, transport: broker });

// a tenant
TelescopeModule.forRoot({
  topology: 'tenant',
  tenant: { partition: 'shop', token: process.env.TELESCOPE_TENANT_TOKEN!, transport: broker },
});
DriverTenant sendsControl plane readsDead lettersPeer (loaded only when used)
transports.http({ url, fetch?, timeoutMs? }) (default)POST <url>/api/ingestthe ingest routenone: the tenant drops a batch answered 400/413none
transports.bullmq({ connection, queue?, prefix?, attempts?, concurrency? })one job per batch on telescope-ingesta BullMQ workerBullMQ's failed set (last keepFailed, 10 000)bullmq
transports.redis({ connection | client, prefix?, group?, maxAttempts?, minIdleMs?, blockMs?, reclaimIntervalMs?, trimIntervalMs?, sendIntervalMs? })XADD <prefix>:ingest (capped with MAXLEN ~ maxLen)a consumer group, blocking reads on a connection of its own<prefix>:ingest:deadioredis (unless you pass client)

Redis streams and command cost

Managed Redis is often billed per command, so transports.redis keeps the count low:

OptionDefaultWhat it does
blockMs10000Control plane: one read waits this long on the server (XREADGROUP ... BLOCK). A message is read as soon as it lands; an idle control plane sends about one read per blockMs. 0 polls every pollMs instead.
pollMs500Control plane: the read interval when the read cannot block, and the pause after a failed read.
reclaimIntervalMs30000Control plane: how often unacknowledged messages are looked at for a take-over (also on start and after a failed read).
trimIntervalMs30000Control plane: how often messages every consumer group acknowledged are removed (XTRIM MINID ~), when there were any. Pending and unread messages are never removed. 0: only maxLen caps the stream.
sendIntervalMs5000Tenant: how often the buffer is sent when tenant.intervalMs is not set.

The blocking read runs on client.duplicate() (or a second connection built from connection), closed when the control plane stops; your client is never blocked. A client without duplicate() is polled every pollMs. Keep any ioredis commandTimeout above blockMs. The messages of one read are acknowledged with a single XACK.

The same rules hold whatever the transport:

  • Every message is verified. A broker message carries the batch and the tenant's token. The control plane runs verifyTenant on each one, takes the app from the token, and dedupes by <app>:<id>. One handler serves the HTTP route and the broker, so a batch that arrives both ways is stored once.
  • Refused messages are dead-lettered, not retried. That covers a bad or expired token, a malformed batch, and a message larger than maxMessageBytes (1 MiB).
  • Transient failures are retried. When the store or the verifier is down, BullMQ retries up to attempts (default 5) with exponential backoff. A Redis stream message stays pending and is taken over after minIdleMs (30 s), up to maxAttempts (5).
  • The tenant behaves the same. A broker that is down keeps entries in the tenant's buffer and retries them; shutdown flushes to the broker.
  • Browsers always stay on HTTP. That covers the console, the live tail and the client-error beacon. A control plane on a broker keeps its /api/ingest route, so a fleet can mix HTTP and broker tenants.

A broker message keeps the token it was sent with. If a message waits longer than the token's lifetime (a control plane down for a day, with tokens minted with ttlMs), it is refused and dead-lettered. Give tokens a lifetime longer than the outages you want to survive.

Who sees which app

On the control plane, the console's authorize can grant apps next to organizations:

authorize: (ctx) => {
  const user = ctx.switchToHttp().getRequest().user;
  if (user?.isStaff) return true; // every app
  if (user?.team === 'payments') return { allowed: true, apps: ['billing'] };
  return false;
},
appsThe viewer sees
omitted or '*'Every app. All apps in the picker, or one picked app (?app=).
['billing', ...]Only these apps.

authorizeByToken({ token, apps }) takes the same option. With organizations on as well, an entry is visible only when both its organization and its app are granted.

The limit applies to every read: entries, traces, metrics, Pulse, exceptions, the live tail, the ⌘K search and the MCP tools. An ?app= outside the viewer's apps answers empty (and is logged), never with another app's data. Global actions (clearing entries, pruning, queue and schedule controls, Prometheus metrics) are refused to a viewer limited to some apps, as they are to a viewer limited to some organizations.

The App picker is hidden while no entry carries an app, so a standalone app's console looks as before. It lists the apps the control plane has stored entries of, kept in memory as batches arrive and reconciled with the store every five minutes, so opening the console never counts the tags of the whole table. The entries table shows an App column when entries of several apps are in view.

On this page