otel
lib/otel.vklib/otel.vk
Pure-Veko OpenTelemetry W3C Trace Context (traceparent), span recorder, OTLP/HTTP JSON exporter,
and Prometheus text-format metrics registry (Counter, Gauge).
Zero capabilities required for span/metric recording and wire encoding (time/now optional via timestamps).
TraceContext = struct { trace_id str, span_id str, sampled bool = ... }
W3C traceparent context (00-<trace_id_32hex>-<span_id_16hex>-<flags_2hex>).
Span = struct { name str, trace_id str, span_id str, parent_id str, start_ns i64, end_ns i64 = ..., status str = ..., attributes map[str] = ... }
Recorded distributed trace span.
Registry = struct { service_name str, counters map[i64], gauges map[i64], helps map[str] }
In-memory metrics registry supporting counters and gauges.
make-context = fn [trace_hi i64, trace_lo i64, span_num i64, sampled bool] TraceContext
Formats a TraceContext as a W3C traceparent HTTP header value.
use [otel]
ctx = otel/make-context 0x1122334455667788 0x99aabbccddeeff00 0x0102030405060708 true
hdr = otel/format-traceparent ctx
parsed = otel/parse-traceparent hdr
if parsed.trace_id != ctx.trace_id or parsed.span_id != ctx.span_id or (not parsed.sampled) [
err 'traceparent roundtrip'
] else [ .ok ]
format-traceparent = fn [ctx TraceContext] str
Serializes ctx into 00-<32hex>-<16hex>-<01|00>.
parse-traceparent = fn [header_val str] TraceContext
Parses and validates a W3C traceparent header string (returns err if malformed; combine with /or).
start-span = fn [name str, parent TraceContext, span_num i64, start_ns i64] Span
Starts a child Span linked to parent with explicit start_ns timestamp and span_num ID.
finish-span = fn [mut sp Span, end_ns i64, /status st str] Span
Completes sp with end_ns and status ('OK' or 'ERROR').
export-otlp-json = fn [service_name str, spans block[Span]] str
Exports a block[Span] as an OpenTelemetry OTLP/HTTP ExportTraceServiceRequest JSON payload.
new-registry = fn [service_name str] Registry
Creates a new metrics Registry for service_name.
inc-counter = fn [mut reg Registry, name str, delta i64, /help help_txt str] i64
Increments monotonic counter name by delta (delta >= 0).
set-gauge = fn [mut reg Registry, name str, val i64, /help help_txt str] i64
Sets instantaneous gauge name to val.
export-prometheus = fn [reg Registry] str
Renders all counters and gauges in Prometheus 0.0.4 text exposition format.