Link releases for Ruby

Ruby apps run their source code directly, so there are no source maps to upload. Stack traces already show the right files and lines.

To link each exception to the release that produced it, create the release when you deploy and give its ID to your app. The Ruby SDK reads the ID from the POSTHOG_RELEASE_ID environment variable and sends it as $release_id on every event. This also applies to Rails apps, since posthog-rails uses the Ruby SDK.

  1. Update the SDK

    Required

    Update to posthog-ruby 3.25.0 or later:

    Terminal
    bundle update posthog-ruby

    On Rails, update posthog-rails in the same command. Each posthog-rails version depends on one exact posthog-ruby version:

    Terminal
    bundle update posthog-rails posthog-ruby
  2. Resolve the release in GitHub Actions

    Required

    Resolve the release in the workflow that deploys your app to production. Resolving creates the release if it doesn't exist yet, so skip it for pull requests, preview builds, and local development. When POSTHOG_RELEASE_ID isn't set, the SDK sends no release ID.

    Add the PostHog/resolve-release action before the step that deploys your app:

    YAML
    name: Deploy
    on:
    push:
    branches: [main]
    jobs:
    deploy:
    runs-on: ubuntu-latest
    permissions:
    id-token: write # lets hog get an OIDC token for PostHog
    contents: read
    steps:
    - uses: actions/checkout@v6
    - name: Resolve PostHog release
    id: posthog-release
    uses: PostHog/resolve-release@v2
    with:
    hog-version: 1
    project-id: ${{ vars.POSTHOG_PROJECT_ID }}
    # For EU cloud:
    # host: https://eu.posthog.com
    - name: Deploy
    env:
    POSTHOG_RELEASE_ID: ${{ steps.posthog-release.outputs.release-id }}
    # Your deploy command. It must pass POSTHOG_RELEASE_ID to your app.
    run: ./deploy.sh

    The action installs hog, finds the release for this commit, or creates it, and puts its ID in the release-id output. hog logs in with the job's OIDC token, so you don't store a PostHog key in GitHub. Run hog ci setup --scope error_tracking:write once in the repository, and an organization admin approves it in PostHog. It names the release after the repository and uses the commit SHA as the version. If the same workflow also uploads source maps with that name and version, both steps use the same release.

    InputRequiredDescription
    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
    hostNoPostHog host URL. Defaults to host in posthog.json, then US cloud. For EU cloud, set it to https://eu.posthog.com
    release-nameNoRelease name. Defaults to the repository name
    release-versionNoRelease version. Defaults to the commit SHA

    To keep deploying when PostHog can't be reached, add continue-on-error: true and timeout-minutes: 5 to the step. If the step fails, release-id is empty, and the SDK treats an empty POSTHOG_RELEASE_ID as unset.

    See the action's README for all inputs and outputs, and for how to share one release across several jobs.

    If you don't use GitHub Actions, see without GitHub Actions.

  3. Give the release ID to your app

    Required

    Your deployed app must have POSTHOG_RELEASE_ID in its environment when it starts. The SDK reads it once, when you create the PostHog client.

    Set it to the value of the release-id output, the same way you set your app's other environment variables.

  4. Verify the release

    Checkpoint

    Deploy the app and capture a test exception. Then open the issue in error tracking.

    The stack trace shows the release, with its version and commit. The exception's $release_id property has the same value as the release-id output of the workflow.

Without GitHub Actions

If you deploy with another CI system or a script, resolve the release with hog, the PostHog CLI. Run these commands in your production deploy, from a checkout of your repository:

Terminal
curl -fsSL https://posthog.com/install.sh | sh
export PATH="$HOME/.local/bin:$PATH"
# Set these from your CI secrets
export HOG_PERSONAL_API_KEY=<personal_api_key>
export HOG_PROJECT_ID=<project_id>
# For EU cloud:
# export HOG_HOST=https://eu.posthog.com
export POSTHOG_RELEASE_ID=$(hog error-tracking release -o text)

In GitHub Actions, GitLab.com, and Depot CI, hog can log in with the job's OIDC token instead of a personal API key. Run hog ci setup --scope error_tracking:write once in your repository, and leave out HOG_PERSONAL_API_KEY. In GitHub Actions, the job also needs the id-token: write permission.

The command prints only the release ID. It reads the repository name and commit from Git. To choose your own, add --release-name and --release-version.

Then give POSTHOG_RELEASE_ID to your deployed app, so that it is in the app's environment when the app starts.

Still have questions?

Was this page useful?