Link releases for Ruby
Contents
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
RequiredUpdate to posthog-ruby 3.25.0 or later:
TerminalOn Rails, update
posthog-railsin the same command. Eachposthog-railsversion depends on one exactposthog-rubyversion:Terminal - 2
Resolve the release in GitHub Actions
RequiredResolve 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_IDisn't set, the SDK sends no release ID.Add the
PostHog/resolve-releaseaction before the step that builds your app:YAMLThe action finds the release for this commit, or creates it, and puts its ID in the
release-idoutput. 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.Input Required Description api-keyYes Personal API key with the error tracking write scope. Get it from your personal API key settings project-idYes PostHog project ID. Get it from your project settings hostNo PostHog host URL. Defaults to US cloud. For EU cloud, set it to https://eu.posthog.comrelease-nameNo Release name. Defaults to the repository name release-versionNo Release version. Defaults to the commit SHA To keep deploying when PostHog can't be reached, add
continue-on-error: trueandtimeout-minutes: 5to the step. If the step fails,release-idis empty, and the SDK treats an emptyPOSTHOG_RELEASE_IDas 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
RequiredThe app must have
POSTHOG_RELEASE_IDin its environment when it starts. The SDK reads it once, when you create the PostHog client.If you deploy a Docker image, turn the build argument into an environment variable. Add these lines to the stage of your Dockerfile that runs the app:
dockerfileIf you don't build an image, set
POSTHOG_RELEASE_IDthe same way you set your app's other environment variables, with the value of therelease-idoutput. Verify the release
CheckpointDeploy 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_idproperty has the same value as therelease-idoutput of the workflow.
Without GitHub Actions
If you deploy with another CI system or a script, resolve the release with the PostHog CLI 0.12.0 or later. Run these commands in your production deploy, from a checkout of your repository:
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 app when it starts, for example with docker build --build-arg POSTHOG_RELEASE_ID="$POSTHOG_RELEASE_ID".