Skip to content

OtlpResource.ts

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



Converts key/value entries into OTLP KeyValue attributes.

Signature

declare const entriesToAttributes: (entries: Iterable<[string, unknown]>) => Array<KeyValue>

Source

Since v4.0.0

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) => string

Source

Since v4.0.0

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) => AnyValue

Source

Since v4.0.0

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>

Source

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
}) => Resource

Source

Since v4.0.0

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
}

Source

Since v4.0.0

OTLP array value containing nested AnyValue entries.

Signature

export interface ArrayValue {
/** ArrayValue values */
values: Array<AnyValue>
}

Source

Since v4.0.0

Accepted runtime representations for an OTLP/protobuf fixed 64-bit value.

Signature

type Fixed64 = LongBits | string | number

Source

Since v4.0.0

An OTLP attribute represented as a string key and typed value.

Signature

export interface KeyValue {
/** KeyValue key */
key: string
/** KeyValue value */
value: AnyValue
}

Source

Since v4.0.0

OTLP key/value-list value containing nested attributes.

Signature

export interface KeyValueList {
/** KeyValueList values */
values: Array<KeyValue>
}

Source

Since v4.0.0

Low and high 32-bit parts of a 64-bit integer value.

Signature

export interface LongBits {
low: number
high: number
}

Source

Since v4.0.0

OTLP resource metadata attached to exported logs, metrics, and traces.

Signature

export interface Resource {
/** Resource attributes */
attributes: Array<KeyValue>
/** Resource droppedAttributesCount */
droppedAttributesCount: number
}

Source

Since v4.0.0