OtlpResource.ts
OtlpResource.ts overview
Section titled “OtlpResource.ts overview”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.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”Attributes
Section titled “Attributes”entriesToAttributes
Section titled “entriesToAttributes”Converts key/value entries into OTLP KeyValue attributes.
Signature
declare const entriesToAttributes: (entries: Iterable<[string, unknown]>) => Array<KeyValue>Since v4.0.0
serviceNameUnsafe
Section titled “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 const serviceNameUnsafe: (resource: Resource) => stringSince v4.0.0
unknownToAttributeValue
Section titled “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 const unknownToAttributeValue: (value: unknown) => AnyValueSince v4.0.0
constructors
Section titled “constructors”fromConfig
Section titled “fromConfig”Creates an OTLP resource from explicit options and OpenTelemetry configuration.
Details
OTEL_RESOURCE_ATTRIBUTES, OTEL_SERVICE_NAME, and
OTEL_SERVICE_VERSION override explicit options; missing required
configuration is converted to a defect.
Signature
declare const fromConfig: ( options?: | { readonly serviceName?: string | undefined readonly serviceVersion?: string | undefined readonly attributes?: Record<string, unknown> | undefined } | undefined) => Effect.Effect<Resource>Since v4.0.0
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 const make: (options: { readonly serviceName: string readonly serviceVersion?: string | undefined readonly attributes?: Record<string, unknown> | undefined}) => ResourceSince v4.0.0
models
Section titled “models”AnyValue (interface)
Section titled “AnyValue (interface)”OTLP AnyValue payload for scalar, array, key/value-list, or byte values.
Signature
export interface AnyValue { /** AnyValue stringValue */ stringValue?: string | null /** AnyValue boolValue */ boolValue?: boolean | null /** AnyValue intValue */ intValue?: number | null /** AnyValue doubleValue */ doubleValue?: number | null /** AnyValue arrayValue */ arrayValue?: ArrayValue /** AnyValue kvlistValue */ kvlistValue?: KeyValueList /** AnyValue bytesValue */ bytesValue?: Uint8Array}Since v4.0.0
ArrayValue (interface)
Section titled “ArrayValue (interface)”OTLP array value containing nested AnyValue entries.
Signature
export interface ArrayValue { /** ArrayValue values */ values: Array<AnyValue>}Since v4.0.0
Fixed64 (type alias)
Section titled “Fixed64 (type alias)”Accepted runtime representations for an OTLP/protobuf fixed 64-bit value.
Signature
type Fixed64 = LongBits | string | numberSince v4.0.0
KeyValue (interface)
Section titled “KeyValue (interface)”An OTLP attribute represented as a string key and typed value.
Signature
export interface KeyValue { /** KeyValue key */ key: string /** KeyValue value */ value: AnyValue}Since v4.0.0
KeyValueList (interface)
Section titled “KeyValueList (interface)”OTLP key/value-list value containing nested attributes.
Signature
export interface KeyValueList { /** KeyValueList values */ values: Array<KeyValue>}Since v4.0.0
LongBits (interface)
Section titled “LongBits (interface)”Low and high 32-bit parts of a 64-bit integer value.
Signature
export interface LongBits { low: number high: number}Since v4.0.0
Resource (interface)
Section titled “Resource (interface)”OTLP resource metadata attached to exported logs, metrics, and traces.
Signature
export interface Resource { /** Resource attributes */ attributes: Array<KeyValue> /** Resource droppedAttributesCount */ droppedAttributesCount: number}Since v4.0.0