Skip to content

New Relic Source Map Upload

This document explains how to configure and use automatic source map uploads to New Relic for better error reporting and debugging.

Source maps allow New Relic to un-minify JavaScript error stack traces, making it easier to debug production issues. Our build process automatically generates source maps, and we can upload them to New Relic using their API.

This setup covers both:

  • 🌐 Browser Monitoring: Client-side JavaScript errors (via API upload)
  • πŸ–₯️ APM Monitoring: Server-side Node.js errors (via Node.js flag)
FeatureAPM (Server-side)Browser (Client-side)
PurposeServer-side Node.js errorsClient-side JavaScript errors
SetupNode.js --enable-source-maps flagUpload via API
DetectionAutomaticManual upload required
Source Mapsdist/server/*.mjs.mapdist/client/_astro/*.js.map
Configurationβœ… Already enabled in this project⚠️ Requires API keys

You need to set the following environment variables:

  • NEW_RELIC_USER_API_KEY - Your New Relic User API Key (not the same as the license key)
  • NEW_RELIC_BROWSER_APPLICATION_ID - Your New Relic Browser Application ID
  • GITHUB_REPOSITORY_URL - Your repository URL (e.g., https://github.com/your-org/your-repo)
  • GITHUB_SHA or GIT_COMMIT - Git commit hash for the build
  1. Go to New Relic API Keys
  2. Click β€œCreate a key”
  3. Choose β€œUser key” type
  4. Give it a descriptive name like β€œSource Maps Upload”
  5. Copy the generated key
  1. Go to your New Relic Browser application
  2. Look at the URL - it should contain the application ID
  3. Or go to Settings β†’ Application settings and find the Application ID

Upload source maps manually after building:

Terminal window
# Build the project first
npm run build
# Then upload source maps (CI/CD only)
node .github/scripts/upload-sourcemaps.js

Note: Manual upload requires the same environment variables as CI/CD and is primarily intended for debugging.

For GitHub Actions, the source maps are uploaded as part of the deployment process (not build process) to ensure environment-specific application IDs are used.

Required GitHub Secrets:

NEW_RELIC_USER_API_KEY: your_user_api_key
NEW_RELIC_BROWSER_APPLICATION_ID_PROD: browser_app_id_for_production
NEW_RELIC_BROWSER_APPLICATION_ID_NONPROD: browser_app_id_for_nonprod_and_ephemeral
NEW_RELIC_APM_APPLICATION_ID_PROD: apm_app_id_for_production
NEW_RELIC_APM_APPLICATION_ID_NONPROD: apm_app_id_for_nonprod_and_ephemeral

The workflow automatically:

  1. Downloads build artifacts (including source maps)
  2. Determines environment (production vs nonprod/ephemeral)
  3. Sets the appropriate New Relic application IDs (both Browser and APM)
  4. Uploads source maps with deployment metadata
  5. Records deployment markers in APM for performance correlation

This approach allows you to:

  • βœ… Build once, deploy to multiple environments
  • βœ… Use environment-specific New Relic application IDs
  • βœ… Track source maps per deployment
  • βœ… Include git commit information for better tracking
  • βœ… Correlate deployments with performance changes in APM

This deployment-based approach provides several advantages over build-time uploads:

  • πŸ—οΈ Build once, deploy many: Source maps uploaded per environment, not per build
  • 🎯 Environment-specific: Different New Relic app IDs for prod vs nonprod
  • πŸ”„ Deployment tracking: Source maps tied to specific deployments with git commit info
  • πŸš€ Parallel uploads: Multiple environments can be deployed with appropriate source maps
  • πŸ“¦ Artifact reuse: Same build artifacts used across all environments

The deployment markers provide additional observability benefits:

  • πŸ“ˆ Performance correlation: See how deployments affect response times, error rates, and throughput
  • πŸ“… Timeline visualization: Vertical lines on APM charts mark deployment times
  • πŸ” Deployment details: View who deployed, when, and what changed
  • 🚨 Incident correlation: Quickly identify if performance issues started after a deployment
  • πŸ“‹ Deployment history: Track all deployments in the APM Deployments page
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Build │───▢│ Artifacts │───▢│ Deploy β”‚
β”‚ (with maps) β”‚ β”‚ (dist/) β”‚ β”‚ (per env) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Upload Source Maps β”‚
β”‚ (env-specific) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  1. Build Process: Astro/Vite generates source maps alongside the minified JavaScript files
  2. Discovery: The upload script scans the dist/ directory for .map files
  3. Mapping: For each source map, it finds the corresponding JavaScript file
  4. Upload: Each source map is uploaded to New Relic with metadata about the JavaScript URL
  5. Verification: The script reports success/failure for each upload
  1. β€œNo source maps found”

    • Ensure sourcemap: true is set in your Vite configuration
    • Check that the build completed successfully
    • Verify the dist directory contains .map files
  2. β€œAPI key invalid”

    • Verify you’re using a User API key, not the license key
    • Check the key hasn’t expired
    • Ensure the key has proper permissions
  3. β€œApplication ID not found”

    • Verify the Browser Application ID is correct
    • Ensure you’re using the browser app ID, not the APM app ID
  4. Rate limit errors

    • New Relic limits: 1000 uploads/minute, 15000 uploads/day
    • If you hit limits, wait and retry

For more verbose logging, you can modify the script or add environment variables to see detailed upload information.

Once set up, you’ll get:

  • πŸ› Readable Stack Traces: Error reports in New Relic will show original source code locations
  • 🎯 Better Debugging: Click through from errors to exact source code lines
  • πŸ‘₯ Team Collaboration: Developers can quickly identify and fix production issues
  • πŸ“Š Performance Insights: Link performance data to specific code areas
  • πŸ“ Deployment Correlation: See how code changes affect performance in APM charts and dashboards

βœ… APM Source Maps: Enabled via Node.js --enable-source-maps flag (server-side errors)
βœ… Browser Source Maps: Upload script configured for client-side errors
βœ… GitHub Actions: Deployment-based upload workflow ready
βœ… Deployment Markers: APM deployment tracking configured
⚠️ Secrets: Requires GitHub secrets setup for New Relic API keys