Telescope (Node)
Telescope (Node) in the JavaScript SDK.
import { NexusTelescope } from '@inverge/nexus/telescope'| Symbol | Kind | Summary |
|---|---|---|
EntryType | type | The entry vocabulary — identical across every Nexus SDK. |
TelescopeOptions | interface | |
InitOptions | interface | |
NexusTelescope | class |
EntryType
type @inverge/nexus/telescopeexport type EntryType = | 'request' | 'command' | 'job' | 'schedule' | 'query' | 'model' | 'event' | 'middleware' | 'exception' | 'log' | 'http' | 'cache' | 'redis' | 'mail' | 'notification' | 'gate' | 'view' | 'dump' | 'batch' | 'span';The entry vocabulary — identical across every Nexus SDK.
TelescopeOptions
interface @inverge/nexus/telescopeapiKey
propertyapiKey: stringbaseUrl
propertybaseUrl?: stringservice
propertyservice?: stringService name shown in traces. Default: NEXUS_SERVICE_NAME, else the package name.
release
propertyrelease?: stringsampleRate
propertysampleRate?: number | nullnull = the console's sample rate. Failed/slow/monitored work is always kept.
ignorePaths
propertyignorePaths?: string[]ignoreTypes
propertyignoreTypes?: EntryType[]redactKeys
propertyredactKeys?: string[]captureBodies
propertycaptureBodies?: booleanRecord response bodies (JSON is parsed). Default true.
bodySizeLimit
propertybodySizeLimit?: numberKB. Default 64.
maxEntries
propertymaxEntries?: numberflushIntervalMs
propertyflushIntervalMs?: numberHow often buffered journeys are shipped. Default 2000 ms.
timeoutMs
propertytimeoutMs?: numberDelivery timeout. Default 3000 ms.
enabled
propertyenabled?: booleanMaster switch (also NEXUS_TELESCOPE_ENABLED=false).
fetch
propertyfetch?: typeof globalThis.fetchonError
propertyonError?: (e: unknown) => voidCalled on delivery failures (default: silent).
InitOptions
interface @inverge/nexus/telescopeinstrument
propertyinstrument?: { server?: boolean; client?: boolean; console?: boolean; pg?: boolean | unknown; mysql2?: boolean | unknown; ioredis?: boolean | unknown; }Auto-instrumentation; everything defaults to on.
NexusTelescope
class @inverge/nexus/telescopeinit()
static methodstatic init(opts: InitOptions): NexusTelescopeCreate (once) and return the process-wide recorder. Call before your app creates its server.
Parameters
Prop
Type
Returns NexusTelescope
get()
static methodstatic get(): NexusTelescope | nullReturns NexusTelescope | null
recorder
propertyreadonly recorder: Recorderexpress()
methodexpress(): (req: AnyReq, res: { once: (e: string, f: () => void) => void; }, next: () => void) => voidExpress / Connect middleware: names the route and keeps the parsed body. Mount it first.
Returns (req: AnyReq, res: { once: (e: string, f: () => void) => void; }, next: () => void) => void
expressErrors()
methodexpressErrors(): (err: unknown, _req: unknown, _res: unknown, next: (e: unknown) => void) => voidExpress error middleware — records the exception, then passes it on. Mount it last.
Returns (err: unknown, _req: unknown, _res: unknown, next: (e: unknown) => void) => void
fastify()
methodfastify(): (app: { addHook: (name: string, fn: (...a: never[]) => unknown) => void; }) => Promise<void>Fastify plugin: await app.register(telescope.fastify()).
Returns (app: { addHook: (name: string, fn: (...a: never[]) => unknown) => void; }) => Promise<void>
koa()
methodkoa(): (ctx: { req: AnyReq; _matchedRoute?: string | undefined; request?: { body?: unknown; } | undefined; }, next: () => Promise<unknown>) => Promise<void>Koa middleware: app.use(telescope.koa()) (before the router).
Returns (ctx: { req: AnyReq; _matchedRoute?: string | undefined; request?: { body?: unknown; } | undefined; }, next: () => Promise<unknown>) => Promise<void>
prisma()
methodprisma(): { name: string; query: { $allOperations({ model, operation, args, query }: { model?: string | undefined; operation: string; args: unknown; query: (a: unknown) => Promise<unknown>; }): Promise<unknown>; }; }Prisma: const db = new PrismaClient().$extends(telescope.prisma()).
Returns { name: string; query: { $allOperations({ model, operation, args, query }: { model?: string | undefined; operation: string; args: unknown; query: (a: unknown) => Promise<unknown>; }): Promise<unknown>; }; }
job()
methodjob<T>(name: string, fn: () => Promise<T> | T, opts: { carrier?: Record<string, unknown>; queue?: string; attempts?: number; data?: unknown } = {}): Promise<T>Run a queued job as its own journey. Pass the job's data as carrier so
it joins the trace of the request that queued it (see {@link inject}).
new Worker('emails', (job) => telescope.job(job.name, () => send(job.data), { carrier: job.data, queue: 'emails' }));Parameters
Prop
Type
Returns Promise<T>
command()
methodcommand<T>(name: string, fn: () => Promise<T> | T, args?: Record<string, unknown>): Promise<T>A CLI command / script as a journey.
Parameters
Prop
Type
Returns Promise<T>
schedule()
methodschedule<T>(name: string, fn: () => Promise<T> | T, expression?: string): Promise<T>A scheduled task (node-cron, agenda, …) as a journey.
Parameters
Prop
Type
Returns Promise<T>
inject()
methodinject(jobName?: string, queue?: string): Record<string, string>Fields to merge into a job payload so its execution joins this trace, and
records the dispatch in the current journey:
queue.add('send', { ...data, ...telescope.inject('SendInvoice', 'emails') }).
Parameters
Prop
Type
Returns Record<string, string>
span()
methodspan<T>(name: string, fn: () => T, content: Record<string, unknown> = {}): TParameters
Prop
Type
Returns T
record()
methodrecord(type: EntryType, content: Record<string, unknown>, opts?: { durationMs?: number; status?: string; name?: string; tags?: string[] }): voidParameters
Prop
Type
query()
methodquery(sql: string, bindings: unknown[] = [], durationMs?: number, connection?: string): voidParameters
Prop
Type
event()
methodevent(name: string, payload?: unknown, listeners?: string[]): voidParameters
Prop
Type
cache()
methodcache(action: 'hit' | 'missed' | 'set' | 'forget', key: string, value?: unknown): voidParameters
Prop
Type
log()
methodlog(level: string, message: string, context?: Record<string, unknown>): voidParameters
Prop
Type
exception()
methodexception(error: unknown, handled: boolean = true, context?: Record<string, unknown>): voidParameters
Prop
Type
user()
methoduser(user: { id: string | number; email?: string; name?: string } & Record<string, unknown>): voidThe signed-in user of the current request: tags it Auth:<id>, links it to Nexus Sessions.
Parameters
Prop
Type
tag()
methodtag(tags: string[]): voidParameters
Prop
Type
traceparent()
methodtraceparent(): string | nullReturns string | null
flush()
methodflush(): Promise<void>