Skip to content

presets(cloudflare): bridge tracing channel events to observability custom spans#4413

Open
RihanArfan wants to merge 8 commits into
mainfrom
cloudflare-tracingchannel
Open

presets(cloudflare): bridge tracing channel events to observability custom spans#4413
RihanArfan wants to merge 8 commits into
mainfrom
cloudflare-tracingchannel

Conversation

@RihanArfan

Copy link
Copy Markdown
Member

🔗 Linked issue

#4355

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

Porting #4355 to Cloudflare to support Nitro tracing on more platforms.

Bridge tracing channel messages to Cloudflare Workers Observability as custom spans.

image

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@RihanArfan RihanArfan requested a review from pi0 as a code owner July 9, 2026 14:00
@vercel

vercel Bot commented Jul 9, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
nitro.build Ready Ready Preview, Comment Jul 14, 2026 10:19am

Request Review

@pkg-pr-new

pkg-pr-new Bot commented Jul 9, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/nitro@4413

commit: 92b63c9

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds experimental tracing-channel support for Cloudflare presets. It extends traced-channel completion handling, installs a Cloudflare telemetry bridge, emits custom spans with attributes and exceptions, adds comprehensive unit tests, and documents the required Wrangler observability configuration.

Changes

Tracing channel telemetry integration

Layer / File(s) Summary
Traced-channel completion contracts
src/runtime/internal/telemetry/subscribe.ts
Adds generic per-span state, start hooks, start-time information fallback, synchronous error completion, and sink error isolation.
Cloudflare preset bridge wiring
src/presets/cloudflare/preset.ts
Conditionally prepends the telemetry plugin for Miniflare development and Cloudflare module builds when tracingChannel is configured.
Cloudflare custom span lifecycle
src/presets/cloudflare/runtime/telemetry/plugin.ts
Bridges traced operations to Cloudflare custom spans, converts OTLP attributes, records exceptions, and closes spans reliably.
Tracing validation and documentation
test/unit/telemetry-subscribe.test.ts, test/unit/cloudflare-telemetry.test.ts, docs/2.deploy/20.providers/cloudflare.md
Tests lifecycle, completion, naming, attributes, malformed payloads, and subscription behavior; documents experimental configuration and Wrangler trace recording.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • nitrojs/nitro#4338: Changes the Cloudflare development runner setup used by the tracing bridge condition.
  • nitrojs/nitro#4406: Provides a related traced-channel consumer and depends on the shared subscription API changes.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title follows conventional commit structure and clearly matches the Cloudflare tracing bridge change.
Description check ✅ Passed The description is directly related to the Cloudflare tracing and custom span changes in this PR.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cloudflare-tracingchannel

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment thread src/presets/cloudflare/runtime/telemetry/plugin.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/presets/cloudflare/runtime/telemetry/plugin.ts`:
- Around line 31-35: In the attribute loop within the telemetry plugin, handle
`attributeValue(value)` results before calling `entry.span.setAttribute`: skip
entries whose converted value is `undefined`, while preserving valid primitive
or array values.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a6b844e5-5673-4a74-a6b0-9ceb174e1d33

📥 Commits

Reviewing files that changed from the base of the PR and between 1f01479 and 0668713.

📒 Files selected for processing (6)
  • src/presets/cloudflare/runtime/telemetry/plugin.ts
  • src/presets/vercel/runtime/telemetry/plugin.ts
  • src/runtime/internal/telemetry/logger-plugin.ts
  • src/runtime/internal/telemetry/subscribe.ts
  • test/unit/cloudflare-telemetry.test.ts
  • test/unit/telemetry-subscribe.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/unit/cloudflare-telemetry.test.ts

Comment thread src/presets/cloudflare/runtime/telemetry/plugin.ts Outdated
export default definePlugin(() => {
subscribeTracedChannels((info, startTimeUnixNano, error) => {
// Describer failed on the completed payload — nothing to report.
if (!info) return;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like a bug. Why are we even calling callback in this case?

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/runtime/internal/telemetry/subscribe.ts (1)

69-75: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Log warnings for recoverable telemetry failures.

While catching exceptions here correctly prevents telemetry sink failures from crashing the traced application, swallowing them silently prevents visibility into malformed payloads or broken span exports. Please add console.warn to these catch blocks to provide actionable context.

  • src/runtime/internal/telemetry/subscribe.ts#L69-L75: Add console.warn inside the catch block to log onStart or initial describe failures.
  • src/runtime/internal/telemetry/subscribe.ts#L91-L93: Add console.warn inside the catch block to log completion describe failures.
  • src/runtime/internal/telemetry/subscribe.ts#L97-L101: Add console.warn inside the catch block to log onSpan sink export failures.

As per coding guidelines, "Prefer explicit errors over silent failures; use warnings for recoverable situations" and "Use console only for logging in src/runtime/ code; never use consola."

🛡️ Proposed fixes for explicit error logging
@@ -69,7 +69,8 @@
         try {
           entry.info = describe(name, message);
           entry.state = onStart(entry.info);
-        } catch {
+        } catch (error) {
           // Malformed payload, or a sink failure (e.g. the platform refused to
           // open a span) — no state; the completion callback still fires.
+          console.warn(`[nitro] Failed to start span for channel ${name}:`, error);
         }
@@ -91,3 +92,5 @@
       try {
         info = describe(name, message);
-      } catch {}
+      } catch (error) {
+        console.warn(`[nitro] Failed to describe completed span for channel ${name}:`, error);
+      }
@@ -97,4 +100,5 @@
       try {
         onSpan(info, entry.start, (message as { error?: unknown }).error, entry.state);
-      } catch {
+      } catch (error) {
         // A sink failure must never break the traced operation.
+        console.warn(`[nitro] Failed to export span for channel ${name}:`, error);
       }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/runtime/internal/telemetry/subscribe.ts` around lines 69 - 75, Make the
three exception handlers in src/runtime/internal/telemetry/subscribe.ts—covering
initial describe/onStart, completion describe, and onSpan export—emit
console.warn with actionable failure context while preserving their existing
recovery behavior; use console only and do not rethrow or replace the catches.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/runtime/internal/telemetry/subscribe.ts`:
- Around line 69-75: Make the three exception handlers in
src/runtime/internal/telemetry/subscribe.ts—covering initial describe/onStart,
completion describe, and onSpan export—emit console.warn with actionable failure
context while preserving their existing recovery behavior; use console only and
do not rethrow or replace the catches.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b5bfa969-a7b2-4b4d-a9e9-d400195ea65c

📥 Commits

Reviewing files that changed from the base of the PR and between 0668713 and 92b63c9.

📒 Files selected for processing (4)
  • src/presets/cloudflare/runtime/telemetry/plugin.ts
  • src/runtime/internal/telemetry/subscribe.ts
  • test/unit/cloudflare-telemetry.test.ts
  • test/unit/telemetry-subscribe.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/presets/cloudflare/runtime/telemetry/plugin.ts
  • test/unit/cloudflare-telemetry.test.ts

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.

2 participants