Skip to content
Myr

Merge observability/typed-failures into main

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by oscabriel · committed by oscabriel · parents 1985111, 09babdf · Browse files · 3 files+33 added−18 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+33 added−18 removed

  • tests:+9 added−5 removed
  • other:+24 added−13 removed

3 files+33 added−18 removed

modified:apps/sandbox/test/telemetry.test.ts+3 added-1 removed
modified:packages/telemetry/src/spans/binding.ts+24 added-13 removed
2 unmodified lines
3// way to make a span active once it is open: every span opened here is a4// child of the invocation's root span, a sibling of the others and of the5// runtime's own (fetch, RPC, D1, storage) opened while it runs. Effect keeps6// the nesting; the trace shows each span's name, timing, ids and failures.7import { Cause, Exit, Layer, Predicate, Tracer } from "effect";7import { Array, Cause, Exit, Layer, Predicate, Tracer } from "effect";89import type { DefectKeeping } from "../defects.ts";10import type { Scrub } from "../logger.ts";11import { INVOCATION_KEYS, InvocationSpan, SPAN_KEYS } from "../spans.ts";
18 unmodified lines
30 */31 readonly defects: DefectKeeping;32}3334// A typed failure is a refusal or a port's error: its tag says what it was.35// Only a defect brings its message and stack, scrubbed.34// A typed failure is a refusal or a port's error, the product working: its35// tag goes on the span as `failure`. workerd logs each recorded exception at36// error level, where Issues, smoke and the alerts count it, so only a defect37// is recorded as one, with its message and stack, scrubbed.38const recordFailures = <A, E>(39 span: WorkerSpan,40 exit: Exit.Exit<A, E>,41 { defects, scrub }: Keeping
1 unmodified line
43 if (Exit.isSuccess(exit)) {44 return;45 }4645 for (const reason of exit.cause.reasons) {46 if (Cause.isFailReason(reason)) {47 const failures = Array.dedupe(48 exit.cause.reasons.flatMap((reason) => {49 if (!Cause.isFailReason(reason)) {50 return [];51 }5253 const failure = reason.error;5449 span.recordException({50 name:51 Predicate.hasProperty(failure, "_tag") &&52 Predicate.isString(failure._tag)53 ? failure._tag54 : "Failure",55 });56 }55 return [56 Predicate.hasProperty(failure, "_tag") &&57 Predicate.isString(failure._tag)58 ? failure._tag59 : "Failure",60 ];61 })62 );6364 if (Array.isReadonlyArrayNonEmpty(failures)) {65 span.setAttribute("failure", failures.join(","));66 }6768 for (const reason of exit.cause.reasons) {69 if (Cause.isDieReason(reason)) {70 for (const error of Cause.prettyErrors(Cause.fromReasons([reason]))) {71 span.recordException(72 defects === "name"
107 unmodified lines
modified:packages/telemetry/test/spans.test.ts+6 added-4 removed
112 unmodified lines
113 })114 );115116 it.effect(117 "records a typed failure by its tag alone, and a defect by its name, message and stack, scrubbed",117 "keeps a typed failure's tag as an attribute, never an exception workerd would log as an error, and records a defect by its name, message and stack, scrubbed",118 () =>119 Effect.gen(function* () {120 const secret = "tok_0123456789abcdef0123456789abcdef";121
23 unmodified lines
145 });146147 const [, refused, defect] = spans;148149 expect(refused?.exceptions).toStrictEqual([150 { name: "VerifierBlocked" },151 ]);149 expect(refused?.exceptions).toStrictEqual([]);150 expect(Object.fromEntries(refused?.attributes ?? [])).toStrictEqual({151 failure: "VerifierBlocked",152 });153 expect(Object.fromEntries(defect?.attributes ?? [])).toStrictEqual({});154 expect(155 defect?.exceptions.map(({ message, name }) => ({ message, name }))156 ).toStrictEqual([157 { message: "no fetch with <redacted>", name: "TypeError" },
163 unmodified lines