Uploading Honeybadger source maps with esbuild and Sprockets

Curated ago by @jeremysmithco

Description

If you are using Honeybadger for JS error monitoring on your Rails app, you may want to upload source maps so they can be applied to JS stack traces.

Here’s how you can do that if you are using esbuild, Sprockets, and deploying to Heroku. The source map will be uploaded to Honeybadger during the build phase, via a Rake task enhancing the assets:precompile step.

1
2
3
4
5
6
7
8
<script src="//js.honeybadger.io/v6.9/honeybadger.min.js" type="text/javascript"></script>
<script type="text/javascript">
  Honeybadger.configure({
    apiKey: "<%= ENV["HONEYBADGER_API_KEY_JS"] %>",
    environment: "<%= ENV["HONEYBADGER_ENV"] %>",
    revision: "<%= ENV["HEROKU_SLUG_COMMIT"] %>",
  });
</script>

You’d render this partial in the <head> of your app layout.

You’ll need to ensure HONEYBADGER_API_KEY_JS and HONEYBADGER_ENV config vars are set in Heroku. The HEROKU_SLUG_COMMIT var will be the commit hash for the current release.