Upload source maps with CLI
- 1
Download CLI
RequiredInstall
posthog-cli: - 2
Authenticate
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_HOSTThe PostHog host to connect to [default: https://us.posthog.com] Project settings POSTHOG_CLI_PROJECT_IDPostHog project ID Project settings POSTHOG_CLI_API_KEYPersonal API key with error tracking writeandorganization readscopesAPI key settings You can also use the
--hostoption instead of thePOSTHOG_CLI_HOSTenvironment variable to target a different PostHog instance or region. For EU users:Terminal - 3
Inject
RequiredOnce you've built your application and have bundled assets, inject the context required by PostHog to associate the maps with the served code.
TerminalYou can verify that the metadata has been injected by checking for the
//# chunkId=...comment in the minified code. - 4
Upload
RequiredYou will then need to upload the modified assets to PostHog.
TerminalThe CLI will create or reuse the release for the detected or supplied release name and version. The CLI will try to detect release name and version information, but you can set them explicitly with
--release-nameand--release-version. We recommend setting the release name, and letting the CLI detect the version, if your project is continuously deployed (the version will be the git commit hash at build time).💡 Tip: You can use
--delete-afteroption to clean up sourcemaps after uploading them. - 5
Serve injected assets
RequiredYou 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.
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.