Skip to content

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

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

presets(cloudflare): bridge tracing channel events to observability custom spans#4413
RihanArfan wants to merge 7 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 10, 2026 4:34pm

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: 0668713

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds an experimental Cloudflare telemetry bridge connecting Nitro tracing-channel events to Cloudflare Workers custom spans. It updates shared subscription handling and existing consumers, wires the bridge into Cloudflare presets, adds tests, and documents the required configuration.

Changes

Tracing channel telemetry integration

Layer / File(s) Summary
Traced-channel completion contracts
src/runtime/internal/telemetry/subscribe.ts, src/runtime/internal/telemetry/logger-plugin.ts, src/presets/vercel/runtime/telemetry/plugin.ts
Adds stateful onStart support, missing-info handling, synchronous-error completion, and sink error isolation across telemetry consumers.
Cloudflare preset bridge wiring
src/presets/cloudflare/preset.ts
Conditionally prepends the Cloudflare telemetry plugin for Miniflare development and Cloudflare module builds when tracingChannel is configured.
Cloudflare custom span lifecycle
src/presets/cloudflare/runtime/telemetry/plugin.ts
Creates and closes Cloudflare custom spans, converts OTLP attributes, and records exception attributes from Nitro traced-channel events.
Tracing validation and documentation
test/unit/telemetry-subscribe.test.ts, test/unit/cloudflare-telemetry.test.ts, docs/2.deploy/20.providers/cloudflare.md
Tests subscription semantics, span lifecycle, naming, attributes, and malformed payloads, and documents the experimental configuration and Wrangler observability setting.

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

Possibly related PRs

  • nitrojs/nitro#4338: Changes the Cloudflare development preset’s Miniflare runner selection, which affects when the tracing bridge hook runs.
  • nitrojs/nitro#4406: Updates shared tracing internals and telemetry plugin paths used by this Cloudflare bridge.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title uses conventional-commit style and accurately describes the Cloudflare tracing bridge work.
Description check ✅ Passed The description is clearly related to the Cloudflare tracing and observability changes.
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
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?

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