IF Commons GitHub

otlp

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0001-telemetry FR-004

OTLP/HTTP with JSON, both ways (commons 0001-telemetry FR-004): export requests of traces, logs and metrics as the OTLP specification's JSON encoding writes them (camel-case field names, trace and span ids as hexadecimal, 64-bit integers as decimal strings, enumerations as integers, bytes as base64, signals grouped by resource and scope), the export responses with their partial success, and the decoding of each back to the values of ./otel.ts: a failure is a Result naming the path, a 64-bit integer is read from a JSON number or a string, an enumeration from its number or its name, and a field the decoder does not know is ignored.

import { decodeTraces, encodeTraces } from "./otlp.ts";
const request = encodeTraces([{ resource: { attributes: { "service.name": "build" } }, scope: { name: "ifc" }, spans: [] }]);
decodeTraces(JSON.parse(JSON.stringify(request))); // { kind: "ok", value: [ ...the same batch ] }

Source: commons/telemetry/src/otlp.ts

12 of 48 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

otlpnamespace
namespace otlp
otlp.TraceBatchtypeno test imports it
type TraceBatch = { readonly resource: Resource; readonly scope: Scope; readonly spans: readonly SpanData[] };

The spans of one resource and scope, as OTLP groups them.

otlp.LogBatchtypeno test imports it
type LogBatch = { readonly resource: Resource; readonly scope: Scope; readonly records: readonly LogRecord[] };

The log records of one resource and scope, as OTLP groups them.

otlp.MetricBatchtypeno test imports it
type MetricBatch = { readonly resource: Resource; readonly scope: Scope; readonly metrics: readonly Metric[] };

The metrics of one resource and scope, as OTLP groups them.

otlp.ExportResponsetypeno test imports it
type ExportResponse = { readonly rejected: number; readonly errorMessage: string };

An export response: how many signals were rejected (spans, log records or data points) and why; zero and "" for full success.

otlp.encodeAnyValuefunctionno test imports it
function encodeAnyValue(value: AnyValue): JsonObject

A value as OTLP's JSON AnyValue.

otlp.encodeAttributesfunctionno test imports it
function encodeAttributes(attributes: Readonly<Record<string, AttributeValue>>): Json[]

Attributes as OTLP's JSON list of KeyValue.

otlp.encodeSpanfunctionno test imports it
function encodeSpan(s: SpanData): JsonObject

A finished span as OTLP's JSON Span.

otlp.encodeLogRecordfunctionno test imports it
function encodeLogRecord(r: LogRecord): JsonObject

A log record as OTLP's JSON LogRecord.

otlp.encodeMetricfunctionno test imports it
function encodeMetric(m: Metric): JsonObject

A metric as OTLP's JSON Metric.

otlp.encodeTracesfunctionno test imports it
function encodeTraces(batches: readonly TraceBatch[]): JsonObject

Trace batches as an OTLP/JSON ExportTraceServiceRequest.

otlp.encodeLogsfunctionno test imports it
function encodeLogs(batches: readonly LogBatch[]): JsonObject

Log batches as an OTLP/JSON ExportLogsServiceRequest.

otlp.encodeMetricsfunctionno test imports it
function encodeMetrics(batches: readonly MetricBatch[]): JsonObject

Metric batches as an OTLP/JSON ExportMetricsServiceRequest.

otlp.encodeResponsefunctionno test imports it
function encodeResponse(signal: SignalName, response: ExportResponse): JsonObject

An export response as OTLP/JSON: {} for full success, else partialSuccess with the rejected count (a decimal string) and the message.

otlp.decodeAnyValueconstno test imports it
const decodeAnyValue: Decoder<AnyValue>

OTLP's JSON AnyValue as a value; an AnyValue that holds none is refused.

otlp.decodeAttributeValueconstno test imports it
const decodeAttributeValue: Decoder<AttributeValue>

An AnyValue that is an attribute value: a primitive, or an array of primitives of one type.

otlp.decodeAttributesconstno test imports it
const decodeAttributes: Decoder<Readonly<Record<string, AttributeValue>>>

OTLP's JSON list of KeyValue as attributes.

otlp.decodeSpanconstno test imports it
const decodeSpan: Decoder<SpanData>

OTLP's JSON Span as a finished span.

otlp.decodeLogRecordconstno test imports it
const decodeLogRecord: Decoder<LogRecord>

OTLP's JSON LogRecord as a log record; its severity number must be 1 to 24.

otlp.decodeMetricconstno test imports it
const decodeMetric: Decoder<Metric>

OTLP's JSON Metric as a metric: a sum, a gauge or a histogram (other data is refused).

otlp.decodeTracesfunctionno test imports it
function decodeTraces(input: unknown): Result<readonly TraceBatch[], DecodeError>

An OTLP/JSON ExportTraceServiceRequest as trace batches, one for each scope of each resource; a failure names its path.

otlp.decodeLogsfunctionno test imports it
function decodeLogs(input: unknown): Result<readonly LogBatch[], DecodeError>

An OTLP/JSON ExportLogsServiceRequest as log batches, one for each scope of each resource; a failure names its path.

otlp.decodeMetricsfunctionno test imports it
function decodeMetrics(input: unknown): Result<readonly MetricBatch[], DecodeError>

An OTLP/JSON ExportMetricsServiceRequest as metric batches, one for each scope of each resource; a failure names its path.

otlp.decodeResponsefunctionno test imports it
function decodeResponse(signal: SignalName, input: unknown): Result<ExportResponse, DecodeError>

An OTLP/JSON export response; an absent partialSuccess is full success.

otlp.countSignalsfunctionno test imports it
function countSignals(batches: readonly LogBatch[] | readonly MetricBatch[] | readonly TraceBatch[]): number

The number of signals in trace, log or metric batches: spans, log records, or data points (what a partial success counts).

TraceBatchtype
type TraceBatch = { readonly resource: Resource; readonly scope: Scope; readonly spans: readonly SpanData[] };

The spans of one resource and scope, as OTLP groups them.

Imported by 28 tests of the run (27 passed, 0 failed): the library's results

LogBatchtype
type LogBatch = { readonly resource: Resource; readonly scope: Scope; readonly records: readonly LogRecord[] };

The log records of one resource and scope, as OTLP groups them.

Imported by 28 tests of the run (27 passed, 0 failed): the library's results

MetricBatchtype
type MetricBatch = { readonly resource: Resource; readonly scope: Scope; readonly metrics: readonly Metric[] };

The metrics of one resource and scope, as OTLP groups them.

Imported by 28 tests of the run (27 passed, 0 failed): the library's results

ExportResponsetypeno test imports it
type ExportResponse = { readonly rejected: number; readonly errorMessage: string };

An export response: how many signals were rejected (spans, log records or data points) and why; zero and "" for full success.

encodeAnyValuefunctionno test imports it
function encodeAnyValue(value: AnyValue): JsonObject

A value as OTLP's JSON AnyValue.

encodeAttributesfunctionno test imports it
function encodeAttributes(attributes: Readonly<Record<string, AttributeValue>>): Json[]

Attributes as OTLP's JSON list of KeyValue.

encodeSpanfunctionno test imports it
function encodeSpan(s: SpanData): JsonObject

A finished span as OTLP's JSON Span.

encodeLogRecordfunctionno test imports it
function encodeLogRecord(r: LogRecord): JsonObject

A log record as OTLP's JSON LogRecord.

encodeMetricfunctionno test imports it
function encodeMetric(m: Metric): JsonObject

A metric as OTLP's JSON Metric.

encodeTracesfunction
function encodeTraces(batches: readonly TraceBatch[]): JsonObject

Trace batches as an OTLP/JSON ExportTraceServiceRequest.

Imported by 27 tests of the run (27 passed, 0 failed): the library's results

encodeLogsfunction
function encodeLogs(batches: readonly LogBatch[]): JsonObject

Log batches as an OTLP/JSON ExportLogsServiceRequest.

Imported by 8 tests of the run (8 passed, 0 failed): the library's results

encodeMetricsfunction
function encodeMetrics(batches: readonly MetricBatch[]): JsonObject

Metric batches as an OTLP/JSON ExportMetricsServiceRequest.

Imported by 8 tests of the run (8 passed, 0 failed): the library's results

encodeResponsefunction
function encodeResponse(signal: SignalName, response: ExportResponse): JsonObject

An export response as OTLP/JSON: {} for full success, else partialSuccess with the rejected count (a decimal string) and the message.

Imported by 8 tests of the run (8 passed, 0 failed): the library's results

decodeAnyValueconstno test imports it
const decodeAnyValue: Decoder<AnyValue>

OTLP's JSON AnyValue as a value; an AnyValue that holds none is refused.

decodeAttributeValueconstno test imports it
const decodeAttributeValue: Decoder<AttributeValue>

An AnyValue that is an attribute value: a primitive, or an array of primitives of one type.

decodeAttributesconstno test imports it
const decodeAttributes: Decoder<Readonly<Record<string, AttributeValue>>>

OTLP's JSON list of KeyValue as attributes.

decodeSpanconstno test imports it
const decodeSpan: Decoder<SpanData>

OTLP's JSON Span as a finished span.

decodeLogRecordconstno test imports it
const decodeLogRecord: Decoder<LogRecord>

OTLP's JSON LogRecord as a log record; its severity number must be 1 to 24.

decodeMetricconstno test imports it
const decodeMetric: Decoder<Metric>

OTLP's JSON Metric as a metric: a sum, a gauge or a histogram (other data is refused).

decodeTracesfunction
function decodeTraces(input: unknown): Result<readonly TraceBatch[], DecodeError>

An OTLP/JSON ExportTraceServiceRequest as trace batches, one for each scope of each resource; a failure names its path.

Imported by 28 tests of the run (27 passed, 0 failed): the library's results

decodeLogsfunction
function decodeLogs(input: unknown): Result<readonly LogBatch[], DecodeError>

An OTLP/JSON ExportLogsServiceRequest as log batches, one for each scope of each resource; a failure names its path.

Imported by 26 tests of the run (25 passed, 0 failed): the library's results

decodeMetricsfunction
function decodeMetrics(input: unknown): Result<readonly MetricBatch[], DecodeError>

An OTLP/JSON ExportMetricsServiceRequest as metric batches, one for each scope of each resource; a failure names its path.

Imported by 9 tests of the run (8 passed, 0 failed): the library's results

decodeResponsefunction
function decodeResponse(signal: SignalName, input: unknown): Result<ExportResponse, DecodeError>

An OTLP/JSON export response; an absent partialSuccess is full success.

Imported by 8 tests of the run (8 passed, 0 failed): the library's results

countSignalsfunction
function countSignals(batches: readonly LogBatch[] | readonly MetricBatch[] | readonly TraceBatch[]): number

The number of signals in trace, log or metric batches: spans, log records, or data points (what a partial success counts).

Imported by 20 tests of the run (20 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.