Skip to content

Conversation

@devin-ai-integration
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Oct 30, 2025

Backport of #11135 to v3-maintenance branch.

This PR implements tail-based logging for wrangler dev --remote sessions behind the --x-tail-logs experimental flag. Instead of using the Chrome DevTools Protocol inspector for logs, this creates a tail consumer WebSocket connection to receive runtime logs, similar to wrangler tail.

Changes Overview

Core tail logging implementation:

  • Added --experimental-tail-logs (alias --x-tail-logs) flag to wrangler dev
  • Modified createPreviewSession() to conditionally skip inspector URL creation when tail logs are enabled
  • Made inspectorUrl optional in CfPreviewToken and CfPreviewSession types
  • Added tailUrl to preview token response
  • Implemented tail-based log streaming in RemoteRuntimeController using WebSocket
  • Added simplified realishPrintLogs() for printing tail messages (compared to the full prettyPrintLogs() used in wrangler tail)
  • Disabled devtools hotkey when tail logs are enabled

v3-maintenance compatibility fixes:

  • Added tailConsumers: TailConsumer[] property to StartDevWorkerOptions type
  • Made userWorkerInspectorUrl optional in ProxyData type
  • Fixed inspector type checks (v3 doesn't support inspector: false string value, only boolean or object)
  • Added REALISH_TAIL_LOGS to experimental flags in all 7 command initialization points
  • Updated test configuration helpers to include tailConsumers: []
  • Fixed optional inspector URL handling in tests using assert() instead of non-null assertion
  • Added CLOUDFLARE_ACCOUNT_ID global type declaration for e2e tests

Test modifications:

  • Relaxed error message expectations in e2e tests (looking for "monkey" instead of full error details with stack traces, since tail logs don't include source maps)
  • Skipped inspector test for remote runtime (inspector not available when using tail logs)
  • Added workaround comment for EWC bug requiring bindings for remote dev workers to log properly

Human Review Checklist

Critical items:

  1. 🚨 Runtime testing required: This PR was validated with pnpm check and pnpm fix but was NOT runtime tested with actual wrangler dev --remote --x-tail-logs. This should be tested in a real v3 environment before merging to verify:

    • Tail logs are received and printed correctly
    • No inspector errors when inspector is disabled
    • Proper fallback when tail URL is not available
    • WebSocket cleanup on errors and teardown
  2. Optional inspector URL: Verify that making inspectorUrl optional doesn't break existing code paths:

    • ProxyController event emission handles undefined inspector URL correctly
    • Devtools hotkey is properly disabled when tail logs are enabled (line in hotkeys.ts)
    • Tests properly handle undefined inspector URLs with assert() statements
  3. Type compatibility changes: Review the TypeScript fixes made for v3-maintenance:

    • Is keeping switchedExchangeUrl as URL object (instead of string) correct for v3?
    • Are the inspector type check changes (typeof config.inspector !== "object") safe for all v3 code paths?
    • Does v3 actually not support inspector: false string value?
  4. WebSocket lifecycle: Verify the tail WebSocket is properly cleaned up:

    • this.#activeTail?.terminate() is called in teardown and before creating new preview
    • Abort signal is passed to WebSocket constructor
    • Error handling for WebSocket connection failures
  5. Experimental flags coverage: Verify all 7 locations where experimental flags are initialized include REALISH_TAIL_LOGS: false:

    • ✅ core/register-yargs-command.ts
    • ✅ deploy/index.ts
    • ✅ dev.ts
    • ✅ pages/dev.ts
    • ✅ versions/upload.ts
    • ✅ api/integrations/platform/index.ts
    • ✅ configuration.test.ts (3 locations)
  6. Test expectation changes: The e2e tests now only check for "monkey" in error messages instead of full error details with stack traces. Is this acceptable for tail-based logs? Should we document this limitation?

  7. CI expectation: The "v3 Maintenance / Is original PR merged" CI check will fail until PR Implement tail-based logging for realish preview #11135 is merged to main. This is expected and should be ignored until the original PR merges.


Link to Devin run: https://app.devin.ai/sessions/de6e732841fc4f8ab637b03d5efd847e

Requested by: smacleod@cloudflare.com

penalosa and others added 6 commits October 30, 2025 16:18
Co-Authored-By: smacleod@cloudflare.com <smacleod@cloudflare.com>
- Add tailConsumers property to StartDevWorkerOptions type
- Make userWorkerInspectorUrl optional in ProxyData type
- Fix inspector type check (v3 doesn't support inspector: false)
- Remove minimal_mode flag (v3 only has boolean remote)
- Fix switchedExchangeUrl type (keep as URL object)
- Add tailConsumers to test config defaults
- Add REALISH_TAIL_LOGS to experimental flags in tests
- Add CLOUDFLARE_ACCOUNT_ID global type declaration

Co-Authored-By: smacleod@cloudflare.com <smacleod@cloudflare.com>
@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@changeset-bot
Copy link

changeset-bot bot commented Oct 30, 2025

🦋 Changeset detected

Latest commit: 4ae576a

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

This PR includes changesets to release 1 package
Name Type
wrangler 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-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Oct 30, 2025
@devin-ai-integration devin-ai-integration bot added the v3-backport The PR is a v3 backport targetting the v3-maintenance branch label Oct 30, 2025
@workers-devprod workers-devprod added e2e Run wrangler + vite-plugin e2e tests on a PR c3-e2e Run c3 e2e tests on a PR labels Oct 30, 2025
devin-ai-integration bot and others added 4 commits October 30, 2025 17:01
Co-Authored-By: smacleod@cloudflare.com <smacleod@cloudflare.com>
Co-Authored-By: smacleod@cloudflare.com <smacleod@cloudflare.com>
This backports the core tail-based logging functionality from PR #11135 to the
v3-maintenance branch. Due to significant divergence between main and v3-maintenance
(11 merge conflicts), this is a manual port focusing on the essential changes:

- Add realishPrintLogs function to tail/printing.ts for simplified log output
- Update create-worker-preview.ts to handle tailUrl in CfPreviewToken
- Update RemoteRuntimeController.ts to create WebSocket tail connections
- Export TRACE_VERSION from createTail.ts for reuse
- Add WRANGLER_TAIL_LOGS environment variable to turbo.json

The tail-based logging is opt-in via WRANGLER_TAIL_LOGS=1 environment variable
or automatically used when the inspector is unavailable.

Backport of: #11135

Co-Authored-By: smacleod@cloudflare.com <smacleod@cloudflare.com>
…ort-11135

Resolved merge conflicts by keeping the type-safe fixes:
- Keep type cast for logger.console level parameter in printing.ts
- Keep optional tail_url type in create-worker-preview.ts
- Keep WebSocket import and extracted proxyData variable in RemoteRuntimeController.ts

Co-Authored-By: smacleod@cloudflare.com <smacleod@cloudflare.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c3-e2e Run c3 e2e tests on a PR e2e Run wrangler + vite-plugin e2e tests on a PR v3-backport The PR is a v3 backport targetting the v3-maintenance branch

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

2 participants