Skip to content

chore: track bundle sizes in Amplitude#1762

Open
daniel-graham-amplitude wants to merge 42 commits into
mainfrom
SDK-14-track-bundle-size-in-amplitude
Open

chore: track bundle sizes in Amplitude#1762
daniel-graham-amplitude wants to merge 42 commits into
mainfrom
SDK-14-track-bundle-size-in-amplitude

Conversation

@daniel-graham-amplitude
Copy link
Copy Markdown
Collaborator

@daniel-graham-amplitude daniel-graham-amplitude commented May 15, 2026

Summary

Track JS bundle sizes in Amplitude after publish

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?: No

Note

Low Risk
Observability-only post-publish step with continue-on-error; no runtime SDK or publish behavior changes beyond optional telemetry.

Overview
After a release publish, the deploy workflow now runs a new script that measures the same gzipped bundles defined in .size-limit.js and sends SDK Bundle Size events to Amplitude (package name/version, path, filename, byte size). That step uses AMPLITUDE_API_KEY and is continue-on-error: true so a telemetry failure does not block shipping.

.size-limit.js gains packageJsonPath and name on each entry so the reporter can attach npm package metadata without duplicating paths. CI’s check-size-limits job drops the redundant Save Nx cache step (restore + size-limit action remain).

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

@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 15, 2026

SDK-14

@daniel-graham-amplitude daniel-graham-amplitude changed the base branch from main to SDK-12-size-limit-gating-part-2 May 15, 2026 23:42
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 4 potential issues.

Autofix Details

Bugbot Autofix prepared fixes for all 4 issues found in the latest run.

  • ✅ Fixed: Wrong script path references non-existent .scripts directory
    • Updated the workflow to invoke the existing scripts/report-bundle-size.js path.
  • ✅ Fixed: Missing AMPLITUDE_API_KEY env var in workflow step
    • Added the AMPLITUDE_API_KEY secret mapping to the bundle-size reporting workflow step.
  • ✅ Fixed: Missing name property on session-replay size entry
    • Added the missing session replay bundle name value for consistent reporting.
  • ✅ Fixed: Missing Content-Type header in Amplitude API request
    • Added the Content-Type: application/json header to the Amplitude HTTP V2 request.

Create PR

Or push these changes by commenting:

@cursor push 744dbd9a82
Preview (744dbd9a82)
diff --git a/.github/workflows/publish-v1.yml b/.github/workflows/publish-v1.yml
--- a/.github/workflows/publish-v1.yml
+++ b/.github/workflows/publish-v1.yml
@@ -119,4 +119,6 @@
       # Report bundle size to Amplitude
       - name: Report bundle size to Amplitude
         run: |
-          node ./.scripts/report-bundle-size.js
+          node ./scripts/report-bundle-size.js
+        env:
+          AMPLITUDE_API_KEY: ${{ secrets.AMPLITUDE_API_KEY }}

diff --git a/.size-limit.js b/.size-limit.js
--- a/.size-limit.js
+++ b/.size-limit.js
@@ -11,6 +11,7 @@
     // session-replay standalone bundle
     packageJsonPath: './packages/session-replay-browser/package.json',
     path: `./packages/session-replay-browser/lib/scripts/session-replay-browser-min.js.gz`,
+    name: 'session-replay-browser.min.js.gz',
     limit: '150kb',
     brotli: false,
   },
@@ -22,6 +23,6 @@
     limit: '225kb',
     brotli: false,
   },
-]
+];
 
 module.exports = limits;

diff --git a/scripts/report-bundle-size.js b/scripts/report-bundle-size.js
--- a/scripts/report-bundle-size.js
+++ b/scripts/report-bundle-size.js
@@ -18,7 +18,7 @@
   };
 }
 
-const events = [];  
+const events = [];
 for (const limit of sizeLimits) {
   const size = fs.statSync(limit.path).size;
   events.push(getBundleSizeEvent(limit.path, size, limit.name, limit.packageJsonPath));
@@ -26,17 +26,22 @@
 
 fetch('https://api.amplitude.com/2/httpapi', {
   method: 'POST',
+  headers: {
+    'Content-Type': 'application/json',
+  },
   body: JSON.stringify({
     api_key: process.env.AMPLITUDE_API_KEY,
     events: events,
   }),
-}).then(response => {
-  console.log(response.status);
-  response.json().then(data => {
-    console.log(data);
-    process.exit(response.status >= 400 ? 1 : 0);
+})
+  .then((response) => {
\ No newline at end of file
+    console.log(response.status);
+    response.json().then((data) => {
+      console.log(data);
+      process.exit(response.status >= 400 ? 1 : 0);
+    });
+  })
+  .catch((error) => {
+    console.error('Error reporting bundle size to Amplitude:', error);
+    process.exit(1);
   });
-}).catch(error => {
-  console.error('Error reporting bundle size to Amplitude:', error);
-  process.exit(1);
-});

You can send follow-ups to the cloud agent here.

Comment thread .github/workflows/publish-v1.yml Outdated
Comment thread .github/workflows/publish-v1.yml Outdated
Comment thread .size-limit.js
Comment thread scripts/report-bundle-size.js
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 2 potential issues.

Autofix Details

Bugbot Autofix prepared fixes for both issues found in the latest run.

  • ✅ Fixed: Bundle size reporting missing from the release deploy job
    • Added the Amplitude bundle size reporting step to the release deploy job after publishing to NPM.
  • ✅ Fixed: Inner promise not returned causes unhandled rejection
    • Returned the response.json() promise so JSON parsing failures propagate to the existing catch handler.

Create PR

Or push these changes by commenting:

@cursor push df81012d4f
Preview (df81012d4f)
diff --git a/.github/workflows/publish-v2.yml b/.github/workflows/publish-v2.yml
--- a/.github/workflows/publish-v2.yml
+++ b/.github/workflows/publish-v2.yml
@@ -177,6 +177,13 @@
         env:
           S3_BUCKET_NAME: ${{ secrets.S3_BUCKET_NAME }}
 
+      # Report bundle size to Amplitude
+      - name: Report bundle size to Amplitude
+        env:
+          AMPLITUDE_API_KEY: ${{ secrets.AMPLITUDE_API_KEY }}
+        run: |
+          node ./scripts/report-bundle-size.js
+
   prerelease:
     name: Prerelease feature branch
     runs-on: ubuntu-latest

diff --git a/scripts/report-bundle-size.js b/scripts/report-bundle-size.js
--- a/scripts/report-bundle-size.js
+++ b/scripts/report-bundle-size.js
@@ -35,7 +35,7 @@
   }),
 }).then(response => {
   console.log(response.status);
-  response.json().then(data => {
+  return response.json().then(data => {
     console.log(data);
     process.exit(response.status >= 400 ? 1 : 0);
   });

You can send follow-ups to the cloud agent here.

Comment thread .github/workflows/publish-v2.yml Outdated
Comment thread scripts/report-bundle-size.js
Base automatically changed from SDK-12-size-limit-gating-part-2 to main May 22, 2026 15:40
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 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Invalid GitHub Actions syntax allow-failure instead of continue-on-error
    • Replaced the invalid workflow step key with continue-on-error: true so bundle size reporting remains non-blocking.

Create PR

Or push these changes by commenting:

@cursor push 341389638f
Preview (341389638f)
diff --git a/.github/workflows/publish-v2.yml b/.github/workflows/publish-v2.yml
--- a/.github/workflows/publish-v2.yml
+++ b/.github/workflows/publish-v2.yml
@@ -179,7 +179,7 @@
 
       # Report bundle size to Amplitude
       - name: Report bundle size to Amplitude
-        allow-failure: true
+        continue-on-error: true
         env:
           AMPLITUDE_API_KEY: ${{ secrets.AMPLITUDE_API_KEY }}
         run: |

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit 634b36f. Configure here.

Comment thread .github/workflows/publish-v2.yml Outdated
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.

1 participant