Upload source maps for Angular
- 1
Install the PostHog CLI
RequiredInstall
posthog-cli: - 2
Authenticate the PostHog CLI
RequiredTo authenticate the CLI, you can call the
logincommand and follow the instructions:TerminalIf you are using the CLI in a CI/CD environment such as GitHub Actions, you can set environment variables to authenticate:
Environment Variable Description Source POSTHOG_CLI_ENV_IDPostHog project ID Environment settings POSTHOG_CLI_TOKENPersonal API key with error tracking writescopeAPI key settings Use the
--hostoption in subsequent commands to specify a different PostHog instance / or region. For EU users:Terminal - 3
Output source maps for Angular
RequiredYou can configure Angular to generate source maps by adding the following to your
angular.jsonfile:angular.jsonThen, build your Angular application:
Terminal Verify source map generation
CheckpointConfirm source maps are generatedConfirm that the source maps are generated in the
dist/<your-app-name>/directory. You should see a.js.mapfile for each JS bundle.- 4
Inject source map
RequiredYour goal in this step: Add metadata to associate maps with your code.Once you've built your application and have bundled assets, inject the context required by PostHog to associate the maps with the served code.
Terminal Verify source map injection
CheckpointConfirm source map comments are presentConfirm that the served files are injected with the correct source map comment in production in dev tools:
You should see a comment like this in your minified JS files, for example
main-IX6K2QJM.js:JavaScript- 5
Upload source map
RequiredYour goal in this step: Send the processed source maps to PostHog.You will then need to upload the modified assets to PostHog.
Terminal💡 Tip: You can use
--delete-afteroption to clean up sourcemaps after uploading them.Serve injected assets
You must serve the injected assets in deployed production app. The injected metadata is used during error capture to identify the correct source map to use. We suggest you upload source maps right after your production build in CI.
If you serve a copy of the bundled assets as they were prior to running
posthog-cli sourcemap inject, we won't be able to use the uploaded sourcemap to unminify or demangle your stack traces.