// examples/36_regex_zstd_otel_and_bindgen.vk // Demonstrates Phase 6 batteries (zero capabilities required!): // - `text/re` linear-time Thompson NFA regex matching, extraction, and replacement // - `compress/zstd` RFC 8878 Zstandard frame compression & decompression // - `otel` W3C `traceparent` propagation, OTLP JSON span export, and Prometheus metrics use [ re = text/re zstd = compress/zstd otel ] main = fn [] any [ // 1. Linear-time Thompson NFA regex (`text/re`) rx = re/compile '[a-z]+-[0-9]+|v[0-9]+\\.[0-9]+' // Match service tags and versions in log line rx_ver = re/compile 'v[0-9]+\\.[0-9]+\\.[0-9]+' log_line = 'deploy node-07 running v1.0.0 -> upgraded to v1.2.4' vers = re/find-all rx_ver log_line scrubbed = re/replace-all (re/compile '[0-9]+') 'token=94821 user=42' '#' _ = rx if (len vers) != 2 or vers[0].text != 'v1.0.0' or vers[1].text != 'v1.2.4' or scrubbed != 'token=# user=#' [ return (err 'text/re match or replace failed') ] // 2. RFC 8878 Zstandard frame roundtrip (`compress/zstd`) raw_payload = bytes/from-str 'telemetry-frame: AAAAAAAAAAAAAAAAAAAAAAAA status=200 ok' compressed = zstd/compress raw_payload restored = zstd/decompress compressed if (not (zstd/zstd-frame? compressed)) or restored != raw_payload [ return (err 'compress/zstd roundtrip failed') ] // 3. OpenTelemetry W3C `traceparent` + OTLP JSON + Prometheus metrics (`otel`) ctx = otel/make-context 0x0af7651916cd43dd 0x8448eb211c80319c 0x00f067aa0ba902b7 true tp_hdr = otel/format-traceparent ctx parsed_ctx = otel/parse-traceparent tp_hdr mut sp = otel/start-span 'GET /api/nodes' parsed_ctx 0x1122334455667788 1000000 otel/set-attr mut sp 'http.method' 'GET' _ = otel/finish-span mut sp 1420000 otlp_json = otel/export-otlp-json 'veko-gateway' [sp] mut reg = otel/new-registry 'veko-gateway' _ = otel/inc-counter/help mut reg 'http_requests_total' 5 'Total HTTP requests' _ = otel/set-gauge mut reg 'active_connections' 12 prom_txt = otel/export-prometheus reg if (not (str/contains? otlp_json 'veko-gateway')) or (not (str/contains? prom_txt 'http_requests_total')) [ return (err 'otel export mismatch') ] println `[Example 36 OK] regex={vers[1].text} zstd={len compressed}B traceparent={tp_hdr[0..19]}...` .ok ] res = main if err? res [ println (str/append 'FAIL: ' (mold res)) os/exit 1 ]