@dudousxd/nestjs-telescope-official
NestJS's first-party packages in Telescope — the resilience, workflows, authentication, authorization and mail diagnostics channels as entries, @nestjs/ai usage on the AI screen, and @nestjs/observe trace ids.
pnpm add @dudousxd/nestjs-telescope-officialNestJS's first-party packages already publish what they do: each one emits its events on
node:diagnostics_channel channels named nestjs:<package>:<event>, and @nestjs/ai hands every
model call to an onUsage listener. This package records those as Telescope entries. It builds
nothing those packages already do. It never imports them at runtime, and it reads every payload
structurally, so a 0.x shape change shows up as fewer fields, never a crash. All the official
packages are optional peers.
| Package | Docs | What Telescope records |
|---|---|---|
@nestjs/resilience ≥ 0.0.3 | docs.nestjs.com | resilience entries from the 9 nestjs:resilience:* channels |
@nestjs/workflows ≥ 0.0.5 | Workflows | workflow entries from the 19 nestjs:workflows:* channels |
@nestjs/authentication ≥ 0.1.5 | docs.nestjs.com | auth entries from the 13 nestjs:authentication:* channels, redacted |
@nestjs/authorization ≥ 0.1.3 | docs.nestjs.com | auth entries from nestjs:authorization:denied |
@nestjs/mail ≥ 0.0.2 | docs.nestjs.com | built-in mail entries from nestjs:mail:sent / nestjs:mail:failed |
@nestjs/ai ≥ 0.0.2 | AI overview | usage.recorded rows on the AI screen and the AI metrics |
@nestjs/observe ≥ 0.3.20 | docs.nestjs.com | the trace id only, as Telescope's traceContext |
Channel watchers
import { TelescopeModule } from '@dudousxd/nestjs-telescope';
import { officialWatchers } from '@dudousxd/nestjs-telescope-official';
TelescopeModule.forRoot({
storage,
watchers: [...officialWatchers()],
});officialWatchers() returns one watcher per package. An uninstalled package publishes nothing,
so its watcher records nothing and costs nothing. You can turn each one off, or use the classes
directly:
officialWatchers({ mail: false, auth: { authorization: false } });
// or: new NestResilienceWatcher(), new NestWorkflowsWatcher(), new NestAuthWatcher(), new NestMailWatcher()Correlation. The payloads carry no trace id, and they don't need one. A channel calls its
subscribers synchronously, in the publisher's async context. So each entry joins the request or
job batch that emitted it, and carries the current trace from your traceContext
(OpenTelemetry, ObserveTraceContextProvider below, or @dudousxd/nestjs-context).
@nestjs/workflows runs instances on its worker loop, so workflow entries correlate to whatever
batch is active there, usually none.
Refusals and failures are tagged failed: timeouts, open or refusing breakers, bulkhead and
rate-limit refusals, failed workflows and steps, timed-out signals, failed second factors, reused
refresh tokens, refused magic links, failed session touches, denials and failed sends. Entries are
grouped (familyHash) by event:policy, by workflow name, by auth event (a denial by
Policy.ability), and by mail class.
The app an event is about
When an event names the app it is about (the app of a @dudousxd/nestjs-diagnostics envelope, else an app in its payload, [A-Za-z0-9_.-]{1,64}), its entry is tagged app:<name>, unless the mapper already set an app: tag. The App picker then lists that app, and a relaying tenant gets the entry stored as that app on its control plane. The envelope is read structurally, so no particular diagnostics version is needed.
What each entry holds
resilience:event,policy,source(the entrypoint), and the fields of the type:attemptanddelayMs,timeoutMs, a breaker'sfromandto,retryAfterMs, a bulkhead'sreason,activeandqueued, and theerror(name, message, code).workflow:event, the instanceid,workflow,version,at, and per type:run,wakeAtandwaits,step,attempt,durationMs(also the entry's duration),retryAt, the child, the signal, journal size, the customstatus, theoutput, a retry's or a skipped schedule'sfromandto, and the serializederror(no stack).outputandstatusare your data, so they go through Telescope's redaction and size bounds.auth:source(authenticationorauthorization) andevent, plus the fields below.mail: the same shape as the nodemailer watcher's (mailer: '@nestjs/mail',tofrom the envelope recipients,subject,status), plusmail,transport,messageId,providerMessageId,attempts,permanentanderror. The event carries no sender or body, sofromandpreviewarenull.
Auth entries are redacted
Only known fields are copied, so a field a later version adds isn't recorded until this package
reviews it. Session ids and refresh-token family ids become a short SHA-256 fingerprint
(sessionRef, tokenFamilyRef). That's enough to tell that a sign-in and a sign-out were the same
session, and nothing in it authenticates. Email addresses are masked (j***@example.com). The
session metadata keeps only its key names. A denial keeps the user's id / sub / userId
and the number of policy arguments, never the user object or the records, as
@nestjs/authorization advises.
Don't record the same mailer twice. If a transport is also wrapped by
@dudousxd/nestjs-telescope-mail's MailWatcher, pass officialWatchers({ mail: false }).
Resilience page
resilienceTelescopeExtension() adds a Resilience page (under Libraries in the nav) built
from the resilience entries NestResilienceWatcher records, plus the live state of
@nestjs/resilience's ResilienceService when the app imports ResilienceModule:
import { TelescopeModule } from '@dudousxd/nestjs-telescope';
import {
officialWatchers,
resilienceTelescopeExtension,
} from '@dudousxd/nestjs-telescope-official';
TelescopeModule.forRoot({
storage,
mutations: true, // for the Reset button
watchers: [...officialWatchers()],
extensions: [resilienceTelescopeExtension()],
});The page shows:
- Now: open and half-open circuits, and over the window: calls refused by a breaker (short-circuited), circuits opened, retries, timeouts, bulkhead rejections and outbound rate-limit refusals, each against the window before it.
- Circuits: every circuit breaker, open ones first, with its status, the calls and failures in its sliding window, failure rate and threshold, how often it opened and refused calls in the window, its last change, and when an open breaker lets probe calls through.
- Events over the window, stacked by type, and the noisiest policies (retries, timeouts, refusals and fallbacks). Click a policy to filter the whole page by it.
- Bulkheads (running, queued, limits, rejections) and outbound rate limits (refusals and
the last
retryAfterMs). - Recent transitions: each breaker that opened, went half-open, closed or was reset, linked to its entry, with who reset it.
Live versus history
Breakers live in each process. A circuit's status, window counts and bulkhead load come from the
process serving the console (Source: live). Counts, charts and transitions come from the
recorded entries, so they cover every instance writing to the same Telescope storage. A circuit
only another instance holds shows its last recorded transition (Source: history).
@nestjs/resilience doesn't list its outbound rate limits, so that table is built from their
refusals only.
Reset a circuit
Open and half-open live circuits get a Reset button. After you confirm, the breaker closes with an empty window, so calls reach the dependency again. The reset:
- needs
mutations: trueand passes the console'sauthorize, like every console mutation; - writes an audit line (
extension action resilience.reset-circuit ok by user:42 via console …) through theTelescopeAuditlogger; - records a
resilienceentry (event: 'circuit-reset', withby) that shows under Recent transitions.
Options:
resilienceTelescopeExtension({
window: '6h', // what the counts, charts and transitions cover (default '1h')
reset: false, // no Reset button and no telescope_resilience_reset_circuit tool (default true)
});Dev tools
With the agent's dev MCP endpoint, the extension adds two tools next to Telescope's, behind the
console's authorize:
| Tool | Kind | What it does |
|---|---|---|
telescope_resilience_circuits | read | The circuits (live state merged with recorded transitions), open ones first, and the bulkheads' load. Filters: status, limit (default 20, max 100). |
telescope_resilience_reset_circuit | action | Resets the circuit name of this process. Served only with mutations: true. Writes the same audit line and entry as the page, with the MCP caller. |
@nestjs/ai usage
import { AiModule } from '@nestjs/ai';
import { telescopeAiUsage } from '@dudousxd/nestjs-telescope-official';
AiModule.forRoot({
models: { default: { model: anthropic('claude-sonnet-5-5'), pricing: { input: 3, output: 15 } } },
onUsage: telescopeAiUsage(),
});Each model call that answered becomes a usage.recorded row in the shape the
AI screen already reads: the feature is the call's label, cached input
counts as cacheReadTokens, and the cost is costSource: 'estimate', because @nestjs/ai prices
calls from the pricing you configured, not from the provider's bill. The same call is counted in
the AI metrics (aiMetrics.prometheus, and the otel AI exporter). The entry joins the request that
made the call.
| Option | Default | |
|---|---|---|
feature(event) | event.label ?? 'default' | The AI screen's feature. |
actor(event) | '@platform' | Who pays: shown on the "by actor" breakdown, never a metric label. |
toUsd(cost, event) | the cost as given | cost is in your pricing unit; convert it here, or return undefined for unpriced. |
record | true | Record the agent entry. |
metrics | true | Count it in the AI metrics. |
Keep an existing onUsage by calling both:
const toTelescope = telescopeAiUsage();
AiModule.forRoot({
models,
onUsage: (event) => {
toTelescope(event);
return myOnUsage(event);
},
});Attach it in one place. @nestjs/ai calls the module's onUsage and then the call's own, so
putting it on both counts every call twice. A call-level onUsage: telescopeAiUsage({ feature: () => 'triage' })
is for a call the module-level listener doesn't already cover.
@nestjs/observe trace ids
import { TracerService } from '@nestjs/observe';
import { ObserveTraceContextProvider } from '@dudousxd/nestjs-telescope-official';
TelescopeModule.forRootAsync({
inject: [TracerService],
useFactory: (tracer: TracerService) => ({
storage,
traceContext: new ObserveTraceContextProvider(tracer),
}),
});Every entry carries the trace id NestJS Observe gives the request, so you can look one request up
in both tools. Observe writes ids as UUIDs. The provider drops the dashes and gets the 32 hex
digits of the W3C trace id (4bf92f35-77b3-… becomes 4bf92f3577b3…). A free-form x-request-id
that Observe keeps as the trace name is hashed into 32 hex digits, so the request's entries still
share one trace. Observe exposes no span id, so the span id is a stable synthetic one derived from
the trace id. The provider never throws: with no trace in flight it returns null.
Trace id only, never Observe's telemetry
@nestjs/observe after 0.3.20 is under the NestJS Observe Agent License. Its telemetry may go
only to observe.nestjs.com, and the software may not be used to build a backend that receives
that telemetry or substitutes for the Service. So Telescope never ingests Observe's spans,
metrics, errors or logs; this provider calls TracerService.currentTraceId() and nothing else.
The license states that passing trace context is allowed: "Passing trace context, such as
traceparent or x-request-id headers, between Your applications and the services they call does
not violate (a) or (b)." currentTraceId() is documented for exactly this kind of use (logs,
outgoing headers). The former @dudousxd/nestjs-telescope-observe exporter, which pushed
Telescope entries into Observe over its private ingest wire, is deprecated: to report into
NestJS Observe, use @nestjs/observe itself.
Channel lists
The channel names live in this package (OFFICIAL_CHANNEL_NAMES, RESILIENCE_EVENT_TYPES,
WORKFLOW_EVENT_TYPES, AUTHENTICATION_EVENT_TYPES). They were checked against the published
tarballs of the versions in the table above, and they can come from @dudousxd/nestjs-diagnostics
once that package publishes the same constants.
@dudousxd/nestjs-telescope-otel
OpenTelemetry for Telescope — your app's spans in the trace waterfall, entries stamped with the active trace, metrics and spans out through your OpenTelemetry SDK.
@dudousxd/nestjs-telescope-ai
AI-powered exception diagnosis — turn a captured exception into a markdown triage report (probable cause, where to look, suggested fix, confidence) using the Vercel AI SDK with any provider.