Skip to content
Effect 4.0 is here. One ecosystem. Zero dependencies.

Resource unstable

OpenTelemetry resource service and layers.

An OpenTelemetry resource identifies the process or service that emits spans, metrics, and logs. This module stores that resource in Effect context and provides layers for creating it from explicit service metadata, from OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES, or as an empty resource. It also includes configToAttributes for turning service metadata into raw OpenTelemetry attributes.

5 exports Since v4.0.0 Source

Converting

Since v4.0.0

Converts service metadata into OpenTelemetry attributes with SDK defaults.

When to use

Use to turn explicit service metadata into a raw OpenTelemetry attribute map for lower-level resource construction or merging with environment-derived attributes via layerFromEnv.

Details

Custom attributes override telemetry.sdk.* defaults. Service options override matching attributes. An empty serviceVersion is treated as absent.

See

  • layer for creating a Resource layer from explicit metadata
  • layerFromEnv for merging attributes with OpenTelemetry environment variables

Signature

declare function configToAttributes(options: {
readonly attributes?: any;
readonly serviceName: string;
readonly serviceVersion?: string;
}): Record<string, string>

Layers

layer

unstable
Since v4.0.0

Creates a Resource layer from service metadata and additional OpenTelemetry attributes.

Signature

declare function layer(config: {
readonly attributes?: any;
readonly serviceName: string;
readonly serviceVersion?: string;
}): Layer<Resource, never, never>

layerEmpty

unstable
Since v4.0.0

Layer that provides an empty OpenTelemetry resource.

Signature

declare const layerEmpty: Layer<Resource, never, never>
Since v4.0.0

Creates a Resource layer from SDK defaults, then environment variables, then additional attributes (later values take precedence).

Signature

declare function layerFromEnv(additionalAttributes?: any): Layer<Resource>

Services

Resource

unstable
Since v4.0.0

Service tag for OpenTelemetry metadata attached to emitted telemetry.

When to use

Use to provide process, service, and deployment metadata that should be attached to spans, metrics, and logs.

Signature

declare class Resource extends Shape<"@effect/opentelemetry/Resource", Resource, this> {
constructor(_: never);
}