Resource.ts
Resource.ts overview
Section titled “Resource.ts overview”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.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”configuration
Section titled “configuration”configToAttributes
Section titled “configToAttributes”Converts resource configuration into OpenTelemetry attributes, adding service name, optional service version, and telemetry SDK metadata.
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
The returned record copies attributes first, then sets service.name,
telemetry.sdk.name, and telemetry.sdk.language. service.version is
included only when serviceVersion is provided.
Gotchas
Custom values for service.name and telemetry.sdk.* are overwritten by this
helper. An empty serviceVersion is treated as absent.
See
layerfor creating aResourcelayer from explicit metadatalayerFromEnvfor merging attributes with OpenTelemetry environment variables
Signature
declare const configToAttributes: (options: { readonly serviceName: string readonly serviceVersion?: string readonly attributes?: OtelApi.Attributes}) => Record<string, string>Since v4.0.0
layers
Section titled “layers”Creates a Resource layer from service metadata and additional OpenTelemetry attributes.
Signature
declare const layer: (config: { readonly serviceName: string readonly serviceVersion?: string readonly attributes?: OtelApi.Attributes}) => Layer.Layer<Resource, never, never>Since v4.0.0
layerEmpty
Section titled “layerEmpty”Layer that provides an empty OpenTelemetry resource.
Signature
declare const layerEmpty: Layer.Layer<Resource, never, never>Since v4.0.0
layerFromEnv
Section titled “layerFromEnv”Creates a Resource layer from OpenTelemetry environment variables, optionally merging additional attributes.
Signature
declare const layerFromEnv: (additionalAttributes?: OtelApi.Attributes | undefined) => Layer.Layer<Resource>Since v4.0.0
services
Section titled “services”Resource (class)
Section titled “Resource (class)”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 ResourceSince v4.0.0