OtlpResource
Builds OTLP resource metadata shared by exported telemetry.
An OTLP resource describes the service and other attributes attached to every exported log, metric, or trace. This module builds resources from explicit options or OpenTelemetry environment variables and converts JavaScript values into OTLP attribute values.
Attributes
entriesToAttributes
Signature
declare function entriesToAttributes(entries: Iterable<[string, unknown]>): Array<KeyValue>;serviceNameUnsafe
Returns the service.name attribute from an OTLP resource.
When to use
Use when an OTLP resource is known to contain a string service.name and throwing is acceptable if that invariant is broken.
Gotchas
Throws if the resource does not contain a string service.name attribute.
Signature
declare function serviceNameUnsafe(resource: Resource): string;unknownToAttributeValue
Converts an arbitrary JavaScript value into an OTLP AnyValue.
Details
Arrays are converted recursively, primitive values use their matching OTLP fields, and unsupported values are formatted as strings.
Signature
declare function unknownToAttributeValue(value: unknown): AnyValue;Constructors
fromConfig
Creates an OTLP resource from explicit options and OpenTelemetry configuration.
When to use
Use when resource metadata may be configured in code or by the deployment environment. To let operators set the service identity, omit serviceName, serviceVersion, and their matching attributes, then use OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES.
Details
Explicit serviceName and serviceVersion options take precedence over matching explicit attributes. Explicit attributes take precedence over environment variables. OTEL_SERVICE_NAME and OTEL_SERVICE_VERSION take precedence over matching attributes in OTEL_RESOURCE_ATTRIBUTES. Missing required configuration is converted to a defect.
Signature
declare const fromConfig: (options?: { readonly attributes?: Record<string, unknown>; readonly serviceName?: string; readonly serviceVersion?: string;}) => Effect.Effect<Resource>;Creates an OTLP resource from service metadata and additional attributes.
Details
The resource always includes service.name, includes service.version when provided, and converts custom attributes into OTLP attribute values.
Signature
declare function make(options: { readonly attributes?: Record<string, unknown>; readonly serviceName: string; readonly serviceVersion?: string;}): Resource;Models
OTLP AnyValue payload for scalar, array, key/value-list, or byte values.
Signature
interface AnyValue { arrayValue?: ArrayValue; boolValue?: boolean | null; bytesValue?: Uint8Array<ArrayBufferLike>; doubleValue?: number | null; intValue?: string | number | null; kvlistValue?: KeyValueList; stringValue?: string | null;}ArrayValue interface
OTLP array value containing nested AnyValue entries.
Signature
interface ArrayValue { values: Array<AnyValue>;}Accepted runtime representations for an OTLP/protobuf fixed 64-bit value.
Signature
type Fixed64 = LongBits | string | number;An OTLP attribute represented as a string key and typed value.
Signature
interface KeyValue { key: string; value: AnyValue;}KeyValueList interface
OTLP key/value-list value containing nested attributes.
Signature
interface KeyValueList { values: Array<KeyValue>;}Low and high 32-bit parts of a 64-bit integer value.
Signature
interface LongBits { high: number; low: number;}OTLP resource metadata attached to exported logs, metrics, and traces.
Signature
interface Resource { attributes: Array<KeyValue>; droppedAttributesCount: number;}
Converts key/value entries into OTLP
KeyValueattributes.