Upload source maps with CLI

AI wizard

Set up source map uploading automatically with our wizard by running this command in your project directory with your terminal (it also works for LLM coding agents like Cursor and Bolt):

Manual setup

  1. Install hog

    Required

    Install hog, PostHog's CLI:

    curl -fsSL https://posthog.com/install.sh | sh

    In GitHub Actions, install hog with the PostHog/setup-hog action:

    YAML
    - uses: PostHog/setup-hog@v1

  2. Authenticate

    Required

    Log in to PostHog. This opens your browser, where you approve the login:

    Terminal
    hog auth login

    If posthog-cli is already logged in on this machine, import that login instead:

    Terminal
    hog auth migrate

    hog reads only the HOG_* names. The PostHog build plugins and upload scripts still pass the old POSTHOG_CLI_* names to hog for now, with a warning for each one. A hog command you run yourself needs the HOG_* names. The migration guide lists each rename.

    If you already keep your project's configuration in a dotenv-style file, you can load the HOG_* variables from it with the --dotenv-file option instead of exporting them:

    Terminal
    hog error-tracking upload ./path/to/assets --dotenv-file .env
  3. Inject

    Required

    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
    # Inject release and chunk metadata into sourcemaps
    hog error-tracking inject ./path/to/assets

    You can verify that the metadata has been injected by checking for the //# chunkId=... comment in the minified code.

  4. Upload

    Required

    You will then need to upload the modified assets to PostHog.

    Terminal
    # Upload injected sourcemaps to their release
    hog error-tracking upload ./path/to/assets --release-name my-app --release-version 1.2.3

    hog creates or reuses the release for the detected or supplied release name and version. hog tries to detect the release name and version from Git and your CI provider, but you can set them explicitly with --release-name and --release-version. We recommend setting the release name, and letting hog detect the version, if your project is continuously deployed (the version will be the git commit hash at build time).

    You can also pass --build to add a build number (e.g. CFBundleVersion on iOS, versionCode on Android) to the release version, as <version>+<build>. This is optional.

    💡 Tip: You can use the --delete-after option to clean up sourcemaps after uploading them. To inject and upload in one command, use hog error-tracking process ./path/to/assets.

  5. Serve injected assets

    Required

    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.

    If you serve a copy of the bundled assets as they were prior to running hog error-tracking inject, we won't be able to use the uploaded sourcemap to unminify or demangle your stack traces.

  6. Verify source maps upload

    Checkpoint
    Confirm that source maps are successfully uploaded to PostHog.Check symbol sets in PostHog

Still have questions?

Was this page useful?