Skip to content

feat: report $release_id from POSTHOG_RELEASE_ID - #239

Closed
ablaszkiewicz wants to merge 4 commits into
mainfrom
ab/feat/release-id-env
Closed

feat: report $release_id from POSTHOG_RELEASE_ID#239
ablaszkiewicz wants to merge 4 commits into
mainfrom
ab/feat/release-id-env

Conversation

@ablaszkiewicz

@ablaszkiewicz ablaszkiewicz commented Aug 27, 2026

Copy link
Copy Markdown

Problem

A compiled Rust binary carries no release. A JavaScript build injects $release_id into its bundle, and a mobile app reads its version from the OS, but a Rust binary has neither.

Change

Report a $release_id on $exception events, from either an explicit release_id client option or the POSTHOG_RELEASE_ID environment variable. posthog-cli release resolve creates the release and prints its id; that id reaches the SDK one of two ways:

  • Build time (baked in). Set the release_id option — typically option_env!("POSTHOG_RELEASE_ID") — so the id is compiled into the binary. A shipped binary then self-identifies with nothing set at runtime. This survives code signing (the id is in the linked binary before you sign) and needs no deploy-time configuration.
  • Runtime (env fallback). Leave the option unset and the SDK reads POSTHOG_RELEASE_ID from the environment at launch, so a deploy can supply the release without a rebuild.

Precedence: an explicit option wins over the environment.

let options = ClientOptionsBuilder::default()
    .api_key(key)
    // Baked at build time; falls back to POSTHOG_RELEASE_ID at runtime when unset.
    .release_id(option_env!("POSTHOG_RELEASE_ID").unwrap_or_default())
    .build()?;

The server resolves each exception's release by a direct id lookup, so no release name or version has to match anything the app reports. Only $exception events carry the property — that is the only event the server resolves a release from. The value is resolved once per capture; an unset or blank value changes nothing; the property is set before before_send, so a hook can still drop it. No binary patching and no code signing.

Trade-off. Baking a different id per release changes the binary, so its debug id changes and each release gets its own symbol set (the runtime-env path keeps one binary and one symbol set across releases). Both are supported; pick per deployment — known-at-build-time favours baking, assigned-after-build favours the env var.

Contract: the release id is the UUID that posthog-cli release resolve prints. The CLI side is PostHog/posthog#89834: symbol-sets upload --release-mode=event uploads the symbols release-independent, and release resolve (already on master) names the release and prints its id.

This is a second, lighter alternative to the marker-injection approach in #237. The two are independent branches off main; pick one.

How did you test this code?

Automated (cargo test): unit tests for the value normalization (unset → none, blank → none, whitespace trimmed), the source precedence (explicit option beats the environment; environment used when the option is unset; none when neither is set), the event-name gate (a $release_id lands on an $exception, not on a $pageview, and not at all when unset), and that an explicit release_id option reaches the resolved capture defaults. cargo fmt --check and cargo clippy clean; the public-API snapshot is updated for the new setter.

End to end against a local PostHog stack, run by the agent (Claude). The rust-release-env example — a plain posthog-rs app with no release code of its own — is built against this branch. ./run resolves the release, builds with POSTHOG_RELEASE_ID set so option_env! bakes the id into the binary, uploads the symbols release-independent, and runs the binary with the runtime env unset — so the reported id can only have come from the build. It is shipped twice (1.0.0, 2.0.0) to show the release tracks the build.

posthog-cli — release resolve, then a release-independent symbol-sets upload of the baked build
# the release is named here; its id is baked into the binary at build time
$ posthog-cli release resolve --release-name rust-release-env --release-version 2.0.0
01a043c7-7d1a-0000-3834-390958992b49

# symbols, release-independent — no release name/version here (PostHog/posthog#89834)
# --include-source bundles the .rs files so frames show source context
$ posthog-cli symbol-sets upload --directory target/release --include-source --release-mode=event
INFO  Collected 1251 source files
INFO  Processing dSYM .../rust-release-env.dSYM (UUIDs: 3A474928-6A67-3E44-887A-5CBC62E95BAF)
INFO  --release-mode=event: uploading symbol sets release-independent; the release is carried on each exception as $release_id (POSTHOG_RELEASE_ID)
INFO  Upload summary: 1 chunk(s) uploaded, 0 skipped
the app, run with POSTHOG_RELEASE_ID unset — the id is already compiled in
$ unset POSTHOG_RELEASE_ID
$ ./target/release/rust-release-env
starting — release 01a043c7-7d1a-0000-3834-390958992b49 (baked into the binary at build time via option_env!)
stopping

Read back server-side (a dev-login session over the local API): one issue holds both builds, each $exception ($lib = posthog-rs) carries its baked $release_id, cymbal resolved it into a $exception_release, and the in-app frames symbolicate to source off the uploaded symbol set:

$lib               : posthog-rs
frames (in app)    : crash_site three.rs:5  two two.rs:6  one one.rs:6  main main.rs:41  — symbolicated, with source
1.0.0  $release_id 01a04245-8c54-0000-7530-28eed93002b0 → $exception_release rust-release-env@1.0.0
2.0.0  $release_id 01a043c7-7d1a-0000-3834-390958992b49 → $exception_release rust-release-env@2.0.0
Symbolicated stack trace, with Rust source context Release resolved via the baked $release_id
stack-trace release-resolved

The binary was run with nothing in its environment — the release id it reports was compiled in at build time. The same code shipped as 2.0.0 is a different baked id, resolving to a different release.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Authored by Claude in Claude Code, directed by @ablaszkiewicz (DRI). This is the SDK half of a second, env-variable-based approach to native release tracking, offered alongside the marker-injection pair (#237 + PostHog/posthog#89117) for comparison. The release_id client option (build-time baking, env var as fallback) was added in response to review feedback on this PR. The end-to-end verification above was run by the agent against a local PostHog dev stack (ingestion + cymbal), with screenshots uploaded via hogli pr:upload-image. The example data is invented (rust-release-env demo binary) and draws on no customer material.

🤖 Generated with Claude Code

Report a `$release_id` on every event when `POSTHOG_RELEASE_ID` is set in
the environment. This is the native, deploy-time counterpart to injecting
`$release_id` into a web bundle: a build tool runs `posthog-cli release
resolve` to create the release and print its id, launches the app with
that id in `POSTHOG_RELEASE_ID`, and the SDK stamps it on every event, so
the server resolves the exception's release by a direct id lookup — no
release name or version has to match anything the app reports.

The value is read once (cached), an unset or blank value changes nothing,
and it is set in `apply_capture_defaults` before before_send, so a hook
can still drop the property. No binary patching and no code signing,
unlike the marker-injection alternative.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

posthog-rs-v0 Compliance Report

Date: 2026-08-27 15:21:15 UTC
Duration: 15594ms

✅ All Tests Passed!

46/46 tests passed


Capture Tests

29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 139ms
Format Validation.Event Has Uuid 152ms
Format Validation.Event Has Lib Properties 140ms
Format Validation.Distinct Id Is String 148ms
Format Validation.Token Is Present 151ms
Format Validation.Custom Properties Preserved 151ms
Format Validation.Event Has Timestamp 150ms
Retry Behavior.Retries On 503 5155ms
Retry Behavior.Does Not Retry On 400 2152ms
Retry Behavior.Does Not Retry On 401 2152ms
Retry Behavior.Respects Retry After Header 5115ms
Retry Behavior.Implements Backoff 15120ms
Retry Behavior.Retries On 500 5112ms
Retry Behavior.Retries On 502 5104ms
Retry Behavior.Retries On 504 5104ms
Retry Behavior.Max Retries Respected 15108ms
Deduplication.Generates Unique Uuids 111ms
Deduplication.Preserves Uuid On Retry 5024ms
Deduplication.Preserves Uuid And Timestamp On Retry 10043ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 5036ms
Deduplication.No Duplicate Events In Batch 27ms
Deduplication.Different Events Have Different Uuids 23ms
Compression.Sends Gzip When Enabled 23ms
Batch Format.Uses Proper Batch Structure 22ms
Batch Format.Flush With No Events Sends Nothing 23ms
Batch Format.Multiple Events Batched Together 109ms
Error Handling.Does Not Retry On 403 2090ms
Error Handling.Does Not Retry On 413 2063ms
Error Handling.Retries On 408 5073ms

Feature_Flags Tests

17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 72ms
Request Payload.Flags Request Uses V2 Query Param 57ms
Request Payload.Flags Request Hits Flags Path Not Decide 34ms
Request Payload.Flags Request Omits Authorization Header 33ms
Request Payload.Token In Flags Body Matches Init 31ms
Request Payload.Groups Round Trip 39ms
Request Payload.Groups Default To Empty Object 39ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 62ms
Request Payload.Disable Geoip Omitted Defaults To False 41ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 42ms
Request Lifecycle.No Flags Request On Init Alone 19ms
Request Lifecycle.No Flags Request On Normal Capture 52ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 55ms
Request Lifecycle.Mock Response Value Is Returned To Caller 41ms
Retry Behavior.Retries Flags On 502 226ms
Retry Behavior.Retries Flags On 504 244ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 42ms

@github-actions

github-actions Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

posthog-rs-v1 Compliance Report

Date: 2026-08-27 15:21:26 UTC
Duration: 22961ms

✅ All Tests Passed!

111/111 tests passed


Capture_V1 Tests

94/94 tests passed

View Details
Test Status Duration
Endpoint And Method.Targets V1 Endpoint 149ms
Endpoint And Method.Does Not Use Legacy Endpoints 148ms
Required Headers.Has Authorization Bearer Header 147ms
Required Headers.Has Content Type Json 147ms
Required Headers.Has Posthog Sdk Info Format 146ms
Required Headers.Has Posthog Attempt Header 147ms
Required Headers.Has Posthog Request Id 146ms
Required Headers.Has Posthog Request Timestamp 148ms
Required Headers.Has User Agent 147ms
Body Format.Body Has Created At And Batch 151ms
Body Format.No Api Key In Body 137ms
Body Format.No Sent At In Body 137ms
Event Format.Event Has Required Root Fields 137ms
Event Format.Event Uuid Is Valid 141ms
Event Format.Event Timestamp Is Rfc3339 138ms
Event Format.Distinct Id Is String 137ms
Event Format.Distinct Id At Root Not Properties 136ms
Event Format.Custom Properties Preserved 136ms
Event Format.Set Properties Preserved 135ms
Event Format.Set Once Properties Preserved 132ms
Event Format.Groups Properties Preserved 125ms
Event Format.Sdk Generates Uuid If Not Provided 125ms
Event Format.Event Has Required Root Fields Batch 156ms
Event Format.Event Uuid Is Valid Batch 167ms
Event Format.Event Timestamp Is Rfc3339 Batch 144ms
Event Format.Distinct Id Is String Batch 144ms
Event Format.Distinct Id At Root Not Properties Batch 156ms
Event Format.Custom Properties Preserved Batch 156ms
Event Format.Set Properties Preserved Batch 144ms
Event Format.Set Once Properties Preserved Batch 140ms
Event Format.Groups Properties Preserved Batch 133ms
Event Format.Sdk Generates Uuid If Not Provided Batch 153ms
Batch Behavior.Multiple Events In Single Batch 197ms
Batch Behavior.Batch Envelope Smoke 162ms
Batch Behavior.Flush With No Events Sends Nothing 96ms
Batch Behavior.Flush At Triggers Batch 1133ms
Batch Behavior.Created At Reflects Batch Creation Time 101ms
Deduplication.Generates Unique Uuids 185ms
Deduplication.Different Events Same Content Different Uuids 141ms
Deduplication.Preserves Uuid On Retry 5114ms
Deduplication.Preserves Timestamp On Retry 5067ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 5102ms
Deduplication.No Duplicate Events In Batch 128ms
Header Behavior On Retry.Attempt Header Starts At One 72ms
Header Behavior On Retry.Attempt Header Increments On Retry 10059ms
Header Behavior On Retry.Request Id Preserved On Retry 5074ms
Header Behavior On Retry.Different Requests Have Different Request Ids 2060ms
Header Behavior On Retry.Request Timestamp Changes On Retry 5046ms
Response Format Validation.Success Response Has Uuid Keyed Results 58ms
Response Format Validation.Success Response Has Ok For Each Event 44ms
Response Format Validation.Success No Retry After When All Ok 27ms
Response Format Validation.Success Retry After Present When Retry Events 29ms
Response Format Validation.Success No Retry After When Drop Only 31ms
Response Format Validation.Response Echoes Request Id 25ms
Retry Behavior.Retries On 408 5031ms
Retry Behavior.Retries On 500 5025ms
Retry Behavior.Retries On 503 5026ms
Retry Behavior.Retries On 504 5026ms
Retry Behavior.Retryable Errors Have Retry After 2027ms
Retry Behavior.Respects Retry After On Retryable Error 8024ms
Retry Behavior.Does Not Retry On 400 2030ms
Retry Behavior.Does Not Retry On 401 2031ms
Retry Behavior.Does Not Retry On 402 2031ms
Retry Behavior.Does Not Retry On 413 2028ms
Retry Behavior.Does Not Retry On 415 2025ms
Retry Behavior.Non Retryable Errors Have No Retry After 2028ms
Retry Behavior.Implements Backoff 15031ms
Retry Behavior.Max Retries Respected 15026ms
Partial Batch Handling.Handles 200 Full Success 2032ms
Partial Batch Handling.Handles 200 With All Ok 3041ms
Partial Batch Handling.Does Not Retry Dropped Events 3037ms
Partial Batch Handling.Does Not Retry Limited Events 3034ms
Partial Batch Handling.Prunes Ok Events On Partial Retry 5035ms
Partial Batch Handling.Prunes Dropped Events On Partial Retry 5029ms
Partial Batch Handling.Retries Only Retry Events From Partial 5027ms
Partial Batch Handling.Partial Retry Preserves Uuids 5026ms
Partial Batch Handling.Partial Retry Attempt Header Increments 5030ms
Partial Batch Handling.Partial Retry Request Id Preserved 5032ms
Partial Batch Handling.Respects Retry After On Partial 5025ms
Partial Batch Handling.Unknown Result Treated As Terminal 3025ms
Partial Batch Handling.Mixed Ok Drop Limited No Retry 3028ms
Compression.Sends Gzip Content Encoding 23ms
Compression.No Content Encoding When Disabled 23ms
Compression.Compressed Body Is Decompressible 23ms
Error Handling.Does Not Retry On Unknown 4Xx 2025ms
Event Options.Cookieless Mode Override 25ms
Event Options.Disable Skew Correction Override 23ms
Event Options.Process Person Profile Override 22ms
Event Options.Product Tour Id Override 23ms
Event Options.Unset Options Omitted 23ms
Event Options.Options Override In Batch 23ms
Geoip And Historical Migration.Geoip Disable Injected Into Properties 22ms
Geoip And Historical Migration.Historical Migration Set In Body 23ms
Geoip And Historical Migration.Historical Migration Absent By Default 22ms

Feature_Flags Tests

17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 15ms
Request Payload.Flags Request Uses V2 Query Param 15ms
Request Payload.Flags Request Hits Flags Path Not Decide 16ms
Request Payload.Flags Request Omits Authorization Header 14ms
Request Payload.Token In Flags Body Matches Init 15ms
Request Payload.Groups Round Trip 14ms
Request Payload.Groups Default To Empty Object 16ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 16ms
Request Payload.Disable Geoip Omitted Defaults To False 14ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 15ms
Request Lifecycle.No Flags Request On Init Alone 11ms
Request Lifecycle.No Flags Request On Normal Capture 24ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 17ms
Request Lifecycle.Mock Response Value Is Returned To Caller 15ms
Retry Behavior.Retries Flags On 502 218ms
Retry Behavior.Retries Flags On 504 218ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 23ms

Scope the injected `$release_id` to `$exception` events. That is the only
event where the server resolves a release from `$release_id`, so a
pageview or a custom event does not need it. The insertion is split into
a small `apply_release_id` helper gated on the event name, so the rule is
unit-tested without the process-global `POSTHOG_RELEASE_ID` read.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ablaszkiewicz added a commit to PostHog/posthog that referenced this pull request Aug 27, 2026
Add `--release-mode` to `symbol-sets upload` (env `POSTHOG_RELEASE_MODE`).
The default `symbol-set` mode keeps binding the release to every uploaded
symbol set. `event` uploads the symbol sets release-independent — bound
to no release — so one symbol set serves every release of an unchanged
binary, and the upload no longer needs `--release-name`/`--release-version`.

In event mode the release rides the event as `$release_id`, which the SDK
reports from `POSTHOG_RELEASE_ID` (posthog-rs 0.26+, PostHog/posthog-rs#239);
the release is named with `posthog-cli release resolve`, whose id you pass
to the app. No binary patching and no code signing, unlike the injected
`--release-mode=event` variant.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@posthog

posthog Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

🦔 PostHog Review reviewed this pull request

Nothing worth raising this time, so here's a calming picture instead:

A panda relaxing and waving

posthog Bot added a commit to PostHog/posthog that referenced this pull request Aug 27, 2026
The runtime release-id section claimed posthog-rs and "other native SDKs"
read POSTHOG_RELEASE_ID, with no version gate. Only posthog-rs 0.26+ reads
it (PostHog/posthog-rs#239), and no other native SDK does today. State the
version gate the CLI help text and changeset already carry, and drop the
unverified multi-SDK claim.

Generated-By: PostHog Desktop
Task-Id: 81d53914-e1ab-4ecf-9740-da990f29d7dd
@ablaszkiewicz
ablaszkiewicz marked this pull request as ready for review August 27, 2026 12:09
@ablaszkiewicz
ablaszkiewicz requested a review from a team as a code owner August 27, 2026 12:09
@greptile-apps

greptile-apps Bot commented Aug 27, 2026

Copy link
Copy Markdown

Reviews (1): Last reviewed commit: "feat: report $release_id only on $except..." | Re-trigger Greptile

Comment thread src/release_env.rs
Comment on lines +15 to +20
pub(crate) fn release_id() -> Option<&'static str> {
static CACHE: OnceLock<Option<String>> = OnceLock::new();
CACHE
.get_or_init(|| normalize(std::env::var(RELEASE_ID_ENV).ok()))
.as_deref()
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be a proc macro? if we want to bake the env var into the binary at build time, this won't work

Comment thread src/release_env.rs
use std::sync::OnceLock;

/// The environment variable the release id is read from.
const RELEASE_ID_ENV: &str = "POSTHOG_RELEASE_ID";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a thought - we could fall back to attempting to derive a release id from the git HEAD (git rev-parse --verify 'HEAD^{commit}')

expecting cases where git is not found or we're not running in a .git repo

ablaszkiewicz and others added 2 commits August 27, 2026 17:07
…llback

Report $release_id from an explicit `release_id` client option in addition to
the POSTHOG_RELEASE_ID environment variable, so the release can be baked into
the binary at build time.

- New `ClientOptionsBuilder::release_id(...)`. Set it to
  `option_env!("POSTHOG_RELEASE_ID")` to bake the id in at build time, so a
  shipped binary self-identifies with nothing to set at runtime.
- The runtime env var remains the fallback when the option is unset, so a deploy
  can still supply the release without a rebuild.
- Precedence: an explicit option wins over the environment
  (release_env::resolve_release_id, unit-tested).
- Resolved once per capture into CaptureDefaults; still stamped only on
  $exception events; a before_send hook can still drop it.

Updates the public-API snapshot and the changeset.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…he env

resolve_release_id now trims the explicit option and treats a blank string as
unset, matching the environment path. This makes the ergonomic build-time
pattern `option_env!("POSTHOG_RELEASE_ID").unwrap_or_default()` safe: a build
that never set the variable passes an empty string, which now falls back to the
runtime POSTHOG_RELEASE_ID instead of stamping an empty $release_id.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@marandaneto
marandaneto requested a review from a team August 27, 2026 19:37
@marandaneto

Copy link
Copy Markdown
Member

i think we should expose the apps metadata as config, so users would know what to set eg app name, version, build and then we infer the release id in the backend, or even a human readable release identifier
its also ok to provide a release_id env. var. but its less user friendly

eg release = 'myapp@v1.0.0+1'
or app_name = myapp
version = v1.0.0
build =1
or release_git_sha = 'git sha'

this PR only exposes release_id which is a UUID that requires the posthog-cli in advance
just a suggestion, not a blocker

@ablaszkiewicz

Copy link
Copy Markdown
Author

Going to close this as I decided there is no point in migrating rust to the new release system. It always builds one chunk. Migration makes setup more complicated and gives no benefit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants