feat: integrate Sentry Rollup plugin for source map uploads - #215
Conversation
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the ✨ Finishing touches🧪 Generate unit tests (beta)
Comment |
Co-authored-by: chrisdoc <9047291+chrisdoc@users.noreply.github.com>
There was a problem hiding this comment.
✨ PR Review
LGTM
Generated by LinearB AI and added by gitStream.
AI-generated content may contain inaccuracies. Please verify before using.
💡 Tip: You can customize your AI Review using Guidelines Learn how
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #215 +/- ##
=======================================
Coverage 65.60% 65.60%
=======================================
Files 13 13
Lines 407 407
Branches 127 127
=======================================
Hits 267 267
Misses 92 92
Partials 48 48 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
# [1.18.0](v1.17.3...v1.18.0) (2025-12-23) ### Features * integrate Sentry Rollup plugin for source map uploads ([#215](#215)) ([c1195c1](c1195c1))
There was a problem hiding this comment.
Main concern: Sentry uploads are not explicitly gated to “production” and can run in any environment where SENTRY_* variables are present, which risks accidental/undesired release creation and sourcemap uploads. Additionally, injecting Sentry secrets into the general CI build job broadens exposure and increases the chance of uploads from non-release builds. Documentation around token scopes should be verified against current Sentry Rollup plugin requirements to avoid setup failures.
Additional notes (1)
- Maintainability |
README.md:325-339
The README states the auth token needsproject:releasesscope. Sentry’s recommended scopes for sourcemap uploads commonly includeproject:releasesandorg:read(and sometimesproject:read). If the scope guidance is wrong/incomplete, setup will fail in a confusing way and the build will emit warnings.
At minimum, this should align with Sentry’s current docs (and preferably mention the exact scopes needed).
Summary of changes
What this PR changes
Build: Sentry source map upload
- Adds
@sentry/rollup-plugintotsdown.config.tsand wires it into thepluginsarray viasentryRollupPlugin({ ... }). - Configures plugin inputs from environment (
SENTRY_ORG,SENTRY_PROJECT,SENTRY_AUTH_TOKEN), disables plugin telemetry, uploads./dist/**/*.map, and sets the Sentryrelease.nameto the packageversion.
CI / workflows
- Passes Sentry secrets into the build step in:
.github/workflows/build-and-test.yml.github/workflows/release.yml
Docs & repo hygiene
- Documents Sentry env vars in
.env.sample. - Ignores
.env.sentry-build-pluginin.gitignore. - Adds README instructions for configuring Sentry secrets in GitHub Actions.
Dependencies
- Adds
@sentry/rollup-plugin@^4.6.1(and lockfile updates) to support the build integration.
| plugins: [ | ||
| sentryRollupPlugin({ | ||
| org: process.env.SENTRY_ORG, | ||
| project: process.env.SENTRY_PROJECT, | ||
| authToken: process.env.SENTRY_AUTH_TOKEN, | ||
| telemetry: false, | ||
| sourcemaps: { | ||
| assets: ["./dist/**/*.map"], | ||
| }, | ||
| release: { | ||
| name: version, | ||
| }, | ||
| }), | ||
| ], |
There was a problem hiding this comment.
sentryRollupPlugin(...) is always enabled, which means any environment that happens to have SENTRY_* variables set (including local dev or non-prod CI jobs) will attempt to create releases/upload sourcemaps. That can lead to accidental uploads from feature branches or PR builds, and it’s difficult to reason about when uploads should happen.
Given the PR intent (“during production builds”), this should be explicitly gated (e.g., CI && main branch, or a SENTRY_UPLOAD_SOURCEMAPS=true flag, or NODE_ENV=production).
Suggestion
Consider conditionally enabling the plugin and/or passing dryRun when not in a release build. For example:
const shouldUpload =
process.env.SENTRY_UPLOAD_SOURCEMAPS === "true" ||
(process.env.CI === "true" && process.env.GITHUB_REF === "refs/heads/main");
export default defineConfig({
// ...
plugins: shouldUpload
? [
sentryRollupPlugin({
org: process.env.SENTRY_ORG,
project: process.env.SENTRY_PROJECT,
authToken: process.env.SENTRY_AUTH_TOKEN,
telemetry: false,
sourcemaps: { assets: ["./dist/**/*.map"] },
release: { name: version },
}),
]
: [],
});This makes “production builds” explicit and prevents accidental uploads. Reply with "@CharlieHelps yes please" if you'd like me to add a commit with this suggestion.
| release: { | ||
| name: version, | ||
| }, | ||
| }), |
There was a problem hiding this comment.
The release is set to version only. That can easily collide across different repos/environments and makes it hard to correlate a Sentry release back to a specific commit/build. Sentry generally benefits from a unique release identifier (e.g., name@version+sha or name@version with a dist).
Also, without a dist (or commit SHA in release), rebuilding the same version can overwrite artifacts unexpectedly or create confusing state.
Suggestion
Make the release identifier unique and/or set a dist.
Options:
- Include commit SHA in release name:
const sha = process.env.GITHUB_SHA ?? process.env.VERCEL_GIT_COMMIT_SHA;
const releaseName = sha ? `${version}-${sha.slice(0, 7)}` : version;
// release: { name: releaseName }- Keep
release.name = versionbut adddist(e.g., run number / sha):
release: { name: version, dist: process.env.GITHUB_RUN_NUMBER ?? "local" }Reply with "@CharlieHelps yes please" if you’d like me to add a commit with one of these options.
|
|
||
| - name: Run build | ||
| run: pnpm run build | ||
| env: | ||
| SENTRY_ORG: ${{ secrets.SENTRY_ORG }} | ||
| SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }} | ||
| SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} |
There was a problem hiding this comment.
Injecting Sentry secrets into build-and-test means the build step will attempt Sentry uploads on all CI runs where secrets are available. That includes PRs from the same repo (not forks), feature branches, and potentially scheduled builds—risking noise in Sentry releases and polluted artifacts.
If you only want uploads for releases, keep secrets limited to the release workflow/job or gate this step by branch/event.
Suggestion
Gate the env injection (or the build step) so Sentry secrets are only present on main (or on push events) and not on PRs. Example:
- name: Run build
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
run: pnpm run build
env:
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}Or set SENTRY_UPLOAD_SOURCEMAPS: 'true' only in the release workflow and gate in tsdown.config.ts. Reply with "@CharlieHelps yes please" if you'd like me to add a commit with this suggestion.
Adds automatic source map upload to Sentry during production builds via the Sentry Rollup plugin.
Changes
@sentry/rollup-plugintotsdown.config.tswith environment-based auth (SENTRY_ORG, SENTRY_PROJECT, SENTRY_AUTH_TOKEN).env.sample.env.sentry-build-pluginto prevent credential leakageBehavior
Build continues successfully when Sentry credentials are absent (warnings only). Source maps upload automatically when credentials are configured via environment variables or
.env.sentry-build-pluginfile.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
✨ PR Description
Purpose: Integrate Sentry Rollup plugin to automatically upload source maps during build process for improved error tracking and debugging in production.
Main changes:
Generated by LinearB AI and added by gitStream.
AI-generated content may contain inaccuracies. Please verify before using.
💡 Tip: You can customize your AI Description using Guidelines Learn how
Note
Enables automatic source map upload to Sentry during builds while remaining no-op without credentials.
@sentry/rollup-pluginintsdown.config.tswith release name frompackage.jsonand sourcemaps glob./dist/**/*.mapSENTRY_ORG,SENTRY_PROJECT,SENTRY_AUTH_TOKENin GitHub Actions build steps (build-and-test.yml,release.yml).env.sampleand setup instructions inREADME.md.env.sentry-build-pluginin.gitignore@sentry/rollup-pluginand updates lockfileWritten by Cursor Bugbot for commit 3f947fd. This will update automatically on new commits. Configure here.