Skip to content

feat(open-next): create cloudflare-sentry-tail package#8842

Open
flakey5 wants to merge 2 commits intomainfrom
flakey5/20260424/tail-worker
Open

feat(open-next): create cloudflare-sentry-tail package#8842
flakey5 wants to merge 2 commits intomainfrom
flakey5/20260424/tail-worker

Conversation

@flakey5
Copy link
Copy Markdown
Member

@flakey5 flakey5 commented Apr 25, 2026

Creates a cloudflare-sentry-tail package that enables us to add a tail worker to the open next deployment of the site.

This package should be publishable as well so that we can reuse it in the release worker.

Description

Validation

Related Issues

Check List

  • I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • I have run pnpm format to ensure the code follows the style guide.
  • I have run pnpm test to check if all tests are passing.
  • I have run pnpm build to check if the website builds without errors.
  • I've covered new added functionality with unit tests if necessary.

Creates a `cloudflare-sentry-tail` package that enables us to add a tail worker
to the open next deployment of the site.

This package should be publishable as well so that we can reuse it in the
release worker.

Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com>
@flakey5 flakey5 requested review from a team as code owners April 25, 2026 01:17
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 25, 2026

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

Project Deployment Actions Updated (UTC)
nodejs-org Ready Ready Preview Apr 25, 2026 2:14am

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 25, 2026

PR Summary

Medium Risk
Adds new production error/trace reporting via a Cloudflare Tail handler, which can impact observability data volume, privacy (headers/logs), and runtime overhead if misconfigured.

Overview
Adds a new publishable package @node-core/cloudflare-sentry-tail that converts Cloudflare Workers Tail TraceItems into Sentry events (including request context, console logs, diagnostics channel events, and exceptions) with configurable sampling and header redaction.

Integrates this tail handler into the site’s Cloudflare worker-entrypoint.ts via withSentry tail, and wires the new workspace dependency/ownership into apps/site/package.json, .github/CODEOWNERS, and pnpm-lock.yaml.

Reviewed by Cursor Bugbot for commit c0468e2. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions
Copy link
Copy Markdown
Contributor

👋 Codeowner Review Request

The following codeowners have been identified for the changed files:

Team reviewers: @nodejs/web-infra @nodejs/nodejs-website

Please review the changes when you have a chance. Thank you! 🙏

const buffer = new Uint32Array(1);
crypto.getRandomValues(buffer);

const random = buffer[0] / 4294967295;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

idk where this number comes from but it works so 🤷

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.

4294967295 is the maximum value that an element in an Unit32Array could have:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#typedarray_objects

maybe we can add a constant here instead of this magic number?

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.

Also, let's be a bit more apparent in where it comes from:

const UINT_32_LIMIT = 2 ** 32

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.82%. Comparing base (97e28c5) to head (c0468e2).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8842      +/-   ##
==========================================
- Coverage   73.87%   73.82%   -0.05%     
==========================================
  Files         105      105              
  Lines        8883     8883              
  Branches      326      327       +1     
==========================================
- Hits         6562     6558       -4     
- Misses       2320     2324       +4     
  Partials        1        1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment thread packages/cloudflare-sentry-tail/src/index.ts
Comment thread packages/cloudflare-sentry-tail/src/index.ts
Comment thread packages/cloudflare-sentry-tail/src/index.ts Outdated
Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com>
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c0468e2. Configure here.

@@ -0,0 +1,3 @@
{
"**/*.{ts}": ["prettier --check --write", "eslint --fix"]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Single-item brace glob fails to match TypeScript files

Medium Severity

The glob pattern **/*.{ts} uses a single-item brace expression, which micromatch (used by both lint-staged and turbo) does not expand — it is treated as a literal string. As a result, lint-staged will not run prettier/eslint on .ts files in this package, and turbo will not track .ts files as inputs for the lint:js task, silently breaking cache invalidation. The correct form requires multiple items, e.g. **/*.ts or **/*.{ts,tsx}, as used in sibling packages.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c0468e2. Configure here.

tlsExportedAuthenticator: request.cf?.tlsExportedAuthenticator,
tlsVersion: request.cf?.tlsVersion,
},
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tail worker sends PII headers and geo data to Sentry

High Severity

The tail handler copies all request headers (only authorization and cookie are redacted) plus request.cf fields such as asn, colo, country, timezone, etc. into the Sentry event. Headers like user-agent, cf-connecting-ip, x-forwarded-for, and x-real-ip expose client IPs and fingerprinting data, which is exactly the PII that the project's Sentry policy forbids forwarding (the reason sendDefaultPii: true is disallowed). Redacting only auth/cookie does not address the IP and user-agent exposure.

Additional Locations (1)
Fix in Cursor Fix in Web

Triggered by learned rule: Sentry configuration rules for Cloudflare Workers

Reviewed by Cursor Bugbot for commit c0468e2. Configure here.

"lint:fix": "node --run lint:js:fix",
"lint:js": "eslint \"**/*.ts\"",
"lint:js:fix": "node --run lint:js -- --fix"
},
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

New package lacks lint:types script, skips type checking

Medium Severity

The new package registers a lint:types task in turbo.json but provides no corresponding lint:types script in package.json, so turbo lint:types (invoked in CI and the husky pre-commit hook) silently does nothing for this package. Combined with apps/site/tsconfig.json excluding cloudflare/worker-entrypoint.ts from type checking, neither the new 300+ line tail worker source nor its consumer is type-checked anywhere, letting type errors reach production undetected.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c0468e2. Configure here.

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.

this issue seems legit 🤔

"lint:fix": "node --run lint:js:fix",
"lint:js": "eslint \"**/*.ts\"",
"lint:js:fix": "node --run lint:js -- --fix"
},
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.

this issue seems legit 🤔

const buffer = new Uint32Array(1);
crypto.getRandomValues(buffer);

const random = buffer[0] / 4294967295;
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.

4294967295 is the maximum value that an element in an Unit32Array could have:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#typedarray_objects

maybe we can add a constant here instead of this magic number?

Comment on lines +203 to +207
// Allocate space for the elements we're gonna add
sentryEvent.breadcrumbs.length +=
item.logs.length +
item.diagnosticsChannelEvents.length +
item.exceptions.length;
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.

Arrays in JavaScript automatically expand as you add elements to them, see:
example of adding elements to an incrementing index in javascript

So I don't think we need to allocate memory for the new elements here 🤔

Comment on lines +232 to +233
sentryEvent.fingerprint!.length += item.exceptions.length;
sentryEvent.exception!.values!.length += item.exceptions.length;
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.

Like my other comment, I don't think that any "allocation" is needed for the arrays

@@ -0,0 +1,31 @@
{
"name": "@node-core/cloudflare-sentry-tail",
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.

Can you open an issue in admin for this package?

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.

3 participants