Upload source maps with GitHub Actions

  1. Prerequisites

    Required

    Uploading source maps with GitHub Actions requires your build to have already generated source maps. This action does not build your project, it only injects source map metadata into the built files and uploads them to PostHog. Make sure to run your production build first (for example, npm run build).

  2. Trust the repository

    Required

    The action installs hog, the PostHog CLI, which logs in with the job's OIDC token. You don't store a PostHog key in GitHub.

    Once, in a clone of the repository, log in with hog and ask PostHog to trust the repository's workflows:

    Terminal
    hog auth login
    hog ci setup --scope error_tracking:write

    An organization admin approves the request in PostHog. Add the host and projectId that hog prints to posthog.json, or set the project-id and host inputs below.

  3. Use the GitHub action

    Required

    Add a workflow step to run the PostHog upload action after your build. The job needs the id-token: write permission:

    YAML
    name: Upload source maps to PostHog
    on:
    push:
    branches: [main]
    jobs:
    build_and_upload:
    runs-on: ubuntu-latest
    permissions:
    id-token: write # lets hog get an OIDC token for PostHog
    contents: read
    steps:
    - uses: actions/checkout@v6
    - uses: actions/setup-node@v4
    with:
    node-version: 20
    cache: npm
    - run: npm ci
    - run: npm run build
    # Inject and upload source maps using the PostHog action
    - name: Inject & upload source maps to PostHog
    uses: PostHog/upload-source-maps@v3
    with:
    directory: dist
    hog-version: 1
    # project-id: ${{ vars.POSTHOG_PROJECT_ID }} # Without a posthog.json that names it
    # host: https://eu.posthog.com # Required only for EU cloud
    # release-name: my-awesome-project # Optional; falls back to repo name
    # release-version: ${{ github.sha }} # Optional; falls back to current commit SHA

    This step:

    • Injects a //# chunkId=... comment into your built source files so PostHog can match them with uploaded source maps
    • Uploads the source maps to your PostHog project
  4. Inputs

    Reference for action configuration

    NameRequiredDescription
    directoryNoDirectory containing built assets (for example, dist). Defaults to errorTracking.sources in posthog.json
    hog-versionYesThe hog version to install, such as 1.0.0, or 1 for the newest 1.x
    project-idNoPostHog project ID. Get it from your project settings. Defaults to projectId in posthog.json
    release-nameNoRelease name. Defaults to the repository name
    release-versionNoRelease version (for example, commit SHA). Defaults to the commit SHA
    hostNoPostHog host URL. Defaults to host in posthog.json, then https://us.posthog.com. For EU cloud, set it to https://eu.posthog.com

    See the action's README for all inputs, and for how to upgrade from v2.

  5. Verify upload and injection

    Checkpoint
    1. Confirm symbol sets are present in PostHog after the workflow runs.
    Check symbol sets in PostHog
    1. Confirm your served production files include an injected comment at the end of the file similar to:
    JavaScript
    //# chunkId=0197e6db-9a73-7b91-9e80-4e1b7158db5c
  6. Serve injected assets

    Required

    You must deploy the injected build artifacts to production. PostHog reads the injected chunkId metadata during error capture to resolve stack traces. If you deploy files that were not processed by the action, uploaded source maps cannot be used to unminify your stack traces.

Still have questions?

Was this page useful?