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.
Converting
configToAttributes
unstableConverts 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
Resourcelayer 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
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
unstableLayer that provides an empty OpenTelemetry resource.
Signature
declare const layerEmpty: Layer<Resource, never, never>layerFromEnv
unstableCreates a Resource layer from SDK defaults, then environment variables,
then additional attributes (later values take precedence).
Details
OTEL_RESOURCE_ATTRIBUTES is read with Config.Record, so a structured
config value is accepted as well as a key=value list. In the list, keys and
values are trimmed, then percent-decoded once. Entries with an empty value
are kept as ""; entries without = or with an empty key are skipped. When
a key is repeated as written, the last entry wins and the earlier ones are
not decoded. If any remaining key or value is not valid percent-encoding,
the whole variable is discarded and a warning is logged.
Signature
declare function layerFromEnv(additionalAttributes?: any): Layer<Resource>Services
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);}