Skip to content

Structured logger metadata + fold in replay-timeout logging#1832

Closed
pranaygp wants to merge 2 commits into
pranaygp/friendlier-errors-phase-1from
pranaygp/friendlier-errors-phase-3-logger
Closed

Structured logger metadata + fold in replay-timeout logging#1832
pranaygp wants to merge 2 commits into
pranaygp/friendlier-errors-phase-1from
pranaygp/friendlier-errors-phase-3-logger

Conversation

@pranaygp
Copy link
Copy Markdown
Contributor

@pranaygp pranaygp commented Apr 23, 2026

Summary

Phase 3 of the friendlier-errors stack. Also folds in #1812 so that PR can close as superseded.

  • Structured logger child API. runtimeLogger / stepLogger / webhookLogger etc. now expose .child(metadata) and .forRun(runId, workflowName, extra?), so runtime and step handlers don't have to repeat workflowRunId / workflowName / stepId on every log call.
  • Normalized error metadata. Ad-hoc error: err.message strings are replaced with structured errorName / errorMessage / errorStack fields so log drains can render and group them properly.
  • Comments on silent catches. The EntityConflictError / RunExpiredError paths that swallow expected idempotency conflicts now explain why it's safe to drop the error.

Folded in from #1812 (supersedes it)

  • Standardize the console prefix to [workflow-sdk].
  • Split replay-timeout into warn-while-retrying vs. error-when-giving-up, and surface the underlying error when we can't mark a timed-out run as failed.
  • Include error stacks in the "Fatal runtime error during workflow setup" log and the top-level user-code workflow error log so the stack surfaces in flattened drains.
  • Drop the [Workflows] "<runId>" - prefix from buildWorkflowSuspensionMessage — the structured logger attaches run context now.

Closes / supersedes: #1812

Manual test plan

All tests below use workbench/nextjs-turbopack. Start with cd workbench/nextjs-turbopack && pnpm dev and watch the terminal.

  • Console prefix — trigger any workflow. Every log line should begin with [workflow-sdk]. Search logs for \[Workflows\] — should be zero hits (the old prefix is gone).
  • Structured run/step context — inspect any step log line. It should carry runId, workflowName, stepId as structured metadata (the object after the message), not interpolated into the message string.
  • Error stacks in logs — deliberately throw from a step:
    async function brokenStep() { 'use step'; throw new Error('boom'); }
    Run the workflow. Confirm the full stack is the log message (survives flattened drains like Axiom/Datadog), not relegated to a structured field.
  • Structured error fields — at step-failure / run-failure, confirm errorName, errorMessage, and errorStack appear as structured metadata fields (in addition to the stack in the message).
  • Replay-timeout warn vs. error — set WORKFLOW_REPLAY_TIMEOUT_MS=50 in env and run a workflow with any non-trivial work. On early replay attempts expect a warn-level line ("replay timed out, retrying"); after retries exhaust expect an error-level line with the underlying failure cause visible.
  • Fatal setup error includes stack — if you can induce a fatal-at-setup (e.g. by crashing a worker init path), the "Fatal runtime error during workflow setup" log should include the full stack.
  • Suspension message has no legacy prefix — trigger a workflow that awaits a hook and suspends. The suspension log line should NOT start with [Workflows] "<runId>" - — only [workflow-sdk], with run context in structured metadata.
  • Idempotency conflicts are silently dropped — hard to induce deliberately; verify by reading the commented catches (EntityConflictError / RunExpiredError) around idempotent step-completion paths. No user-visible test.

Unit tests

  • New src/logger.test.ts covers .child, .forRun, metadata merging, and conflict precedence (10 tests).
  • Existing src/util.test.ts updated for new suspension-message format (23 tests pass).
  • pnpm typecheck reports no new errors.

📚 Friendlier errors stack

Multi-PR initiative inspired by @Schniz's stalled #706:

# PR Phase Summary
1 #1831 Phase 1 + 2 Ansi rendering primitives + context-violation errors
2 → this PR (#1832) Phase 3 Structured logger metadata; folds in #1812
3 #1836 Phase 4 SerializationError at serialization / stream / encryption boundaries
4 #1837 Phase 5 Presentation-only user vs SDK attribution (describeError)
5 #1838 Phase 6 Consistency pass on remaining bare throw new Error(...) sites
6 #1839 Phase 7 foundation Data-driven describeRunError + public subpath
7 #1840 Phase 8 WorkflowBuildError + applications in @workflow/builders
8 #1849 Followups Drop functionName leak, simplify docs framing, redirect stack to user code

Each PR is stacked on the previous one; merge in order.

🤖 Generated with Claude Code

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Apr 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
example-nextjs-workflow-turbopack Ready Ready Preview, Comment Apr 24, 2026 1:20am
example-nextjs-workflow-webpack Ready Ready Preview, Comment Apr 24, 2026 1:20am
example-workflow Ready Ready Preview, Comment Apr 24, 2026 1:20am
workbench-astro-workflow Ready Ready Preview, Comment Apr 24, 2026 1:20am
workbench-express-workflow Ready Ready Preview, Comment Apr 24, 2026 1:20am
workbench-fastify-workflow Ready Ready Preview, Comment Apr 24, 2026 1:20am
workbench-hono-workflow Ready Ready Preview, Comment Apr 24, 2026 1:20am
workbench-nitro-workflow Ready Ready Preview, Comment Apr 24, 2026 1:20am
workbench-nuxt-workflow Ready Ready Preview, Comment Apr 24, 2026 1:20am
workbench-sveltekit-workflow Ready Ready Preview, Comment Apr 24, 2026 1:20am
workbench-vite-workflow Ready Ready Preview, Comment Apr 24, 2026 1:20am
workflow-docs Ready Ready Preview, Comment, Open in v0 Apr 24, 2026 1:20am
workflow-swc-playground Ready Ready Preview, Comment Apr 24, 2026 1:20am
workflow-web Ready Ready Preview, Comment Apr 24, 2026 1:20am

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 23, 2026

🦋 Changeset detected

Latest commit: b2b1587

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 17 packages
Name Type
@workflow/core Patch
@workflow/builders Patch
@workflow/cli Patch
@workflow/next Patch
@workflow/nitro Patch
@workflow/vitest Patch
@workflow/web-shared Patch
@workflow/web Patch
workflow Patch
@workflow/world-testing Patch
@workflow/astro Patch
@workflow/nest Patch
@workflow/rollup Patch
@workflow/sveltekit Patch
@workflow/vite Patch
@workflow/nuxt Patch
@workflow/ai Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 23, 2026

🧪 E2E Test Results

Some tests failed

Summary

Passed Failed Skipped Total
❌ 💻 Local Development 1052 2 86 1140
✅ 📦 Local Production 1054 0 86 1140
❌ 🐘 Local Postgres 1052 2 86 1140
✅ 🪟 Windows 95 0 0 95
✅ 📋 Other 267 0 18 285
Total 3520 4 276 3800

❌ Failed Tests

💻 Local Development (2 failed)

vite-stable (2 failed):

  • error handling error propagation step errors basic step error preserves message and stack trace
  • error handling error propagation step errors cross-file step error preserves message and function names in stack
🐘 Local Postgres (2 failed)

nuxt-stable (2 failed):

  • fibonacciWorkflow - recursive workflow composition via start()
  • health check (queue-based) - workflow and step endpoints respond to health check messages

Details by Category

❌ 💻 Local Development
App Passed Failed Skipped
✅ astro-stable 89 0 6
✅ express-stable 89 0 6
✅ fastify-stable 89 0 6
✅ hono-stable 89 0 6
✅ nextjs-turbopack-canary 76 0 19
✅ nextjs-turbopack-stable 95 0 0
✅ nextjs-webpack-canary 76 0 19
✅ nextjs-webpack-stable 95 0 0
✅ nitro-stable 89 0 6
✅ nuxt-stable 89 0 6
✅ sveltekit-stable 89 0 6
❌ vite-stable 87 2 6
✅ 📦 Local Production
App Passed Failed Skipped
✅ astro-stable 89 0 6
✅ express-stable 89 0 6
✅ fastify-stable 89 0 6
✅ hono-stable 89 0 6
✅ nextjs-turbopack-canary 76 0 19
✅ nextjs-turbopack-stable 95 0 0
✅ nextjs-webpack-canary 76 0 19
✅ nextjs-webpack-stable 95 0 0
✅ nitro-stable 89 0 6
✅ nuxt-stable 89 0 6
✅ sveltekit-stable 89 0 6
✅ vite-stable 89 0 6
❌ 🐘 Local Postgres
App Passed Failed Skipped
✅ astro-stable 89 0 6
✅ express-stable 89 0 6
✅ fastify-stable 89 0 6
✅ hono-stable 89 0 6
✅ nextjs-turbopack-canary 76 0 19
✅ nextjs-turbopack-stable 95 0 0
✅ nextjs-webpack-canary 76 0 19
✅ nextjs-webpack-stable 95 0 0
✅ nitro-stable 89 0 6
❌ nuxt-stable 87 2 6
✅ sveltekit-stable 89 0 6
✅ vite-stable 89 0 6
✅ 🪟 Windows
App Passed Failed Skipped
✅ nextjs-turbopack 95 0 0
✅ 📋 Other
App Passed Failed Skipped
✅ e2e-local-dev-nest-stable 89 0 6
✅ e2e-local-postgres-nest-stable 89 0 6
✅ e2e-local-prod-nest-stable 89 0 6

📋 View full workflow run


Some E2E test jobs failed:

  • Vercel Prod: failure
  • Local Dev: failure
  • Local Prod: success
  • Local Postgres: failure
  • Windows: success

Check the workflow run for details.

@pranaygp
Copy link
Copy Markdown
Contributor Author

Phase 4 stacked on top of this: #1836SerializationError class + user-facing hints at serialization boundaries.

pranaygp and others added 2 commits April 23, 2026 18:14
Adds a `.child()` and `.forRun(runId, workflowName)` child-logger API to
the structured logger so runtime/step code doesn't have to repeat
`workflowRunId`/`workflowName`/`stepId` on every call. Normalizes error
metadata to structured `errorName` / `errorMessage` / `errorStack` fields
instead of ad-hoc `error: err.message` strings, and adds comments to
silent catches that swallow expected idempotency conflicts.

Also folds in the pending changes from #1812 so that PR can be closed:

- Standardize the console prefix to `[workflow-sdk]`.
- Split the replay-timeout log into a warn-while-retrying vs.
  error-when-giving-up, and surface the underlying error when we can't
  mark a timed-out run as failed.
- Include the error stack in the "Fatal runtime error during workflow
  setup" log and in the top-level user-code workflow error log so the
  stack surfaces in flattened log drains.
- Drop the `[Workflows] "<runId>" - ` prefix from
  `buildWorkflowSuspensionMessage` — the structured logger now attaches
  run context.

Supersedes #1812.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@pranaygp
Copy link
Copy Markdown
Contributor Author

Superseded by #1849 — consolidated friendlier-errors PR with all 8 phases + follow-up fixes (ANSI leak, non-retry semantics, shared captureStackTrace helper).

@pranaygp pranaygp closed this Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant