Skip to content

Add PostHog sourcemap publishing (ENG-460) #1250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

devin-ai-integration[bot]
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Apr 14, 2025

PostHog Sourcemap Publishing

This PR implements sourcemap publishing to PostHog during our application build process to enhance error tracking capabilities. It allows PostHog to properly symbolicate minified JavaScript errors in production, showing accurate file names, line numbers, and function names in error stack traces.

Changes:

  • Added productionBrowserSourceMaps: true to Next.js config to enable sourcemap generation in production builds
  • Created new script scripts/publish-sourcemaps-to-posthog.js to find and upload sourcemaps to PostHog
  • Updated package.json postbuild script to include sourcemap publishing
  • Optimized sourcemap publishing to prevent memory issues
  • Removed unnecessary instrumentationHook option from next.config.mjs

Design Decisions:

  • Only uploads sourcemaps in production environment
  • Uses existing POSTHOG_API_KEY for API authentication
  • Logs errors but doesn't fail the build if sourcemap upload fails
  • Uses timestamp-based versioning to ensure sourcemaps match deployed code
  • Implements memory-efficient strategies:
    • Stream-based file processing
    • Batch processing for sourcemap uploads
    • File size filtering to prevent memory exhaustion
    • Increased Node.js memory limit to 4GB

Testing:

  • Verified that the script runs correctly during build process
  • Confirmed sourcemaps are generated and found by the script
  • Tested error handling to ensure build doesn't fail on upload errors

Notes:

  • The failing test in analytics.do package is unrelated to this PR and should be addressed separately

Fixes Linear Ticket: ENG-460

Link to Devin run: https://app.devin.ai/sessions/5df7812de04b424e9dfe102d26e3ba69

Copy link

linear bot commented Apr 14, 2025

Copy link

vercel bot commented Apr 14, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ai ❌ Failed (Inspect) Apr 14, 2025 7:32am

Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

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.

0 participants