API Reference

Complete API reference for @igniter-js/telemetry — IgniterTelemetry, IgniterTelemetryEvents, IgniterTelemetrySession, all transport adapters, types, and error codes.

API Reference

Complete reference for all public APIs in @igniter-js/telemetry. Every method and type is verified against the implementation in packages/telemetry/src/.


IgniterTelemetry (Builder)

Import: import { IgniterTelemetry } from "@igniter-js/telemetry"

Alias for IgniterTelemetryBuilder. Creates and configures telemetry instances.

Static Methods

MethodReturnsDescription
IgniterTelemetry.create()IgniterTelemetryBuilderCreate a new builder instance

Builder Methods

All builder methods are immutable — each returns a new builder instance.

MethodSignatureDescription
.withService(name)(service: string) => BuilderSet service name (default: "igniter-app")
.withEnvironment(env)(environment: string) => BuilderSet environment (default: "development")
.withVersion(v)(version: string) => BuilderSet service version
.addActor(key, opts?)(key: string, opts?: ActorOptions) => BuilderRegister actor type
.addScope(key, opts?)(key: string, opts?: ScopeOptions) => BuilderRegister scope type
.addEvents(desc, opts?)(desc: EventsDescriptor, opts?: ValidationOptions) => BuilderRegister typed events
.addTransport(adapter)(adapter: TransportAdapter) => BuilderAdd transport adapter
.withSampling(policy)(policy: SamplingPolicy) => BuilderConfigure sampling
.withRedaction(policy)(policy: RedactionPolicy) => BuilderConfigure redaction
.withValidation(opts)(opts: ValidationOptions) => BuilderSet global validation options
.withLogger(logger)(logger: IgniterLogger) => BuilderSet internal logger
.build()IgniterTelemetryManagerCreate runtime manager
.buildConfig()IgniterTelemetryConfigBuild config only

ActorOptions

interface IgniterTelemetryActorOptions {
  description?: string;
  required?: boolean;
}

ScopeOptions

interface IgniterTelemetryScopeOptions {
  description?: string;
  required?: boolean;
}

ValidationOptions

interface IgniterTelemetryEventsValidationOptions {
  mode?: "development" | "always" | "none";
  strict?: boolean;
}

IgniterTelemetryManager (Runtime)

Returned by .build(). The runtime instance for emitting events.

Properties

PropertyTypeDescription
servicestringService name
environmentstringEnvironment name
versionstring | undefinedService version

Methods

MethodSignatureDescription
.emit(name, input?)(name: string, input?: EmitInput) => voidEmit an event
.session()() => IgniterTelemetrySessionCreate a new session
.flush()() => Promise<void>Flush all transport buffers
.shutdown()() => Promise<void>Graceful shutdown

EmitInput

interface IgniterTelemetryEmitInput {
  level?: "debug" | "info" | "warn" | "error" | "fatal";
  time?: string;
  sessionId?: string;
  actor?: { type: string; id?: string; tags?: Record<string, unknown> };
  scope?: { type: string; id: string; tags?: Record<string, unknown> };
  attributes?: Record<string, unknown>;
  error?: {
    name: string;
    message: string;
    code?: string;
    stack?: string;
  };
  source?: {
    causer?: string;
    file?: string;
    line?: number;
  };
}

IgniterTelemetrySession

Created via telemetry.session(). Provides context binding and scoped execution.

Methods

MethodSignatureDescription
.actor(type, id?, tags?)(type: string, id?: string, tags?: Tags) => thisSet actor
.scope(type, id, tags?)(type: string, id: string, tags?: Tags) => thisSet scope
.attributes(attrs)(attrs: Record<string, unknown>) => thisMerge attributes
.id(sessionId)(sessionId: string) => thisSet custom session ID
.emit(name, input?)(name: string, input?: EmitInput) => voidEmit with session context
.run(fn)(fn: () => Promise<T> | T) => Promise<T>Scoped execution
.end()() => Promise<void>End session
.getState()() => SessionStateGet session state copy

Static Methods

MethodReturnsDescription
IgniterTelemetrySession.getActive()SessionState | undefinedGet active session from AsyncLocalStorage

IgniterTelemetryEvents

Import: import { IgniterTelemetryEvents } from "@igniter-js/telemetry"

Creates typed event registries with Zod schema validation.

Methods

MethodSignatureDescription
.namespace(name)(name: string) => EventRegistryBuilderStart a namespace
.event(name, schema)(name: string, schema: Schema) => EventRegistryBuilderAdd flat event
.group(name, builder)(name: string, builder: (g: GroupBuilder) => GroupBuilder) => EventRegistryBuilderAdd nested group
.build()EventsDescriptorBuild the descriptor

EventsDescriptor Helpers

HelperTypeDescription
.get.key(name)(key: string) => stringGet full event key with namespace
.get.schema(name)(key: string) => SchemaGet schema for event
.$Infer.namespacestringNamespace type
.$Infer.eventsEventsMapEvents map type
.$Infer.keysstring unionAll event key types
.$Infer.registryRegistryFull registry type

Transport Adapters

Import: import { ... } from "@igniter-js/telemetry/adapters"

LoggerTransportAdapter

LoggerTransportAdapter.create(options: {
  logger: { info, warn, error, debug };  // Required
  format?: "json" | "pretty";            // Default: "pretty"
  minLevel?: string;                       // Default: "debug"
  includeTimestamp?: boolean;              // Default: true
})

HttpTransportAdapter

HttpTransportAdapter.create(options: {
  url: string;                             // Required
  headers?: Record<string, string>;        // Default: {}
  timeout?: number;                        // Default: 5000
  retries?: number;                        // Default: 0
})

OtlpTransportAdapter

OtltpTransportAdapter.create(options: {
  url: string;                             // Required
  headers?: Record<string, string>;        // Default: {}
})

SentryTransportAdapter

SentryTransportAdapter.create(options: {
  sentry: typeof Sentry;                   // Required
})

SlackTransportAdapter

SlackTransportAdapter.create(options: {
  webhookUrl: string;                      // Required
  minLevel?: string;                       // Default: "warn"
  username?: string;                       // Default: "Igniter Telemetry"
  iconEmoji?: string;                      // Default: ":bar_chart:"
})

DiscordTransportAdapter

DiscordTransportAdapter.create(options: {
  webhookUrl: string;                      // Required
  minLevel?: string;                       // Default: "warn"
  username?: string;                       // Default: "Igniter Telemetry"
  avatarUrl?: string;
})

TelegramTransportAdapter

TelegramTransportAdapter.create(options: {
  botToken: string;                        // Required
  chatId: string;                          // Required
  minLevel?: string;                       // Default: "error"
})

InMemoryTransportAdapter

InMemoryTransportAdapter.create()

// Methods:
.getEvents() => Envelope[]   // Get all captured events
.clear()                      // Clear captured events

MockTelemetryAdapter

MockTelemetryAdapter.create()

// Methods:
.getLastEvent() => Envelope | undefined  // Most recent event
.getEvents() => Envelope[]               // All captured events
.clear()                                  // Clear captured events

StoreStreamTransportAdapter

StoreStreamTransportAdapter.create(options: {
  store: IgniterStore;                     // Required
  stream?: string;                         // Default: "telemetry:events"
  maxLen?: number;                         // Default: 10000
})

Transport Adapter Interface

interface IgniterTelemetryTransportAdapter {
  readonly type: string;
  init?(meta: TransportMeta): Promise<void>;
  handle(envelope: Envelope): Promise<void>;
  flush?(): Promise<void>;
  shutdown?(): Promise<void>;
}

interface IgniterTelemetryTransportMeta {
  service: string;
  environment: string;
  version?: string;
}

Sampling Policy

interface IgniterTelemetrySamplingPolicy {
  debugRate?: number;       // Default: 0.01
  infoRate?: number;        // Default: 0.1
  warnRate?: number;        // Default: 1.0
  errorRate?: number;       // Default: 1.0
  always?: string[];        // Glob patterns always sampled
  never?: string[];         // Glob patterns never sampled
}

Redaction Policy

interface IgniterTelemetryRedactionPolicy {
  denylistKeys?: string[];    // Keys to remove (case-insensitive)
  hashKeys?: string[];        // Keys to SHA-256 hash (case-insensitive)
  maxStringLength?: number;   // Default: 5000
}

Event Envelope

interface IgniterTelemetryEnvelope {
  name: string;
  time: string;
  level: "debug" | "info" | "warn" | "error" | "fatal";
  service: string;
  environment: string;
  version?: string;
  sessionId: string;
  actor?: { type: string; id?: string; tags?: Record<string, unknown> };
  scope?: { type: string; id: string; tags?: Record<string, unknown> };
  attributes?: Record<string, unknown>;
  error?: { name: string; message: string; code?: string; stack?: string };
  source?: { causer?: string; file?: string; line?: number };
}

Error Codes

import { IgniterTelemetryError, IGNITER_TELEMETRY_ERROR_CODES } from "@igniter-js/telemetry";

// Configuration
TELEMETRY_SERVICE_REQUIRED
TELEMETRY_ENVIRONMENT_REQUIRED
TELEMETRY_CONFIGURATION_INVALID

// Transport
TELEMETRY_INVALID_TRANSPORT
TELEMETRY_TRANSPORT_FAILED
TELEMETRY_TRANSPORT_INIT_FAILED

// Events
TELEMETRY_INVALID_EVENT_NAME
TELEMETRY_UNKNOWN_EVENT
TELEMETRY_DUPLICATE_EVENT

// Schema & Validation
TELEMETRY_SCHEMA_VALIDATION_FAILED
TELEMETRY_INVALID_NAMESPACE
TELEMETRY_RESERVED_NAMESPACE
TELEMETRY_DUPLICATE_NAMESPACE

// Sessions
TELEMETRY_SESSION_ENDED
TELEMETRY_SESSION_INVALID

// Scope & Actor
TELEMETRY_DUPLICATE_SCOPE
TELEMETRY_INVALID_SCOPE
TELEMETRY_DUPLICATE_ACTOR
TELEMETRY_INVALID_ACTOR

// Emit & Runtime
TELEMETRY_EMIT_FAILED
TELEMETRY_RUNTIME_NOT_INITIALIZED

Error Class

class IgniterTelemetryError extends IgniterError {
  readonly code: IgniterTelemetryErrorCode;
  static is(error: unknown): error is IgniterTelemetryError;
  hasCode(code: IgniterTelemetryErrorCode): boolean;
}

Event Levels

type IgniterTelemetryLevel = "debug" | "info" | "warn" | "error" | "fatal";

// Level priority values (used internally for minLevel filtering)
IGNITER_TELEMETRY_LEVEL_PRIORITY = { debug: 10, info: 20, warn: 30, error: 40, fatal: 50 }

Utility Types

// Event registry types
type IgniterTelemetryFlattenRegistryKeys<TRegistry>;
type IgniterTelemetryGetEventSchema<TRegistry, TKey>;
type IgniterTelemetryInferEventSchema<TSchema>;

// Session types
type IgniterTelemetrySessionState;
type IIgniterTelemetrySession<TActor, TScope>;

// Manager type
type IIgniterTelemetryManager<TRegistry, TScopes, TActors>;

Next Steps