Link releases for Python
Contents
Python 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 Python SDK reads the ID from the POSTHOG_RELEASE_ID environment variable and sends it as $release_id on every event.
- 1
Update the SDK
RequiredInstall posthog-python 7.59.0 or later:
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 deploys 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
RequiredYour deployed app must have
POSTHOG_RELEASE_IDin its environment when it starts. The SDK reads it once, when you create the PostHog client.Set it to the value of the
release-idoutput, the same way you set your app's other environment variables. 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 deployed app, so that it is in the app's environment when the app starts.