main
ply4 git calls25 ms43 KiB3 cachedprotocol v2
121 lines5.4 KiBRaw
1import { atIndex, chainGet, fromAbsent, fromNullable } from '../absent.ts';
2import type { FlatSpan } from 'ply';
3import type { FilterName, TraceBar, TraceModel } from './model.ts';
5/** One of the request's ended spans, as ply hands it to Tracer `onEnd` (an EndedSpan): plain attribute values. */
6export type TraceSpan = Pick<FlatSpan, 'name' | 'status' | 'attrs'> & { readonly startTimeUnixNano: string; readonly endTimeUnixNano: string };
8type RawSpan = {
9 name: string;
10 startMs: number;
11 durMs: number;
12 status: 'ok' | 'error';
13 message: string;
14 attrs: Record<string, unknown>;
15};
17const SHOW = [
18 'http.response.status_code', 'git.upstream.cf_ray', 'git.upstream.phase', 'git.upstream.dur_ms',
19 'git.response.bytes', 'git.response.cache', 'git.response.duration_ms',
20 'git.fetch.filter', 'git.fetch.filter.requested', 'git.fetch.filter.fallback', 'git.fetch.filter.learned',
21 'git.fetch.wants', 'git.fetch.haves.count', 'git.fetch.deepen', 'git.fetch.thin_pack', 'git.fetch.ofs_delta',
22 'git.server.agent', 'git.server.object_format', 'git.server.caps', 'git.server.fetch', 'git.protocol.version',
23 'git.pkt.frames', 'git.pkt.data', 'git.pkt.flush', 'git.pkt.delim', 'git.pkt.bytes', 'git.pkt.payload.max',
24 'git.sideband.band1.bytes', 'git.sideband.band2.bytes', 'git.sideband.band3.bytes', 'git.sideband.progress.tail',
25 'git.pack.objects', 'git.pack.bytes', 'git.pack.ofs_delta', 'git.pack.ref_delta', 'git.pack.chain.max', 'git.pack.trailer',
26 'git.pack.full', 'git.fetch.wide.objects', 'git.fetch.wide.extra_bytes', 'git.fetch.wide.blobs',
27 'git.ls_refs.count', 'git.ls_refs.head', 'error.type', 'git.viewer.blob.too_big', 'git.viewer.blob.size',
28] as const;
31function spansOf(ended: readonly TraceSpan[]): RawSpan[] {
32 const spans: RawSpan[] = ended.map(span => {
33 const start = BigInt(span.startTimeUnixNano);
34 const end = BigInt(span.endTimeUnixNano);
35 return {
36 name: span.name,
37 startMs: Number(start / 1_000_000n),
38 durMs: Math.max(0, Number((end - start) / 1_000_000n)),
39 status: span.status.code === 2 ? 'error' : 'ok',
40 message: (span.status.code === 2 ? span.status.message : '').slice(0, 180),
41 attrs: span.attrs,
42 };
43 });
44 spans.sort((a, b) => a.startMs - b.startMs || a.name.localeCompare(b.name));
45 return spans;
48function summarise(value: unknown): string {
49 if (Array.isArray(value)) {
50 if (value.length > 8) return `${value.length} items`;
51 return value.map(item => summarise(item)).join(' ');
52 }
53 const text = typeof value === 'string' ? value : JSON.stringify(value);
54 return text.length > 180 ? `${text.slice(0, 177)}...` : text;
57function wantOf(attrs: Record<string, unknown>): string | null {
58 const wants = attrs['git.fetch.wants'];
59 const first = Array.isArray(wants) ? wants[0] : wants;
60 return typeof first === 'string' && /^[0-9a-f]{40}$/.test(first) ? first : null;
63function filterOf(attrs: Record<string, unknown>): FilterName | null {
64 const fallback = attrs['git.fetch.filter.fallback'];
65 const filter = typeof fallback === 'string' && fallback ? fallback : attrs['git.fetch.filter'];
66 if (filter === 'tree:0' || filter === 'blob:none') return filter;
67 return null;
70function linesFor(span: RawSpan): string[] {
71 const lines: string[] = [];
72 for (const key of SHOW) {
73 const value = fromAbsent(span.attrs[key]);
74 if (value.tag === 'none' || value.value === '' || value.value === null) continue;
75 lines.push(`${key}=${summarise(value.value)}`);
76 }
77 if (span.status === 'error' && span.message) lines.push(`error=${span.message}`);
78 return lines;
81function isRoundTrip(name: string): boolean {
82 return name.startsWith('git.upload-pack') || name.startsWith('git.receive-pack');
85export function buildTrace(ended: readonly TraceSpan[], cfRay: string, requestId: string): TraceModel {
86 const raw = spansOf(ended);
87 const trips = raw.filter(span => isRoundTrip(span.name));
88 const shown = trips.length ? trips : raw;
89 const bars: TraceBar[] = shown.map(span => {
90 const http = span.attrs['http.response.status_code'];
91 const bytes = span.attrs['git.response.bytes'];
92 const cache = span.attrs['git.response.cache'];
93 const fetch = span.name === 'git.upload-pack fetch';
94 return {
95 name: span.name,
96 startMs: span.startMs,
97 durMs: span.durMs,
98 status: span.status,
99 httpStatus: typeof http === 'number' ? http : null,
100 bytes: typeof bytes === 'number' ? bytes : null,
101 cache: typeof cache === 'string' ? cache : '',
102 lines: linesFor(span),
103 packWant: fetch ? wantOf(span.attrs) : null,
104 packFilter: fetch ? filterOf(span.attrs) : null,
105 };
106 });
107 const first = atIndex(bars, 0);
108 const firstStart = first.tag === 'some' ? chainGet(first.value, 'startMs') : fromNullable(null);
109 const origin = firstStart.tag === 'some' && typeof firstStart.value === 'number' ? firstStart.value : 0;
110 const start = bars.reduce((min, bar) => Math.min(min, bar.startMs), origin);
111 const end = bars.reduce((max, bar) => Math.max(max, bar.startMs + bar.durMs), start);
112 return { bars: bars.map(bar => ({ ...bar, startMs: bar.startMs - start })), totalMs: Math.max(0, end - start), cfRay, requestId };
115export function traceHeader(trace: TraceModel): string {
116 const parts = trace.bars.slice(0, 16).map(bar => {
117 const name = bar.name.replace(/[^a-z0-9_-]+/gi, '_').replace(/^_+|_+$/g, '').slice(0, 40) || 'span';
118 return `${name};dur=${Math.round(bar.durMs)}`;
119 });
120 return parts.join(', ').slice(0, 1500);
Diagnostics4 git calls · 25 ms
CallStatusSizeTime025 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200145 B · hit3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=145
git.response.cache=HIT
git.response.duration_ms=3
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=145
git.pkt.payload.max=76
git.ls_refs.count=2
git.ls_refs.head=refs/heads/main
fetchblob:none · deepen 1020040 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=41349
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=526b305930b8ef382f2d7a1f9c0238730a585921
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=6
git.pkt.data=4
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=41349
git.pkt.payload.max=41254
git.sideband.band1.bytes=41253
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=61
git.pack.bytes=41253
git.pack.ofs_delta=0
git.pack.ref_delta=0
git.pack.chain.max=0
git.pack.trailer=ab60efef4b7243678c75de64a4386986ee885c1c
git.pack.full=61
Open pack map
fetch2002.0 KiB · hit19 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=19
git.response.bytes=2047
git.response.cache=HIT
git.response.duration_ms=19
git.fetch.wants=d1810a999dc38a5411d0b06f9f4d6cdfb1ca868e
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=2047
git.pkt.payload.max=2026
git.sideband.band1.bytes=2025
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/ply-web.git
Ref
refs/heads/main
Commit
526b305930b8ef382f2d7a1f9c0238730a585921
cf-ray
a5e2eae26c2e4bc2
Request
a24ec698…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format