Repository navigation
fix(capture): keep $release_id on a minimized $feature_flag_called event - #1276
posthog[bot] wants to merge 1 commit into
Conversation
The capture spec's environment-sourced release identifier requirement says $release_id is a static, low-cardinality runtime identity property in the sense of the minimal flag-called allowlist, so a minimized $feature_flag_called event retains it when the SDK stamped it. The SDK stamped it in _enqueue and then stripped it, because the allowlist filter runs after the stamp and did not list the key. Add it next to the other runtime identity properties the allowlist already keeps. Generated-By: PostHog Desktop Task-Id: 700ce639-9125-4a88-a919-8a24ad6edf12
SDK performance: posthog-pythonBenchmarks completed. No changes flagged for review. Flags require at least a 5% change in the median and all six pairs agreeing on direction. This is a noise filter, not proof of a performance change or a CI gate. View all results
Values are medians of paired measurements. Not flagged does not mean unchanged. Unavailable means a measurement could not be provided, not zero. Estimated allocation measurements retain their instrumentation uncertainty. RSS measures the whole process, not just SDK allocations; observed peaks are sampled checkpoints. Paired ranges in the diagnostics describe variability, not confidence intervals. Each shard uses its own runner; compare Before PR against With PR within a row, not across shards. Compared 102 metric rows; 102 rows shown in all results. Omitted or shortened data remain in |
💡 Motivation and Context
Brings posthog-python's Capture contract into compliance with the
capturespec's "Environment-sourced release identifier" requirement insdk-specs:The spec's
@serverscenario "A minimized flag-called event keeps the release id" was failing. The compliance matrix note for this row records it as the single remaining gap on the contract:In practice: an app that sets
POSTHOG_RELEASE_IDgets$release_idon every event except its minimized flag-called events, so flag calls can't be broken down or filtered by release.🔨 What changed
$release_idis added to_MINIMAL_FLAG_CALLED_EVENT_PROPERTIESinposthog/client.py, alongside the$lib/$os/$python_*runtime identity properties already kept. The v2 allowlist derives from this set, so it is covered too.AsyncPosthogalready retained it (it applies the allowlist before filling SDK defaults), so no change was needed there.Nothing else about the minimal shape changes: an unset or blank
POSTHOG_RELEASE_IDstill sends no$release_idat all, and every other non-allowlisted property is still stripped.Backwards compatibility
Backward-compatible and additive. Minimized
$feature_flag_calledevents gain one static, low-cardinality property that the same client already sends on every other event; no public API, signature, or option changes, and no property is removed. Clients that never setPOSTHOG_RELEASE_IDsee no change at all.💚 How did you test it?
test_release_id.py: itstest_minimal_flag_called_events_keep_their_strict_allowlistasserted the pre-spec stripping behavior, so it now asserts that a minimized event keeps$release_idwhile still dropping non-allowlisted properties, plus a new case covering an unset release id.test_gated_non_experiment_flag_keeps_the_release_idtotest_feature_flag_called_minimization.py, which drives the realget_feature_flag_resultpath under the server-controlled minimization gate and asserts both the value and that the event stays within the allowlist.ruff format --check .,ruff check .,mypyon the changed module, and the fullpytestsuite. The only failures are 10 pre-existing AI-integration tests (posthog/test/ai/langchain,posthog/test/ai/openai) that need provider credentials/network in this sandbox; they are unrelated to this change.➡️ Follow-up work
Out of scope here, but noted while verifying:
AsyncPosthog._prepare_eventapplies the minimal allowlist before_fill_event_defaults, whileClient._enqueueapplies it after every enrichment step. Both satisfy this requirement today, but the orderings differ from each other and from the spec's "apply the allowlist after enrichment, beforebefore_send" ordering, so the async client's minimal events can retain SDK-filled properties the sync client drops. Worth a separate look.📝 Checklist
If releasing new changes
.sampo/changesets/release-id-on-minimized-flag-called.md)🤖 Agent context
Autonomy: Fully autonomous
Opened by a scheduled agent run that reads the SDK compliance matrices in
PostHog/sdk-specsand implements one open gap per run. This gap was picked over the other open posthog-python items because it is on a core, widely-used contract (Capture), its remediation is a one-line, strictly additive allowlist change with a matching spec scenario, and it had no in-flight PR or branch. Runner-up candidates considered and deferred: a publicget_distinct_id()(larger public API surface),before_sendhook chaining (spec frames it as optional), and HTTP 413 batch shrink-and-retry (also optional in the spec). The Flush retry gap was excluded outright — its compliance verdict is Breaking.Tools used: shell (git, ripgrep, pytest, ruff, mypy) and the GitHub CLI. No human directed this change, so the PR is left unassigned for the owning team to triage, and it needs human review before merge.
Created with PostHog Desktop