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. Use the GitHub action

    Required

    Add a workflow step to run the PostHog upload action after your build:

    YAML
    name: Upload source maps to PostHog
    on:
    push:
    branches: [main]
    jobs:
    build_and_upload:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - 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@v0.4.6
    with:
    directory: dist
    env-id: ${{ secrets.POSTHOG_ENV_ID }}
    cli-token: ${{ secrets.POSTHOG_CLI_TOKEN }}
    # host: https://eu.posthog.com # Required only for EU cloud
    # project: my-awesome-project # Optional; falls back to repo name
    # 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
  3. Inputs

    Reference for action configuration
    NameRequiredDescription
    directoryYesDirectory containing built assets (for example, dist)
    env-idYesPostHog project ID. Get it from your project settings
    cli-tokenYesPersonal API key with error tracking write scope. Get it from your personal API key settings
    projectNoProject identifier. Defaults to the Git repository name when available
    versionNoRelease/version (for example, commit SHA). Defaults to current commit SHA when available
    hostNoPostHog host URL. Defaults to https://us.posthog.com. For EU cloud, set it to https://eu.posthog.com

    We recommend storing env-id and cli-token in GitHub Secrets (for example, POSTHOG_ENV_ID and POSTHOG_CLI_TOKEN).

  4. 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
  5. 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.

Community questions

Was this page useful?

Questions about this page? or post a community question.