mirror: Blazing fast w3c Trace Contexts for any JS runtime
0

Configure Feed

Select the types of activity you want to include in your feed.

chore: uses w3c for spec conformance testing

Marais Rossouw (Mar 28, 2024, 11:00 PM +1000) 42969494 d77f34d6

+93 -1
+12 -1
.github/workflows/ci.yml
··· 10 10 runs-on: ubuntu-latest 11 11 steps: 12 12 - uses: actions/checkout@main 13 + with: 14 + submodules: recursive 13 15 14 16 - name: (env) setup bun 15 17 uses: oven-sh/setup-bun@v1 16 18 with: 17 - bun-version: 1.0.18 19 + bun-version: '1.0.35' 20 + 21 + - uses: actions/setup-python@v5 22 + with: 23 + python-version: '3.10' 24 + cache: pip 18 25 19 26 - name: (env) cache 20 27 uses: actions/cache@v3 ··· 30 37 - run: bun run build 31 38 - run: bun run typecheck 32 39 - run: bun test 40 + 41 + - run: pip install -r ./validation/requirements.txt 42 + - name: w3c validation test 43 + run: ./validation/test.sh 33 44 34 45 test_rs: 35 46 name: Rust ${{ matrix.rustv }}
+3
.gitmodules
··· 1 + [submodule "validation/w3c"] 2 + path = validation/w3c 3 + url = https://github.com/w3c/trace-context.git
+1
validation/requirements.txt
··· 1 + aiohttp==3.9.3
+18
validation/test.sh
··· 1 + #!/usr/bin/env bash 2 + 3 + set -euo pipefail 4 + 5 + python3 --version 6 + echo -e "Node $(node --version)" 7 + 8 + pushd $(dirname $0) > /dev/null 9 + 10 + node test_server.mjs & 11 + node_pid=$! 12 + trap "kill $node_pid" EXIT 13 + 14 + until nc -z localhost 8000; do echo "Waiting for server to open port..."; sleep 1; done; 15 + 16 + env STRICT_LEVEL=1 python3 w3c/test/test.py http://localhost:8000/test || exit 1 17 + 18 + kill $node_pid
+59
validation/test_server.mjs
··· 1 + import * as traceparent from '../traceparent.mjs'; 2 + import * as tracestate from '../tracestate.mjs'; 3 + 4 + import { createServer } from 'node:http'; 5 + 6 + createServer((req, res) => { 7 + let u = new URL(req.url, 'http://localhost'); 8 + let m = req.method; 9 + if (m === 'POST' && u.pathname === '/test') return void test(req, res); 10 + send(res, '', 404); 11 + }).listen(8000); 12 + 13 + async function test(req, res) { 14 + try { 15 + var payload = await json(req); 16 + } catch (e) { 17 + return send(res, String(e), 400); 18 + } 19 + 20 + let traceparent_v, tracestate_v, tmp; 21 + tmp = req.headers.traceparent; 22 + if (tmp) traceparent_v = traceparent.parse(tmp); 23 + 24 + tmp = req.headers.tracestate; 25 + if (traceparent_v && tmp) tracestate_v = tracestate.parse(tmp); 26 + traceparent_v ||= traceparent.make(); 27 + 28 + const headers = new Headers(); 29 + if (tracestate_v) headers.set('tracestate', String(tracestate_v)); 30 + 31 + // Intentionally not batching requests 32 + for (let p of payload) { 33 + headers.set('traceparent', traceparent_v.child()); 34 + await fetch(p.url, { 35 + method: 'POST', 36 + headers, 37 + body: JSON.stringify(p.arguments), 38 + }); 39 + } 40 + 41 + return send(res, 'Ok', 200); 42 + } 43 + 44 + // -- 45 + function send(res, body, status) { 46 + res.writeHead(status); 47 + res.end(body); 48 + } 49 + 50 + function json(req) { 51 + let v = '', 52 + resolve; 53 + let p = new Promise((rs) => { 54 + resolve = rs; 55 + }); 56 + req.on('data', (c) => (v += c)); 57 + req.on('end', () => resolve(JSON.parse(v))); 58 + return p; 59 + }