Skip to content

createInstrumentation() function

Home > @rimitive/core > createInstrumentation

Create an instrumentation context from configuration.

This is the main entry point for setting up instrumentation. Returns undefined if instrumentation is disabled, allowing safe optional chaining in production.

Type overloads provide precise return types: - enabled: false → always returns undefined - enabled: true with providers → always returns InstrumentationContext - Otherwise → InstrumentationContext | undefined

Signature:

export declare function createInstrumentation(config: InstrumentationConfig & {
enabled: false;
}): undefined;

Parameter

Type

Description

config

InstrumentationConfig & { enabled: false; }

Returns:

undefined

Basic usage

import { createInstrumentation, devtoolsProvider, compose } from '@rimitive/core';
import { SignalModule, ComputedModule } from '@rimitive/signals/extend';
const instrumentation = createInstrumentation({
enabled: import.meta.env.DEV,
providers: [devtoolsProvider()],
});
// Use with compose
const svc = compose(SignalModule, ComputedModule, { instrumentation });

Production-safe pattern

// Returns undefined in production (enabled: false)
const instrumentation = createInstrumentation({
enabled: false,
providers: [],
});
// Type is `undefined`, no runtime overhead

Multiple providers

const instrumentation = createInstrumentation({
providers: [
devtoolsProvider(),
analyticsProvider(),
loggingProvider({ verbose: true }),
],
});