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.
Overview
Section titled βOverviewβ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)
APM vs Browser Source Maps
Section titled βAPM vs Browser Source Mapsβ| Feature | APM (Server-side) | Browser (Client-side) |
|---|---|---|
| Purpose | Server-side Node.js errors | Client-side JavaScript errors |
| Setup | Node.js --enable-source-maps flag | Upload via API |
| Detection | Automatic | Manual upload required |
| Source Maps | dist/server/*.mjs.map | dist/client/_astro/*.js.map |
| Configuration | β Already enabled in this project | β οΈ Requires API keys |
1. Required Environment Variables
Section titled β1. Required Environment VariablesβYou need to set the following environment variables:
Required for Source Map Upload:
Section titled βRequired for Source Map Upload:β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
Optional (but recommended for better tracking):
Section titled βOptional (but recommended for better tracking):βGITHUB_REPOSITORY_URL- Your repository URL (e.g.,https://github.com/your-org/your-repo)GITHUB_SHAorGIT_COMMIT- Git commit hash for the build
2. Getting Your New Relic User API Key
Section titled β2. Getting Your New Relic User API Keyβ- Go to New Relic API Keys
- Click βCreate a keyβ
- Choose βUser keyβ type
- Give it a descriptive name like βSource Maps Uploadβ
- Copy the generated key
3. Finding Your Browser Application ID
Section titled β3. Finding Your Browser Application IDβ- Go to your New Relic Browser application
- Look at the URL - it should contain the application ID
- Or go to Settings β Application settings and find the Application ID
Manual Upload
Section titled βManual UploadβUpload source maps manually after building:
# Build the project firstnpm run build
# Then upload source maps (CI/CD only)node .github/scripts/upload-sourcemaps.jsNote: Manual upload requires the same environment variables as CI/CD and is primarily intended for debugging.
CI/CD Integration
Section titled βCI/CD Integrationβ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_keyNEW_RELIC_BROWSER_APPLICATION_ID_PROD: browser_app_id_for_productionNEW_RELIC_BROWSER_APPLICATION_ID_NONPROD: browser_app_id_for_nonprod_and_ephemeralNEW_RELIC_APM_APPLICATION_ID_PROD: apm_app_id_for_productionNEW_RELIC_APM_APPLICATION_ID_NONPROD: apm_app_id_for_nonprod_and_ephemeralThe workflow automatically:
- Downloads build artifacts (including source maps)
- Determines environment (production vs nonprod/ephemeral)
- Sets the appropriate New Relic application IDs (both Browser and APM)
- Uploads source maps with deployment metadata
- 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
Deployment-Based Upload Benefits
Section titled βDeployment-Based Upload Benefitsβ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
Deployment Markers
Section titled βDeployment Markersβ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
Architecture
Section titled βArchitectureββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββ Build βββββΆβ Artifacts βββββΆβ Deploy ββ (with maps) β β (dist/) β β (per env) ββββββββββββββββ ββββββββββββββββ βββββββββββ¬ββββββββ β βΌ βββββββββββββββββββββββ β Upload Source Maps β β (env-specific) β βββββββββββββββββββββββHow It Works
Section titled βHow It Worksβ- Build Process: Astro/Vite generates source maps alongside the minified JavaScript files
- Discovery: The upload script scans the
dist/directory for.mapfiles - Mapping: For each source map, it finds the corresponding JavaScript file
- Upload: Each source map is uploaded to New Relic with metadata about the JavaScript URL
- Verification: The script reports success/failure for each upload
Troubleshooting
Section titled βTroubleshootingβCommon Issues
Section titled βCommon Issuesβ-
βNo source maps foundβ
- Ensure
sourcemap: trueis set in your Vite configuration - Check that the build completed successfully
- Verify the dist directory contains
.mapfiles
- Ensure
-
β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
-
βApplication ID not foundβ
- Verify the Browser Application ID is correct
- Ensure youβre using the browser app ID, not the APM app ID
-
Rate limit errors
- New Relic limits: 1000 uploads/minute, 15000 uploads/day
- If you hit limits, wait and retry
Debug Mode
Section titled βDebug ModeβFor more verbose logging, you can modify the script or add environment variables to see detailed upload information.
Benefits
Section titled βBenefitsβ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
Current Implementation Status
Section titled βCurrent Implementation Statusββ
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