Merge observability/log-levels 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 0d940fc, 965c992 · Browse files · 5 files·+24 added−12 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+24 added−12 removed
- tests:+13 added−11 removed
- other:+11 added−1 removed
Provenance
- Commit
7b71d37- Tree
9dea606- Author
oscabriel <oscarhernandeziv@gmail.com>- Committer
oscabriel <oscarhernandeziv@gmail.com>- Parent 1
0d940fc- Parent 2
965c992
5 files changed+24 added−12 removed
modified:apps/sandbox/test/telemetry.test.ts+1 added-1 removed
149 unmodified linesExpand all1501511521531541541551561571585 unmodified lines149 unmodified linesExpand all
expect(console.written()).toStrictEqual([ { line: { level: "WARN", level: "warn", message: "git said: bad credentials <redacted>", sha, }, method: "warn",5 unmodified linesmodified:infra/created.jsonl+3 added
372 unmodified lines373 {"at":"2026-10-11T03:15:53.204Z","by":"import","kind":"repo","name":"kilo","namespace":"projects-demo","stage":"demo","note":"tags backfilled"}374 {"at":"2026-10-11T03:16:04.995Z","by":"import","kind":"repo","name":"sinatra","namespace":"projects-demo","stage":"demo","note":"tags backfilled"}375 {"at":"2026-10-11T03:16:13.273Z","by":"import","kind":"repo","name":"nvm","namespace":"projects-demo","stage":"demo","note":"tags backfilled"}376 {"at":"2026-10-12T05:05:00.000Z","by":"import","kind":"repo","name":"github.com__juliangruber__isarray","namespace":"projects-dev-oscabriel","stage":"dev-oscabriel","note":"imported by the user from the web, at the host-path offer /github.com/juliangruber/isarray (issue 1431); the time is when it was seen, not made; kept"}377+{"at":"2026-10-13T22:45:14.143Z","by":"smoke","kind":"project","name":"oscabriel__smoke-20261013-224510","stage":"dev-oscabriel"}378+{"at":"2026-10-13T22:45:14.144Z","by":"smoke","kind":"repo","name":"oscabriel__smoke-20261013-224510","namespace":"projects-dev-oscabriel","stage":"dev-oscabriel"}379+{"at":"2026-10-13T22:46:08.425Z","by":"smoke","kind":"repo","name":"oscabriel__smoke-20261013-224510--parse-year--bram","namespace":"projects-dev-oscabriel","stage":"dev-oscabriel"}modified:packages/telemetry/src/logger.ts+8 added-1 removed
30 unmodified lines31 return kept;32 };33 };34 35+// Workers Logs names a line's level as its console method does, in lowercase36+// (`error`, `warn`, `info`), and a logged object's own `level` takes its37+// place: Effect's `ERROR` would read as no error where a query asks for38+// `level = 'error'`, as smoke and the alerts do. A fatal line is an error.39+const workersLevel = (level: string) =>40+ level === "FATAL" ? "error" : level.toLowerCase();41+42 export const jsonLogger = (scrub: Scrub): Logger.Logger<unknown, void> =>43 Logger.withLeveledConsole(44 Logger.map(45 Logger.formatStructured,8 unmodified lines54 [55 "message",56 Array.isArray(message) ? message.map(scrubbed) : scrubbed(message),57 ],51- ["level", level],58+ ["level", workersLevel(level)],59 ...(cause === undefined ? [] : [["cause", scrub(cause)] as const]),60 ...(Object.keys(spans).length === 061 ? []62 : [["spans", spans] as const]),4 unmodified linesmodified:packages/telemetry/test/defects.test.ts+3 added-3 removed
56 unmodified lines57 );58 59 expect(errors).toHaveLength(1);60 expect(errors[0]).toMatchObject({61- level: "ERROR",61+ level: "error",62 message: "Error: the store is gone",63 project: datekit,64 requestId: "push-1",65 });85 unmodified lines151 "name"152 );153 154 expect(errors).toMatchObject([155- { level: "ERROR", message: "TypeError: <withheld>" },156- { level: "ERROR", message: "Error: <withheld>" },155+ { level: "error", message: "TypeError: <withheld>" },156+ { level: "error", message: "Error: <withheld>" },157 ]);158 expect(errors[0]).toHaveProperty(159 "cause",160 expect.stringMatching(/^TypeError: <withheld>\n\s+at /u)57 unmodified linesmodified:packages/telemetry/test/logger.test.ts+9 added-7 removed
39 unmodified lines40 41 expect(written).toStrictEqual([42 {43 line: {44- level: "INFO",44+ level: "info",45 message: "a push reached custody",46 project: "alice/datekit",47 requestId: "push-1",48 },3 unmodified lines52 })53 );54 55 it.effect(56- "writes each level through its own console method, so Issues hears what is logged at Error",56+ "writes each level through its own console method and names it as Workers Logs does, so Issues and a query of level = 'error' hear what is logged at Error",57 () =>58 Effect.gen(function* () {59 const written = yield* logged(60 Effect.all([61 Effect.logWarning("held"),62 Effect.logError("broke", Cause.die(new Error("the store is gone"))),63+ Effect.logFatal("gone"),64 ])65 );66 66- expect(written.map(({ method }) => method)).toStrictEqual([67- "warn",68- "error",67+ expect(written).toMatchObject([68+ { line: { level: "warn" }, method: "warn" },69+ { line: { level: "error" }, method: "error" },70+ { line: { level: "error" }, method: "error" },71 ]);72 expect(written[1]?.line).toMatchObject({71- level: "ERROR",73+ level: "error",74 message: "broke",75 });76 expect(written[1]?.line).toHaveProperty(77 "cause",12 unmodified lines90 )91 );92 93 expect(written[0]?.line).toStrictEqual({92- level: "INFO",94+ level: "info",95 message: "kept",96 });97 })98 );30 unmodified lines