Skip to content

feat: add observability live tail - #578

Merged
repository merged 2 commits into
cloudflare:mainfrom
repository:lngo/o11y-live-tail
Nov 16, 2026
Merged

repository merged 2 commits into
cloudflare:mainfrom
repository:lngo/o11y-live-tail

Conversation

@repository

Copy link
Copy Markdown
Member

Add cf observability tail to stream live observability events as newline-delimited JSON. Stream all events, select a Worker or zone, and narrow results with JSON filters supplied inline or from a file.

# Stream all observability events.
cf observability tail --all

# Stream events from one Worker.
cf observability tail --worker my-worker

# Stream events for a zone and its subdomains.
cf observability tail --zone example.com

# Show errors using an inline JSON filter.
cf observability tail --filters '{"filterCombination":"and","filters":[{"key":"$metadata.level","type":"string","operation":"eq","value":"error"}]}'

# Apply saved filters to one Worker.
cf observability tail --worker my-worker --filters @filters.json

# Preview the filtered request for a zone.
cf observability tail --zone example.com --filters @filters.json --dry-run

For example, save this as filters.json to select GET requests where CPU time exceeds 50 ms or the response status is 500 or higher:

{
  "filterCombination": "and",
  "filters": [
    {
      "key": "$metadata.trigger",
      "type": "string",
      "operation": "starts_with",
      "value": "GET "
    },
    {
      "kind": "group",
      "filterCombination": "or",
      "filters": [
        {
          "key": "$workers.cpuTimeMs",
          "type": "number",
          "operation": "gt",
          "value": 50
        },
        {
          "key": "$workers.event.response.status",
          "type": "number",
          "operation": "gte",
          "value": 500
        }
      ]
    }
  ]
}

Validation: pnpm check, focused live tail and command metadata tests, and built CLI dry-run examples pass.

Resolves #68

Tracking WO-2120

@repository
repository requested a review from a team as a code owner November 11, 2026 09:13
@pkg-pr-new

pkg-pr-new Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
npm i https://pkg.pr.new/cf@578

commit: 97f92d4

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of a26381a7.

This review, of c2a63e10

💬 Approved with comments — No blocking issues or warnings. There are two small notes: the idle notice text is hardcoded, and a metadata test is now weaker.

Findings: 1 info · 1 suggestion (2 are inline comments on the diff)

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


📋 Code Quality: 💬 1 info · 1 suggestion

Two minor notes: the idle notice text is hardcoded, and a metadata test now checks its data against itself.

Recommendation: 💬 Optional Nits

  • [INFO] The metadata test now builds its expected command list from the same sidecar data it checks. (packages/cli/src/__tests__/commands/hand-written-metadata.test.ts:235)
  • [SUGGESTION] The idle notice hardcodes "30 seconds" while the timer uses idleTimeoutMs. (packages/cli/src/commands/observability/tail/stream.ts:135)
View full review

The streaming logic looks correct: reconnect, heartbeat, EPIPE and output drain, and signal-listener cleanup. Two small points:

  • stream.ts:135: the idle notice always says "30 seconds", but the timer fires after idleTimeoutMs.
  • hand-written-metadata.test.ts:226-238: the expected command list now comes from the same sidecar data the test checks.

✅ All other checks passed

🚀 Release: ✅ LGTM

Low risk. The changeset is present for a new user-facing command.


🔒 Security: ✅ LGTM

The live tail URL must use wss: and never appears in error messages. User filters go only in the JSON request body. --zone is checked as a valid domain name in dry-run mode and looked up through the zone API otherwise. The PEM key under __tests__/fixtures is a test-only fixture.


📖 AGENTS.md: ✅ LGTM

Follows the repository conventions: the command is registered in hand-written.ts, the meta.ts sidecar is in sync, and a changeset is included.


⚡ Performance: ✅ LGTM

No performance concerns.


📝 Documentation: ✅ LGTM

No documentation issues.


Reviewed commit: c2a63e10

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of b370af07.

This review, of a26381a7

✅ Approved — Both earlier notes are fixed and no new issues were found.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🚀 Release: ✅ LGTM

Low risk. A changeset is included for the new user-facing command.


🔒 Security: ✅ LGTM

The live tail URL must use wss: and never appears in error messages. User filters go only in the JSON request body. --zone is checked as a valid domain name in dry-run mode and looked up through the zone API otherwise. The PEM key under __tests__/fixtures is a test-only fixture.


📖 AGENTS.md: ✅ LGTM

Follows the repository conventions: the command is registered in hand-written.ts, the meta.ts sidecar is in sync, and a changeset is included.


📋 Code Quality: ✅ LGTM

Both earlier notes are fixed:

  • Idle notice: stream.ts now builds the message from idleTimeoutMs / 1000, and a test covers the wording.
  • Metadata test: hand-written-metadata.test.ts now uses a literal command count and an explicit cf observability tail entry, so it no longer builds its expected list from the data it checks.

The reconnect, heartbeat, abort and output-drain paths are consistent. The command registration follows the repository conventions.


⚡ Performance: ✅ LGTM

Incoming messages and pending stdout writes are each capped at 16 MiB. Timers, sockets and listeners are cleaned up in finally blocks. Reconnect attempts follow a fixed backoff list.


📝 Documentation: ✅ LGTM

No documentation issues.


Reviewed commit: a26381a7

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 04b0637c.

This review, of b370af07

✅ Approved — The only change since the last approved review is to a test file, and it matches the implementation. No issues were found.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🚀 Release: ✅ LGTM

Risk: Low. A changeset is included for the new command.


🔒 Security: ✅ LGTM

The tests use local loopback servers and a test-only TLS key pair. The throwaway certificate is trusted only inside the test process, and the original CA list is restored afterwards. In stream.ts, the live tail URL must use wss: and never appears in error messages. Proxy credentials are not logged.


📖 AGENTS.md: ✅ LGTM

Follows the repository conventions: the command is registered in hand-written.ts, its meta.ts sidecar is in sync with hand-written-meta.ts, and a changeset is included.


📋 Code Quality: ✅ LGTM

The stream test's fixtures and assertions match the implementation:

  • Idle notice: the expected wording is built from idleTimeoutMs / 1000.
  • Heartbeat counts: the expected counts follow from the rule that three failures in a row end a session.
  • Normal close: a close with code 1000 stops retrying.
  • Output: the EPIPE, write-failure and drain-timeout paths, and the 16 MiB buffer cap, all match what tailOutput does.

The earlier notes are still fixed.


⚡ Performance: ✅ LGTM

  • Incoming messages are capped by maxPayload, and pending stdout writes are bounded.
  • Heartbeats never overlap.
  • Reconnects follow a fixed backoff list.
  • Timers, sockets, agents and listeners are cleaned up in finally blocks.

📝 Documentation: ✅ LGTM

No documentation issues.


Reviewed commit: b370af07

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of d729705d.

This review, of 04b0637c

💬 Approved with comments — One WARNING: with an OAuth login, a long-running tail never refreshes its access token, so it exits after the token expires. Nothing else was found.

Findings: 1 warning (1 is an inline comment on the diff)

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.

🔧 Fix with your agent

Paste the following into your coding agent to investigate and fix these issues.

Fix the following code review issues found in pull request #578.

Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
  for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order

## WARNING (1)

### [Code Quality] With an OAuth login, a long-running tail keeps the access token it started with. After the token expires, heartbeats and reconnects fail with 401 and the command exits.
- **File:** packages/cli/src/commands/observability/tail/command.ts:173

📋 Code Quality: ⚠️ 1 warning

A long-running tail keeps a stale OAuth access token and exits once that token expires.

Recommendation: 📝 Minor Comments

  • [WARNING] With an OAuth login, a long-running tail keeps the access token it started with. After the token expires, heartbeats and reconnects fail with 401 and the command exits. (packages/cli/src/commands/observability/tail/command.ts:173)
View full review

Stale OAuth token in long-running tail (packages/cli/src/commands/observability/tail/command.ts:173, stream.ts:296-336)

How the token goes stale:

  • resolveTailContext calls createCommandClient(argv) once.
  • That calls getAuthToken() once and passes the resulting string to createCloudflareClientWithToken.
  • The client's auth callback captures that string in a closure (lib/auth.ts:261-263), so it never reads the token again.
  • tailRequests reuses the same client for every prepareLiveTail call (initial connect and reconnects) and for every heartbeat.

What happens after an OAuth access token expires:

  • Heartbeats fail with 401.
  • After three failures in a row, the session ends.
  • Reconnects fail with 401 as well, and the command exits with an error.

Users who set CLOUDFLARE_API_TOKEN are not affected.

Fix: get credentials for each request while streaming. Either call getAuthToken() inside the auth callback, or rebuild the client in send. Add a test whose token changes between the connect and a later heartbeat.


✅ All other checks passed

🚀 Release: ✅ LGTM

Risk: Low. A minor changeset is included for the new command.


🔒 Security: ✅ LGTM

The test-only key pair is now documented by the fixtures README as being for local tests only. The live tail URL must use wss: and is kept out of error messages.


📖 AGENTS.md: ✅ LGTM

Follows the repository conventions: the command is registered in hand-written.ts, its meta.ts sidecar is in sync with hand-written-meta.ts, and a changeset is included.


⚡ Performance: ✅ LGTM

No performance issues.


📝 Documentation: ✅ LGTM

No documentation issues.


Reviewed commit: 04b0637c

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of af4386b8.

This review, of d729705d

💬 Approved with comments — One WARNING carried over: with an OAuth login, a long-running tail never refreshes its access token, so it exits after the token expires. Nothing else was found.

Findings: 1 warning

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.

🔧 Fix with your agent

Paste the following into your coding agent to investigate and fix these issues.

Fix the following code review issues found in pull request #578.

Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
  for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order

## WARNING (1)

### [Code Quality] With an OAuth login, a long-running tail keeps the access token it started with. After the token expires, heartbeats and reconnects fail with 401 and the command exits.
- **File:** packages/cli/src/commands/observability/tail/command.ts:173

📋 Code Quality: ⚠️ 1 warning

The stale OAuth token in a long-running tail is still not fixed.

Recommendation: 📝 Minor Comments

  • [WARNING] With an OAuth login, a long-running tail keeps the access token it started with. After the token expires, heartbeats and reconnects fail with 401 and the command exits. (packages/cli/src/commands/observability/tail/command.ts:173)
View full review

Stale OAuth token in long-running tail (packages/cli/src/commands/observability/tail/command.ts:173, stream.ts:299-344)

This is still not fixed at this commit:

  • resolveTailContext calls createCommandClient(argv) once.
  • That calls getAuthToken() once and puts the resulting string into the client's auth callback (lib/auth.ts:261-263), so the token is never looked up again.
  • tailRequests reuses that client for the first connect, every reconnect and every heartbeat.

What happens once an OAuth access token expires:

  • Heartbeats fail with 401, and three failures in a row end the session.
  • Reconnects also fail with 401, and the command exits with an error.

Users who set CLOUDFLARE_API_TOKEN are not affected.

Fix: get credentials for each request while streaming. Either call getAuthToken() inside the auth callback, or rebuild the client per request. Add a test where the token changes between the connect and a later heartbeat.


✅ All other checks passed

🚀 Release: ✅ LGTM

Risk: Low. A minor changeset is included for the new command.


🔒 Security: ✅ LGTM

  • The live tail URL must use wss: and is kept out of error messages.
  • The localhost key pair is a test fixture, and the fixtures README marks it as for local tests only.

📖 AGENTS.md: ✅ LGTM

Follows the repository conventions:

  • The command is registered in hand-written.ts.
  • Its meta.ts sidecar is in sync with hand-written-meta.ts.
  • A changeset is included.

⚡ Performance: ✅ LGTM

Output buffering and WebSocket payloads are capped at 16 MiB, reconnect backoff is bounded, and timers and signal handlers are cleaned up when a session ends.


📝 Documentation: ✅ LGTM

No documentation issues.


Reviewed commit: d729705d

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 6f7330fc.

This review, of af4386b8

✅ Approved — The earlier OAuth token-refresh warning is fixed and tested, and nothing new was found.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🚀 Release: ✅ LGTM

Risk: Low.

  • A minor changeset covers the new command.
  • A separate changeset covers the OAuth refresh fix.

🔒 Security: ✅ LGTM

  • The live tail URL must use wss: and is kept out of error messages.
  • Output is serialized with JSON.stringify, so events from the server cannot inject terminal escape sequences.
  • Message size and buffered output are capped.
  • The localhost key pair is a test fixture, and the fixtures README marks it as for local tests only.

📖 AGENTS.md: ✅ LGTM

Follows the repository conventions:

  • The command is registered in hand-written.ts.
  • Its meta.ts sidecar is in sync with hand-written-meta.ts.
  • Changesets are included.

📋 Code Quality: ✅ LGTM

The client now looks up the token on every request:

  • createCloudflareClientWithToken accepts apiToken as a string or an async function, and its auth callback awaits the function on each request.
  • createCommandClient passes getAuthToken, which refreshes an expired OAuth token. Heartbeats and reconnects in the tail therefore stay authenticated.
  • The extra await getAuthToken() before the client is built keeps the fail-fast check at startup.

The new test covers this.


⚡ Performance: ✅ LGTM

  • Output buffering and WebSocket payloads are capped at 16 MiB.
  • Reconnect backoff is bounded.
  • Timers and signal handlers are cleaned up when a session ends.
  • A token lookup on each request is negligible at one heartbeat every 30 s.

📝 Documentation: ✅ LGTM

No documentation issues.


Reviewed commit: af4386b8

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by the review of 97f92d45.

This review, of 6f7330fc

✅ Approved — The earlier OAuth token-refresh warning is fixed and tested, and nothing new was found.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🚀 Release: ✅ LGTM

Risk: Low.

  • A minor changeset covers the new command.
  • A separate changeset covers the OAuth refresh fix.

🔒 Security: ✅ LGTM

  • The live tail URL must use wss: and is kept out of error messages.
  • Output is serialized with JSON.stringify, so events from the server cannot inject terminal escape sequences.
  • Message size and buffered output are capped.
  • The localhost key pair is a test fixture, and the fixtures README marks it as for local tests only.

📖 AGENTS.md: ✅ LGTM

Follows the repository conventions:

  • The command is registered in hand-written.ts.
  • Its meta.ts sidecar is in sync with hand-written-meta.ts.
  • Changesets are included.

📋 Code Quality: ✅ LGTM

The client now looks up the token on every request:

  • createCloudflareClientWithToken accepts apiToken as a string or an async function, and its auth callback awaits the function on each request.
  • createCommandClient passes getAuthToken, which refreshes an expired OAuth token. Heartbeats and reconnects in the tail therefore stay authenticated.
  • The extra await getAuthToken() before the client is built keeps the fail-fast check at startup.

The new test covers this.


⚡ Performance: ✅ LGTM

  • Output buffering and WebSocket payloads are capped at 16 MiB.
  • Reconnect backoff is bounded.
  • Timers and signal handlers are cleaned up when a session ends.
  • A token lookup on each request is negligible at one heartbeat every 30 s.

📝 Documentation: ✅ LGTM

No documentation issues.


Reviewed commit: 6f7330fc — same changes as af4386b8, so this is that commit's review (no new review was run; line numbers are as of af4386b8)

@petebacondarwin petebacondarwin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code as it stands looks good to me.
Two product questions:

  • what are we doing about the o11y group of commands?
  • should there be some kind of output formatting options?

For the second question the current output is very verbose and full of json fields that most people are not interested in. At the very least we should have a recipe for how to select what fields are rendered from each log line.

@repository

Copy link
Copy Markdown
Member Author

My thinking is that if cf is intended primarily for agents to use, they will use it in combination with jq or other tools to reduce the output volume. We can add a seperate flag to filter attributes down, but I wasn't sure if it was in the spirit of cf.

I plan to add the necessary attributes to make the other commands stop being generated

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approved — No issues found. The only changes since the last approved review are exact-pinned ws/@types/ws dev dependencies with matching lockfile entries.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🚀 Release: ✅ LGTM

Risk: Medium. The pull request adds a new streaming command and changes how OAuth credentials are looked up between requests.

  • A minor changeset covers the new command.
  • A patch changeset covers the OAuth refresh fix.

🔒 Security: ✅ LGTM

  • The new dependencies are pinned, and their lockfile entries carry integrity hashes.
  • The tail accepts only wss: URLs and keeps the URL out of error messages.
  • WebSocket payloads are capped at 16 MiB.
  • The localhost key pair is a test-only fixture, and the fixtures README says so.

📖 AGENTS.md: ✅ LGTM

Follows the repository conventions:

  • The command is registered in hand-written.ts.
  • Its meta.ts sidecar is in sync with hand-written-meta.ts.
  • Changesets are included.

📋 Code Quality: ✅ LGTM

  • ws and @types/ws are exact-pinned devDependencies, which matches the neighbouring entries that are bundled at build time.
  • The lockfile entries match package.json.
  • The OAuth per-request token lookup is still in place.

⚡ Performance: ✅ LGTM

  • Buffered output and WebSocket payloads are capped.
  • Reconnect backoff is bounded.
  • Timers and signal handlers are cleaned up when a session ends.
  • The per-request token lookup costs little at one heartbeat every 30 s.

📝 Documentation: ✅ LGTM

No documentation issues.


Reviewed commit: 97f92d45

@repository
repository added this pull request to the merge queue Nov 16, 2026
Merged via the queue into cloudflare:main with commit 5c2f6cc Nov 16, 2026
9 checks passed
@repository
repository deleted the lngo/o11y-live-tail branch November 16, 2026 18:02
MattieTK added a commit to cloudflare/cloudflare-docs that referenced this pull request Nov 17, 2026
rc.1 adds cf observability tail (cloudflare/cf#578), refreshes expired OAuth
logins during long-running commands, and renames a few generated commands
without aliases. Map wrangler tail to the new command in the Wrangler
reference.
KastanDay pushed a commit to KastanDay/cloudflare-docs that referenced this pull request Nov 17, 2026
…e#35288)

* [cf] Announce the Cloudflare CLI 1.0 release candidate

Add a changelog entry for the first cf 1.0 release candidate. It sets out
what is stable, what changes for projects upgrading from a beta, and what
improved during the beta.

* [cf] Update docs for the 1.0 release candidate

Align the cf docs with the release candidate: Build Output v1, the Vite
plugin 2.0 RC and Wrangler 4.163.0 minimums, new Node.js requirements,
argument forwarding in cf dev, project-local --local state, account
selection without a saved cache, non-zero exits for aborted destructive
commands, new deploy options, Workers Builds variables, and the files
cf init creates. Also correct which .env files cf reads.

* [cf] Remove single secrets from the list of Wrangler-only tasks

cf sets a single Worker secret with cf workers secrets update, so the
Wrangler pages no longer send readers to wrangler secret put.

* [cf] Announce cf support in Workers Builds

Workers Builds now sets up cf build and cf deploy when a connected Worker's
project has a cloudflare.config.ts file.

* [cf] Remove Workers Builds references until cf support is live

Workers Builds does not run cf yet, so drop the changelog section and
bullet, the Workers Builds section in the CI page, and the CI variables
that pointed to it.

* [cf] Address review feedback on the release candidate docs

Describe Node.js support as the latest LTS and active releases, and say
which Vite plugin and Wrangler releases cf supports rather than which it
rejects. Suggest named profiles for using one account across projects,
state that cf build runs the framework's own build command, drop the
credentials note from the previews dry run, and show the --persist-to
value on the Flagship page.

* [cf] Remove Wrangler tail references and date the changelog 17 November

cf observability tail ships in the next release candidate, so the Wrangler
pages no longer send readers to wrangler tail. Move the changelog to the
release date.

* [cf] Rename the beta note partial to release-candidate-note

The note now describes the release candidate, so name the file to match.

* [cf] Clarify account selection in the CI variables table

Say that cf prompts for an account when the token can access more than
one.

* [cf] Document which env files cf dev reads for Worker variables

The Vite plugin reads the .env and .dev.vars files, including the files
for the selected mode. Wrangler reads .dev.vars and falls back to the .env
files only when no .dev.vars file exists. The CI page now also names the
mode-specific files that cf reads for its own credentials.

* [cf] Note the Vite plugin release candidate and drop the duplicate --local bullet

* [cf] Announce the changelog with 1.0.0-rc.1 and cf observability tail

rc.1 adds cf observability tail (cloudflare/cf#578), refreshes expired OAuth
logins during long-running commands, and renames a few generated commands
without aliases. Map wrangler tail to the new command in the Wrangler
reference.
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.

cf workers tail: no replacement for wrangler tail

3 participants