InvergeDocs
JavaScriptAPI reference

Telescope (Node)

Telescope (Node) in the JavaScript SDK.

import { NexusTelescope } from '@inverge/nexus/telescope'
SymbolKindSummary
EntryTypetypeThe entry vocabulary — identical across every Nexus SDK.
TelescopeOptionsinterface
InitOptionsinterface
NexusTelescopeclass

EntryType

type @inverge/nexus/telescope
export 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/telescope

apiKey

property
apiKey: string

baseUrl

property
baseUrl?: string

service

property
service?: string

Service name shown in traces. Default: NEXUS_SERVICE_NAME, else the package name.

release

property
release?: string

sampleRate

property
sampleRate?: number | null

null = the console's sample rate. Failed/slow/monitored work is always kept.

ignorePaths

property
ignorePaths?: string[]

ignoreTypes

property
ignoreTypes?: EntryType[]

redactKeys

property
redactKeys?: string[]

captureBodies

property
captureBodies?: boolean

Record response bodies (JSON is parsed). Default true.

bodySizeLimit

property
bodySizeLimit?: number

KB. Default 64.

maxEntries

property
maxEntries?: number

flushIntervalMs

property
flushIntervalMs?: number

How often buffered journeys are shipped. Default 2000 ms.

timeoutMs

property
timeoutMs?: number

Delivery timeout. Default 3000 ms.

enabled

property
enabled?: boolean

Master switch (also NEXUS_TELESCOPE_ENABLED=false).

fetch

property
fetch?: typeof globalThis.fetch

onError

property
onError?: (e: unknown) => void

Called on delivery failures (default: silent).

InitOptions

interface @inverge/nexus/telescope

instrument

property
instrument?: { 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/telescope

init()

static method
static init(opts: InitOptions): NexusTelescope

Create (once) and return the process-wide recorder. Call before your app creates its server.

Parameters

Prop

Type

Returns NexusTelescope

View source

get()

static method
static get(): NexusTelescope | null

Returns NexusTelescope | null

View source

recorder

property
readonly recorder: Recorder

express()

method
express(): (req: AnyReq, res: { once: (e: string, f: () => void) => void; }, next: () => void) => void

Express / 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

View source

expressErrors()

method
expressErrors(): (err: unknown, _req: unknown, _res: unknown, next: (e: unknown) => void) => void

Express error middleware — records the exception, then passes it on. Mount it last.

Returns (err: unknown, _req: unknown, _res: unknown, next: (e: unknown) => void) => void

View source

fastify()

method
fastify(): (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>

View source

koa()

method
koa(): (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>

View source

prisma()

method
prisma(): { 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>; }; }

View source

job()

method
job<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>

View source

command()

method
command<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>

View source

schedule()

method
schedule<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>

View source

inject()

method
inject(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>

View source

span()

method
span<T>(name: string, fn: () => T, content: Record<string, unknown> = {}): T

Parameters

Prop

Type

Returns T

View source

record()

method
record(type: EntryType, content: Record<string, unknown>, opts?: { durationMs?: number; status?: string; name?: string; tags?: string[] }): void

Parameters

Prop

Type

View source

query()

method
query(sql: string, bindings: unknown[] = [], durationMs?: number, connection?: string): void

Parameters

Prop

Type

View source

event()

method
event(name: string, payload?: unknown, listeners?: string[]): void

Parameters

Prop

Type

View source

cache()

method
cache(action: 'hit' | 'missed' | 'set' | 'forget', key: string, value?: unknown): void

Parameters

Prop

Type

View source

log()

method
log(level: string, message: string, context?: Record<string, unknown>): void

Parameters

Prop

Type

View source

exception()

method
exception(error: unknown, handled: boolean = true, context?: Record<string, unknown>): void

Parameters

Prop

Type

View source

user()

method
user(user: { id: string | number; email?: string; name?: string } & Record<string, unknown>): void

The signed-in user of the current request: tags it Auth:<id>, links it to Nexus Sessions.

Parameters

Prop

Type

View source

tag()

method
tag(tags: string[]): void

Parameters

Prop

Type

View source

traceparent()

method
traceparent(): string | null

Returns string | null

View source

flush()

method
flush(): Promise<void>
View source

On this page