Skip to content

NodeSdk

Node.js OpenTelemetry setup for Effect applications.

This module exports a Configuration type and layers for installing tracing, metrics, and logging in Node.js. The main layer builds the shared OpenTelemetry resource from environment variables and optional service metadata, then enables only the signal types that have processors or readers configured. layerTracerProvider creates a scoped Node tracer provider, and layerEmpty provides an empty resource.

4 exports Added in v2.0.0 Source

Layers

layer

Added in v4.0.0 Source

Creates a Node OpenTelemetry layer from configuration, enabling tracing, metrics, and logging only when their processors or readers are supplied.

When to use

Use to install OpenTelemetry support for a Node.js Effect application from one configuration object, enabling tracing, metrics, logging, or any combination of those signals based on the processors and readers supplied.

Details

The configuration can be provided lazily or effectfully. The layer always provides Resource.Resource, building it from environment variables and any explicit resource metadata in the configuration.

Gotchas

Register Node auto-instrumentations before importing modules that should be patched, because many Node instrumentations hook module loading.

Signature

declare const layer: {
  (evaluate: LazyArg<Configuration>): Layer<Resource>;
  <R, E>(evaluate: Effect<Configuration, E, R>): Layer<Resource, E, R>;
};

layerEmpty

Added in v2.0.0 Source

Layer that provides an empty OpenTelemetry Resource.

Signature

declare const layerEmpty: Layer.Layer<Resource.Resource>;

Creates a scoped Node OpenTelemetry tracer provider from one or more span processors and shuts it down when the layer is released.

Signature

declare function layerTracerProvider(
  processor: any,
  config?: Omit<TracerConfig, "resource"> & {
    readonly shutdownTimeout?: Input;
  },
): Layer<OtelTracerProvider, never, Resource>;

Models

Configuration interface

Added in v4.0.0 Source

Configuration for the Node OpenTelemetry layer, including optional tracing, metrics, logging, resource, and shutdown settings.

Signature

interface Configuration {
  readonly loggerMergeWithExisting?: boolean;
  readonly loggerProviderConfig?: Omit<LoggerProviderConfig, "resource">;
  readonly logRecordProcessor?: any;
  readonly metricReader?: any;
  readonly metricTemporality?: TemporalityPreference;
  readonly resource?: {
    readonly attributes?: any;
    readonly serviceName: string;
    readonly serviceVersion?: string;
  };
  readonly shutdownTimeout?: Input;
  readonly spanProcessor?: any;
  readonly tracerConfig?: Omit<TracerConfig, "resource">;
}