Builder Configuration

Complete reference for the IgniterTelemetry.create() builder — all methods with parameter tables, return types, and verified code examples.

Builder Configuration

The IgniterTelemetry.create() builder is a fluent, immutable configuration chain. Each method returns a new builder instance — no state is mutated in place. Call .build() to create the runtime manager.


Builder Methods Overview

MethodPurposeRequired
.withService(name)Set service nameRecommended
.withEnvironment(env)Set environmentRecommended
.withVersion(version)Set service versionOptional
.addActor(key, options?)Register actor typeOptional
.addScope(key, options?)Register scope typeOptional
.addEvents(descriptor, options?)Register typed eventsOptional
.addTransport(adapter)Add transport adapterAt least one
.withSampling(policy)Configure samplingOptional
.withRedaction(policy)Configure redactionOptional
.withValidation(options)Global validation optionsOptional
.withLogger(logger)Set internal loggerOptional
.build()Create the managerFinal step
.buildConfig()Build config only (no manager)For inspection

withService(name)

Sets the service name that appears in every envelope.

const telemetry = IgniterTelemetry.create()
  .withService("billing-api")
  .addTransport(loggerAdapter)
  .build();
ParameterTypeDescription
servicestringService identifier (e.g., "my-api", "worker")

Defaults to "igniter-app" if not set. Always set a meaningful service name for production.


withEnvironment(env)

Sets the environment name.

const telemetry = IgniterTelemetry.create()
  .withEnvironment(process.env.NODE_ENV ?? "development")
  .addTransport(loggerAdapter)
  .build();
ParameterTypeDescription
environmentstringEnvironment name ("development", "staging", "production")

Defaults to "development" if not set.


withVersion(version)

Sets the service version. Useful for correlating telemetry with deployments.

const telemetry = IgniterTelemetry.create()
  .withVersion(process.env.APP_VERSION ?? "unknown")
  .addTransport(loggerAdapter)
  .build();
ParameterTypeDescription
versionstringVersion string (e.g., "1.4.2")

addActor(key, options?)

Registers an actor type definition. Actors represent who or what initiated an event.

const telemetry = IgniterTelemetry.create()
  .addActor("user", { description: "Authenticated user" })
  .addActor("system", { description: "Automated system action" })
  .addActor("agent", { description: "AI agent" })
  .addTransport(loggerAdapter)
  .build();
ParameterTypeDescription
keystringActor type identifier (e.g., "user", "system")
options.descriptionstring?Human-readable description
options.requiredboolean?Whether this actor is required for all events

Duplicate actors throw TELEMETRY_DUPLICATE_ACTOR. Each actor key must be unique across the builder.


addScope(key, options?)

Registers a scope type definition. Scopes represent the context or tenant dimension (organization, workspace, project).

const telemetry = IgniterTelemetry.create()
  .addScope("organization", { required: true, description: "Tenant organization" })
  .addScope("workspace", { description: "Team workspace" })
  .addScope("project", { description: "Specific project" })
  .addTransport(loggerAdapter)
  .build();
ParameterTypeDescription
keystringScope type identifier (e.g., "organization")
options.descriptionstring?Human-readable description
options.requiredboolean?Whether this scope is required for all events

Duplicate scopes throw TELEMETRY_DUPLICATE_SCOPE. Each scope key must be unique across the builder.


addEvents(descriptor, options?)

Registers typed event definitions. Accepts the output of IgniterTelemetryEvents.build().

const telemetry = IgniterTelemetry.create()
  .addEvents(BillingEvents)
  .addEvents(AuthEvents, { mode: "always", strict: true })
  .addTransport(loggerAdapter)
  .build();
ParameterTypeDescription
descriptorIgniterTelemetryEventsDescriptorBuilt event registry
options.mode"development" | "always" | "none"Validation mode (default: "development")
options.strictbooleanThrow on unknown events (default: false)

addTransport(adapter)

Adds a transport adapter. You must add at least one transport before calling .build().

const telemetry = IgniterTelemetry.create()
  .addTransport(LoggerTransportAdapter.create({ logger: console }))
  .addTransport(HttpTransportAdapter.create({ url: "https://..." }))
  .addTransport(SentryTransportAdapter.create({ sentry: Sentry }))
  .build();
ParameterTypeDescription
adapterIgniterTelemetryTransportAdapterA transport adapter instance

Falsy adapters throw TELEMETRY_INVALID_TRANSPORT. Always pass a valid adapter instance.


withSampling(policy)

Configures event sampling to control telemetry volume.

const telemetry = IgniterTelemetry.create()
  .withSampling({
    debugRate: 0.01,      // 1% of debug events
    infoRate: 0.1,        // 10% of info events
    warnRate: 1.0,        // 100% of warn events
    errorRate: 1.0,       // 100% of error events
    always: ["*.failed", "security.*"],   // Always sample
    never: ["health.check", "metrics.*"], // Never sample
  })
  .addTransport(loggerAdapter)
  .build();
FieldTypeDefaultDescription
debugRatenumber0.01Sampling rate for debug events (0–1)
infoRatenumber0.1Sampling rate for info events (0–1)
warnRatenumber1.0Sampling rate for warn events (0–1)
errorRatenumber1.0Sampling rate for error events (0–1)
alwaysstring[][]Glob patterns always sampled
neverstring[][]Glob patterns never sampled

withRedaction(policy)

Configures PII redaction applied before events reach transports.

const telemetry = IgniterTelemetry.create()
  .withRedaction({
    denylistKeys: ["password", "token", "authorization"],
    hashKeys: ["email", "ip", "userId"],
    maxStringLength: 5000,
  })
  .addTransport(loggerAdapter)
  .build();
FieldTypeDefaultDescription
denylistKeysstring[][]Keys to completely remove (case-insensitive)
hashKeysstring[][]Keys to SHA-256 hash (for correlation)
maxStringLengthnumber5000Maximum string length before truncation

withValidation(options)

Sets global event validation options. Overrides per-registry defaults.

const telemetry = IgniterTelemetry.create()
  .withValidation({ mode: "always", strict: true })
  .addTransport(loggerAdapter)
  .build();
FieldTypeDefaultDescription
mode"development" | "always" | "none""development"When to validate
strictbooleanfalseThrow on unknown events

withLogger(logger)

Sets an internal logger for the telemetry manager to report its own operational events (init, transport errors, etc.).

import { IgniterLogger } from "@igniter-js/common";

const telemetry = IgniterTelemetry.create()
  .withLogger(IgniterLogger.create({ name: "telemetry" }))
  .addTransport(loggerAdapter)
  .build();
ParameterTypeDescription
loggerIgniterLoggerLogger instance from @igniter-js/common

build()

Creates the runtime IgniterTelemetryManager instance. This is the final method in the chain.

const telemetry = IgniterTelemetry.create()
  .withService("api")
  .addTransport(loggerAdapter)
  .build();  // => IgniterTelemetryManager

During .build():

  1. Merges config with defaults
  2. Logs initialization info (if logger is set)
  3. Creates the manager instance
  4. Initializes all transports (adapter.init())

buildConfig()

Builds the configuration object without creating the runtime manager. Useful for inspection or testing.

const config = IgniterTelemetry.create()
  .withService("api")
  .addEvents(BillingEvents)
  .withSampling({ errorRate: 1.0 })
  .buildConfig();

console.log(config.service);     // "api"
console.log(config.sampling);    // { debugRate: 0.01, infoRate: 0.1, ... }
ReturnsTypeDescription
configIgniterTelemetryConfigResolved configuration object with defaults

Global Validation

You can set validation globally via .withValidation(), which applies to all events:

const telemetry = IgniterTelemetry.create()
  .withValidation({ mode: "always", strict: true })   // Global
  .addEvents(BillingEvents, { mode: "development" })   // Per-registry override
  .addEvents(AuthEvents)                                // Inherits global
  .addTransport(loggerAdapter)
  .build();

Per-registry options override global options for that specific registry.


Next Steps

  • Emitting Events — Three emit modes, attributes, levels, and errors
  • Sessions — Session lifecycle and scoped execution
  • Validation — Deep dive into event validation