Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(cli): default release mode to event (#91823)

Aleksander Błaszkiewiczfb9ed9d8ec13
diff --git a/cli/.sampo/changesets/release-mode-event-default.md b/cli/.sampo/changesets/release-mode-event-default.md
new file mode 100644
index 000000000000..27a6353385d7
--- /dev/null
+++ b/cli/.sampo/changesets/release-mode-event-default.md
@@ -0,0 +1,7 @@
+---
+cargo/posthog-cli: minor
+---
+
+Default `--release-mode` to `event` for `sourcemap inject`, `sourcemap process`, `sourcemap upload`, `hermes inject`, `hermes clone` and `hermes upload`. Uploaded symbol sets and source maps are now release-independent, and each exception resolves its own release: a web build reads the `_posthogReleaseId` injected into the chunk, and a Hermes build resolves it from the `$app_namespace` / `$app_version` / `$app_build` the SDK already sends. Two releases that ship the same code keep one symbol set instead of colliding on the release that uploaded it first. Pass `--release-mode symbol-set` to keep binding the release to what you upload. Before upgrading, check that the release coordinates you pass match the app's bundle identifier or applicationId, version and build number, because a mismatch leaves exceptions with no release.
+
+`hermes upload` now resolves `--info-plist` before it checks the release coordinates. An iOS build that supplies them that way no longer gets a warning about a release the run creates correctly.
diff --git a/cli/src/sourcemaps/args.rs b/cli/src/sourcemaps/args.rs
index fe097ea9f983..2ace08ddfe0a 100644
--- a/cli/src/sourcemaps/args.rs
+++ b/cli/src/sourcemaps/args.rs
@@ -134,9 +134,11 @@ impl FileSelectionArgs {
/// How exceptions get associated with a release.
#[derive(clap::ValueEnum, Clone, Copy, Debug, PartialEq, Eq)]
pub enum ReleaseMode {
- /// Bind the release to the uploaded symbol sets (the previous behavior)
+ /// Bind the release to the uploaded symbol sets
SymbolSet,
- /// EXPERIMENTAL: resolve the release per event from an id injected into each chunk
+ /// Resolve the release per event (the default). A web build reads an id injected into the
+ /// chunk. A Hermes build injects nothing, and resolves the release from the app version and
+ /// namespace the SDK already sends
Event,
}
@@ -228,6 +230,16 @@ impl ReleaseArgs {
self.resolve_info_plist_with_environment(|name| std::env::var(name).ok())
}
+ /// Whether the coordinates identify a release an event can resolve.
+ ///
+ /// An event carries its own app metadata, and the server keys a release on the name and the
+ /// packed version. It packs the build into that version, so a release without a build matches
+ /// no event that sends `$app_build`. Call this on resolved args, because `--info-plist` fills
+ /// the same three fields.
+ pub fn event_coordinates_complete(&self) -> bool {
+ self.name.is_some() && self.version.is_some() && self.build.is_some()
+ }
+
fn resolve_info_plist_with_environment<F>(&self, environment: F) -> Result<Self>
where
F: Fn(&str) -> Option<String>,
@@ -363,6 +375,28 @@ mod tests {
}
}
+ #[test]
+ fn event_mode_needs_every_release_coordinate() {
+ // The server packs the build into the version it keys a release on, so a release without
+ // one matches no event that sends `$app_build`.
+ let cases = [
+ // name, version, build, complete
+ (Some("com.app"), Some("1.0"), Some("42"), true),
+ (Some("com.app"), Some("1.0"), None, false),
+ (Some("com.app"), None, Some("42"), false),
+ (None, Some("1.0"), Some("42"), false),
+ (None, None, None, false),
+ ];
+
+ for (name, version, build, complete) in cases {
+ assert_eq!(
+ make_args(name, version, build).event_coordinates_complete(),
+ complete,
+ "name={name:?} version={version:?} build={build:?}"
+ );
+ }
+ }
+
#[test]
fn release_args_to_builder() {
let cases: Vec<(Option<&str>, Option<&str>, bool)> = vec![
diff --git a/cli/src/sourcemaps/hermes/clone.rs b/cli/src/sourcemaps/hermes/clone.rs
index d7de5f43fed6..ed64447aaa53 100644
--- a/cli/src/sourcemaps/hermes/clone.rs
+++ b/cli/src/sourcemaps/hermes/clone.rs
@@ -25,17 +25,17 @@ pub struct CloneArgs {
#[clap(flatten)]
pub release: ReleaseArgs,
- /// How the release is associated with exceptions. `symbol-set` is the default. It stamps the
- /// release id into the source maps, so the upload binds the symbol set to that release.
- /// EXPERIMENTAL `event` stamps nothing and leaves the maps release-independent. Each event
- /// then resolves its own release from the app version and namespace the SDK already sends.
- /// The coordinates you pass to `hermes upload` must match the app's. Also settable via
+ /// How the release is associated with exceptions. `event` is the default. It stamps nothing
+ /// and leaves the maps release-independent. Each event then resolves its own release from the
+ /// app version and namespace the SDK already sends. The coordinates you pass to
+ /// `hermes upload` must match the app's. `symbol-set` stamps the release id into the source
+ /// maps instead, so the upload binds the symbol set to that release. Also settable via
/// `POSTHOG_RELEASE_MODE`.
#[arg(
long,
env = "POSTHOG_RELEASE_MODE",
value_enum,
- default_value = "symbol-set"
+ default_value = "event"
)]
pub release_mode: ReleaseMode,
}
diff --git a/cli/src/sourcemaps/hermes/mod.rs b/cli/src/sourcemaps/hermes/mod.rs
index 1bd0d6ccdf55..da1cbf3f5968 100644
--- a/cli/src/sourcemaps/hermes/mod.rs
+++ b/cli/src/sourcemaps/hermes/mod.rs
@@ -72,10 +72,10 @@ mod tests {
}
#[test]
- fn every_hermes_command_defaults_to_binding_the_release() {
- // Every existing React Native build omits the flag. Those builds must keep uploading
- // maps bound to their release. A different default here unbinds all of them, and
- // nothing in the build output says so.
+ fn every_hermes_command_defaults_to_event_release_mode() {
+ // A build that omits the flag must leave its maps release-independent, so two releases
+ // shipping the same JavaScript keep one symbol set instead of colliding on whichever
+ // release uploaded it first.
let HermesSubcommand::Clone(clone) = parse(&[
"hermes",
"clone",
@@ -86,17 +86,24 @@ mod tests {
]) else {
panic!("expected the clone subcommand");
};
- assert_eq!(clone.release_mode, ReleaseMode::SymbolSet);
+ assert_eq!(clone.release_mode, ReleaseMode::Event);
let HermesSubcommand::Upload(upload) = parse(&["hermes", "upload", "--directory", "dist"])
else {
panic!("expected the upload subcommand");
};
- assert_eq!(upload.release_mode, ReleaseMode::SymbolSet);
+ assert_eq!(upload.release_mode, ReleaseMode::Event);
+
+ // `hermes inject` shares InjectArgs with `sourcemap inject`, so it takes the same default.
+ let HermesSubcommand::Inject(inject) = parse(&["hermes", "inject", "--directory", "dist"])
+ else {
+ panic!("expected the inject subcommand");
+ };
+ assert_eq!(inject.release_mode, ReleaseMode::Event);
}
#[test]
- fn every_hermes_command_accepts_event_release_mode() {
+ fn every_hermes_command_accepts_symbol_set_release_mode() {
let HermesSubcommand::Clone(clone) = parse(&[
"hermes",
"clone",
@@ -105,11 +112,11 @@ mod tests {
"--composed-map-path",
"main.jsbundle.hbc.composed.map",
"--release-mode",
- "event",
+ "symbol-set",
]) else {
panic!("expected the clone subcommand");
};
- assert_eq!(clone.release_mode, ReleaseMode::Event);
+ assert_eq!(clone.release_mode, ReleaseMode::SymbolSet);
let HermesSubcommand::Upload(upload) = parse(&[
"hermes",
@@ -117,10 +124,22 @@ mod tests {
"--directory",
"dist",
"--release-mode",
- "event",
+ "symbol-set",
]) else {
panic!("expected the upload subcommand");
};
- assert_eq!(upload.release_mode, ReleaseMode::Event);
+ assert_eq!(upload.release_mode, ReleaseMode::SymbolSet);
+
+ let HermesSubcommand::Inject(inject) = parse(&[
+ "hermes",
+ "inject",
+ "--directory",
+ "dist",
+ "--release-mode",
+ "symbol-set",
+ ]) else {
+ panic!("expected the inject subcommand");
+ };
+ assert_eq!(inject.release_mode, ReleaseMode::SymbolSet);
}
}
diff --git a/cli/src/sourcemaps/hermes/upload.rs b/cli/src/sourcemaps/hermes/upload.rs
index ef3ff9c07c65..e55a95786311 100644
--- a/cli/src/sourcemaps/hermes/upload.rs
+++ b/cli/src/sourcemaps/hermes/upload.rs
@@ -27,17 +27,17 @@ pub struct Args {
#[clap(flatten)]
pub conflict: UploadConflictArgs,
- /// How the release is associated with exceptions. `symbol-set` is the default. It stamps the
- /// release id onto the uploaded maps. An exception then takes the release of the maps its
- /// frames resolved against. EXPERIMENTAL `event` leaves the maps release-independent. Each
- /// event then resolves its own release from the app version and namespace the SDK already
- /// sends, so the release coordinates must match the app's. Both modes create the release.
+ /// How the release is associated with exceptions. `event` is the default. It leaves the maps
+ /// release-independent. Each event then resolves its own release from the app version and
+ /// namespace the SDK already sends, so the release coordinates must match the app's.
+ /// `symbol-set` stamps the release id onto the uploaded maps instead, and an exception then
+ /// takes the release of the maps its frames resolved against. Both modes create the release.
/// Also settable via `POSTHOG_RELEASE_MODE`.
#[arg(
long,
env = "POSTHOG_RELEASE_MODE",
value_enum,
- default_value = "symbol-set"
+ default_value = "event"
)]
pub release_mode: ReleaseMode,
}
@@ -60,15 +60,16 @@ pub fn upload(args: &Args) -> Result<()> {
);
}
+ // `--info-plist` fills the same fields the check below reads, and it fills them here rather
+ // than inside `get_release_for_maps`. Checking the raw args warns about a missing release that
+ // the run goes on to create.
+ let release = release.resolve_info_plist()?;
+
// Event mode leaves nothing on the symbol set for the server to use. An exception then
// resolves its release only from the app metadata on the event. Coordinates that come from
// git instead of explicit flags do not match that metadata. The exception then reports no
- // release, and nothing in the output says so. The build number counts as a coordinate: the
- // server packs it into the version it keys on, so a release without one matches no event that
- // carries `$app_build`.
- if *release_mode == ReleaseMode::Event
- && (release.name.is_none() || release.version.is_none() || release.build.is_none())
- {
+ // release, and nothing in the output says so.
+ if *release_mode == ReleaseMode::Event && !release.event_coordinates_complete() {
warn!(
"--release-mode=event resolves each exception's release from the app's namespace and \
version. Pass --release-name, --release-version and --build matching the app's bundle \
diff --git a/cli/src/sourcemaps/inject.rs b/cli/src/sourcemaps/inject.rs
index e0857eb75532..d3ec1043abb5 100644
--- a/cli/src/sourcemaps/inject.rs
+++ b/cli/src/sourcemaps/inject.rs
@@ -28,17 +28,18 @@ pub struct InjectArgs {
#[clap(flatten)]
pub release: ReleaseArgs,
- /// How the release is associated with exceptions. `symbol-set` (the default) stamps the
- /// release id into the sourcemap so the uploaded symbol set is bound to it: the previous
- /// behavior. EXPERIMENTAL `event` injects the release id into each chunk as
- /// `_posthogReleaseId` so the SDK emits it on every exception, and derives
- /// content-addressed chunk ids that are stable across rebuilds. Also settable via
- /// `POSTHOG_RELEASE_MODE`.
+ /// How the release is associated with exceptions. `event` (the default) derives
+ /// content-addressed chunk ids that are stable across rebuilds. A web build also injects the
+ /// release id into each chunk as `_posthogReleaseId`, so the SDK emits it on every exception.
+ /// A Hermes build injects no release id, because a bytecode bundle cannot read one back out.
+ /// Each of its events resolves the release from the app version and namespace the SDK sends.
+ /// `symbol-set` stamps the release id into the sourcemap instead, so the uploaded symbol set
+ /// is bound to it. Also settable via `POSTHOG_RELEASE_MODE`.
#[arg(
long,
env = "POSTHOG_RELEASE_MODE",
value_enum,
- default_value = "symbol-set"
+ default_value = "event"
)]
pub release_mode: ReleaseMode,
}
diff --git a/cli/src/sourcemaps/plain/mod.rs b/cli/src/sourcemaps/plain/mod.rs
index cfe039ef8c37..519bb390acba 100644
--- a/cli/src/sourcemaps/plain/mod.rs
+++ b/cli/src/sourcemaps/plain/mod.rs
@@ -50,16 +50,16 @@ pub struct ProcessArgs {
#[clap(flatten)]
pub upload_concurrency: UploadConcurrencyArgs,
- /// How the release is associated with exceptions. `symbol-set` (the default) stamps the
- /// release id onto the uploaded symbol sets: the previous behavior. EXPERIMENTAL `event`
- /// injects the release id into each chunk as `_posthogReleaseId` (alongside
- /// content-addressed chunk ids) so the SDK reports the release per event; symbol sets stay
- /// release-independent. Also settable via `POSTHOG_RELEASE_MODE`.
+ /// How the release is associated with exceptions. `event` (the default) injects the release
+ /// id into each chunk as `_posthogReleaseId` (alongside content-addressed chunk ids) so the
+ /// SDK reports the release per event; symbol sets stay release-independent. `symbol-set`
+ /// stamps the release id onto the uploaded symbol sets instead. Also settable via
+ /// `POSTHOG_RELEASE_MODE`.
#[arg(
long,
env = "POSTHOG_RELEASE_MODE",
value_enum,
- default_value = "symbol-set"
+ default_value = "event"
)]
pub release_mode: ReleaseMode,
}
diff --git a/cli/src/sourcemaps/plain/upload.rs b/cli/src/sourcemaps/plain/upload.rs
index 83e63587cccc..dfb20b162155 100644
--- a/cli/src/sourcemaps/plain/upload.rs
+++ b/cli/src/sourcemaps/plain/upload.rs
@@ -69,16 +69,15 @@ pub struct Args {
#[arg(long)]
pub skip_ssl_verification: bool,
- /// How the release is associated with exceptions. `symbol-set` (the default) stamps the
- /// release id onto the uploaded symbol sets: the previous behavior. EXPERIMENTAL `event`
- /// leaves symbol sets unbound; the chunks already carry the release id in their injected
- /// snippet, so the release is resolved per event rather than per symbol set. Also settable
- /// via `POSTHOG_RELEASE_MODE`.
+ /// How the release is associated with exceptions. `event` (the default) leaves symbol sets
+ /// unbound; the chunks already carry the release id in their injected snippet, so the release
+ /// is resolved per event rather than per symbol set. `symbol-set` stamps the release id onto
+ /// the uploaded symbol sets instead. Also settable via `POSTHOG_RELEASE_MODE`.
#[arg(
long,
env = "POSTHOG_RELEASE_MODE",
value_enum,
- default_value = "symbol-set"
+ default_value = "event"
)]
pub release_mode: ReleaseMode,
}