Upload debug symbols for Rust

The Rust SDK resolves stack traces in-process from whatever debug info the running binary carries — which works well in development, but release builds omit that debug info by default. Uploading debug symbols gives you fully resolved production stack traces: PostHog symbolicates frames server-side from the exact build that crashed, resolves inlined frames, and can display the source code around each frame.

Version requirements
  • posthog-rs 0.16.0 or later, which records the instruction addresses server-side symbolication needs. We recommend the latest version.
  • hog, the PostHog CLI. We recommend keeping it up to date with hog upgrade.
  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.

  3. Keep debug info in release builds

    Required

    Cargo omits debug info from release builds by default, and there is nothing to upload without it. Enable it in your Cargo.toml:

    toml
    [profile.release]
    debug = "line-tables-only"

    line-tables-only is enough to resolve file names, line numbers, and inlined frames while keeping binaries small. Use debug = "full" if you want complete debug info.

    On macOS, also set split-debuginfo = "packed" in the same profile. Cargo's macOS default (unpacked) leaves debug info in intermediate object files instead of producing the .dSYM bundle the CLI uploads.

    Watch out for stripping: if your profile sets strip explicitly, set it to "none" — or strip only after the upload runs. Debug info split into separate files also works: the CLI picks up objcopy --only-keep-debug companion files alongside the binaries.

  4. Check for a build ID

    Required

    PostHog matches stack frames to uploaded symbols by the binary's unique build ID: a GNU build ID on Linux, or the Mach-O UUID on macOS. macOS binaries always carry a UUID, so there is nothing to check there. Most Linux toolchains emit a GNU build ID by default — confirm yours does:

    Terminal
    readelf -n target/release/my-app | grep "Build ID"

    Replace my-app with your binary's name.

    If nothing shows up, tell the linker to add one in .cargo/config.toml, scoped to Linux builds (Apple's linker embeds a UUID on its own and rejects this flag):

    toml
    [target.'cfg(target_os = "linux")']
    rustflags = ["-C", "link-arg=-Wl,--build-id=sha1"]
  5. Build and upload

    Required

    After your release build, point the CLI at the build output directory:

    Terminal
    cargo build --release
    hog error-tracking upload target/release

    The CLI scans the directory and uploads every executable and shared library that carries debug info and a build ID, skipping everything else. On macOS it also uploads .dSYM bundles and standalone Mach-O binaries that embed their own DWARF, splitting universal (fat) binaries into one symbol set per architecture slice. Windows binaries (PDB debug info) are not supported yet. The upload is associated with a release automatically when the build directory is inside a git checkout.

    Run this as part of the same pipeline that produces your production binary. Each build has its own build ID, so symbols must be re-uploaded for every build you deploy.

  6. Optional: Include source code context

    Optional

    By default, only debug symbols are uploaded. To also display the source code around each frame in your stack traces, add --include-source:

    Terminal
    hog error-tracking upload target/release --include-source

    This bundles the project source files referenced by the debug info into the upload. It increases upload size, so only enable it if you want source context in the error tracking UI.

  7. Optional: Upload from CI

    Optional

    In CI, log in as the Authenticate step describes. For GitHub Actions, with the job's OIDC token:

    YAML
    jobs:
    build:
    runs-on: ubuntu-latest
    permissions:
    id-token: write # lets hog get an OIDC token for PostHog
    contents: read
    steps:
    - uses: actions/checkout@v6
    - uses: PostHog/setup-hog@v1
    - name: Build release binary
    run: cargo build --release
    - name: Upload debug symbols
    run: hog error-tracking upload target/release

    In other CI providers, set HOG_PERSONAL_API_KEY and HOG_PROJECT_ID on the upload step only. The build itself doesn't need them.

    hog defaults to US Cloud. If you're on EU Cloud or self-hosted, also set HOG_HOST (for example https://eu.posthog.com), or host in posthog.json.

    If your binary is built inside a Dockerfile, run the upload in the build stage right after the build, and pass the credentials in as build secrets so they never reach the runtime image.

  8. Verify debug symbols upload

    Checkpoint
    Confirm that debug symbols are successfully uploaded to PostHog.Check symbol sets in PostHog
  9. Test it end-to-end

    Optional

    Capture a test exception from the same release binary the symbols were uploaded for:

    Rust
    let error = std::io::Error::new(std::io::ErrorKind::Other, "This is a test exception from Rust");
    client.capture_exception(&error).await.unwrap();

    Run the binary, then check the error tracking issues view: the stack trace should resolve to your source files, including source context if you uploaded with --include-source. A rebuild changes the build ID, so if you rebuild, upload again before testing.

Still have questions?

Was this page useful?