Traces module · writer API
OTLP trace writers
Encode the shared five-table Arrow trace projection as binary OTLP protobuf or standards-compliant OTLP protobuf-JSON.
What it writes
Send normalized trace tables back to OTLP systems.
The writers reconstruct resource, scope, span, event, and link messages from the shared Arrow tables while validating identifiers, relationships, and attribute encoding.
Input
The five documented Arrow tables
Binary
OTLP protobuf bytes
JSON
OTLP protobuf-JSON text or bytes
Validation
IDs, references, values, and attributes
Detailed guide
OTLP trace writer reference
The sections below document usage, JSON formatting, validation, and reconstruction behavior.
OtlpTraceWriter encodes an OtlpTrace Arrow projection as binary protobuf.
OtlpTraceJsonWriter encodes the same input as standards-compliant OTLP protobuf-JSON.
Usage
import {encode, load} from '@loaders.gl/core';
import {OtlpTraceJsonLoader, OtlpTraceJsonWriter, OtlpTraceWriter} from '@loaders.gl/traces/otlp';
const trace = await load('traces.otlp.json', OtlpTraceJsonLoader);
const protobuf = await encode(trace, OtlpTraceWriter);
const json = await encode(trace, OtlpTraceJsonWriter, {
otlpTraceJson: {space: 2}
});
The JSON writer emits trace and span IDs as lowercase hexadecimal strings, enum values as integers, and 64-bit integers using protobuf-JSON string representation.
JSON Writer Options
| Option | Type | Default | Description |
|---|---|---|---|
otlpTraceJson.space | number | 0 | Spaces used to pretty-print JSON. Values are clamped to 0 through 10. |
Validation
The writers require the five documented Arrow tables and schemas. They reject missing relational references, malformed attribute JSON, nonnumeric required values, and identifiers whose byte width does not match OTLP. Rows are grouped back into resource, scope, and span messages using their keys.
Unknown protobuf fields discarded during loading cannot be written back. Attribute values remain lossless because their protobuf-JSON tagged representation is retained in Arrow.