MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / makeTelemetrySurface

Function makeTelemetrySurface

e2e/src/surfaces/telemetry.ts:40–75  ·  view source on GitHub ↗
(motelUrl: string)

Source from the content-addressed store, hash-verified

38}
39
40export const makeTelemetrySurface = (motelUrl: string): TelemetrySurface => {
41 const searchSpans = (query: SpanQuery) =>
42 Effect.gen(function* () {
43 const params = new URLSearchParams({ lookback: "15m", limit: "100" });
44 if (query.operation) params.set("operation", query.operation);
45 if (query.traceId) params.set("traceId", query.traceId);
46 for (const [key, value] of Object.entries(query.attributes ?? {})) {
47 params.set(`attr.${key}`, value);
48 }
49 const response = yield* Effect.promise(() => fetch(`${motelUrl}/api/spans/search?${params}`));
50 if (!response.ok) {
51 return yield* Effect.fail(
52 `motel span search responded ${response.status}: ${yield* Effect.promise(() => response.text())}`,
53 );
54 }
55 const body = (yield* Effect.promise(() => response.json())) as {
56 readonly data?: readonly ExportedSpan[];
57 };
58 return body.data ?? [];
59 });
60
61 return {
62 searchSpans,
63 expectSpan: (query) =>
64 searchSpans(query).pipe(
65 Effect.filterOrFail(
66 (spans) => spans.length > 0,
67 () => `no exported span matched ${JSON.stringify(query)}`,
68 ),
69 Effect.map((spans) => spans[0]!),
70 // ~20s ceiling (40 × 500ms): BatchSpanProcessor flushes ~1s after the
71 // request and the dev stack drains on waitUntil; slower is a real bug.
72 Effect.retry(Schedule.both(Schedule.spaced("500 millis"), Schedule.recurs(40))),
73 ),
74 };
75};

Callers 1

contextForFunction · 0.90

Calls 2

searchSpansFunction · 0.85
retryMethod · 0.80

Tested by

no test coverage detected