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.

fix(capture): harden v1 against mistyped Event::Options fields (#66489)

Eli Reismana333c0062dc5
diff --git a/rust/capture/src/v1/analytics/constants.rs b/rust/capture/src/v1/analytics/constants.rs
index a1f0799cc8a7..2578bf7859a2 100644
--- a/rust/capture/src/v1/analytics/constants.rs
+++ b/rust/capture/src/v1/analytics/constants.rs
@@ -48,6 +48,9 @@ pub(super) const DETAIL_PERSON_PROCESSING_DISABLED: &str = "person_processing_di
/// Detail tag for events dropped by the event restriction service.
pub(super) const DETAIL_EVENT_RESTRICTION_DROP: &str = "event_restriction_drop";
+/// Detail tag for events dropped due to uncoercible options fields.
+pub(super) const DETAIL_INVALID_OPTIONS: &str = "invalid_options";
+
// ---------------------------------------------------------------------------
// Validation limits
// ---------------------------------------------------------------------------
diff --git a/rust/capture/src/v1/analytics/process.rs b/rust/capture/src/v1/analytics/process.rs
index f04ffa94ce6a..d99cedf9836e 100644
--- a/rust/capture/src/v1/analytics/process.rs
+++ b/rust/capture/src/v1/analytics/process.rs
@@ -10,11 +10,11 @@ use super::constants::{
CAPTURE_V1_EVENTS_REROUTED_HISTORICAL, CAPTURE_V1_EVENTS_RESTRICTED,
CAPTURE_V1_EVENT_ADJUSTMENTS_APPLIED, CAPTURE_V1_MAX_EVENT_NAME_LENGTH,
CAPTURE_V1_OVERFLOW_ROUTED, CAPTURE_V1_PARSED_EVENTS, CAPTURE_V1_PROCESSING_DURATION_SECONDS,
- CAPTURE_V1_RATE_LIMITER, DETAIL_EVENT_RESTRICTION_DROP, DETAIL_PERSON_PROCESSING_DISABLED,
- FUTURE_EVENT_HOURS_CUTOFF_MS, ILLEGAL_DISTINCT_IDS,
+ CAPTURE_V1_RATE_LIMITER, DETAIL_EVENT_RESTRICTION_DROP, DETAIL_INVALID_OPTIONS,
+ DETAIL_PERSON_PROCESSING_DISABLED, FUTURE_EVENT_HOURS_CUTOFF_MS, ILLEGAL_DISTINCT_IDS,
};
use super::response::BatchResponse;
-use super::types::{Batch, Event, EventResult, WrappedEvent};
+use super::types::{Batch, Event, EventResult, Options, WrappedEvent};
use crate::event_restrictions::{EventContext, EventRestrictionService};
use crate::global_rate_limiter::{GlobalRateLimitKey, GlobalRateLimiter};
use crate::v0_request::DataType;
@@ -287,8 +287,35 @@ fn validate_events(context: &RequestContext, batch: Batch) -> Result<Vec<Wrapped
match validate_event(&event) {
Ok(raw_ts) => {
+ // Options validation: coerce known fields or drop the event.
+ // The malformed-event metric (CAPTURE_V1_PARSED_EVENTS{malformed})
+ // is emitted uniformly by observe_malformed_events, matching the
+ // other validate-stage drops. Per-field detail is deferred to the
+ // sampled verbose-logging mode rather than logged per-event here.
+ let options = match event.options.validate() {
+ Ok(opts) => opts,
+ Err(_) => {
+ events.push(WrappedEvent {
+ event,
+ uuid,
+ options: Options::default(),
+ adjusted_timestamp: None,
+ result: EventResult::Drop,
+ details: Some(DETAIL_INVALID_OPTIONS),
+ destination,
+ force_disable_person_processing: false,
+ is_gateway_verified: false,
+ });
+ continue;
+ }
+ };
+
metrics::counter!(CAPTURE_V1_PARSED_EVENTS, "result" => "valid").increment(1);
- let adjusted = normalize_timestamp(context, &event, raw_ts);
+ let adjusted = normalize_timestamp(
+ context,
+ options.disable_skew_correction.unwrap_or(false),
+ raw_ts,
+ );
let illegal = is_distinct_id_illegal(&event.distinct_id);
if illegal {
illegal_distinct_id_count += 1;
@@ -296,6 +323,7 @@ fn validate_events(context: &RequestContext, batch: Batch) -> Result<Vec<Wrapped
events.push(WrappedEvent {
event,
uuid,
+ options,
adjusted_timestamp: Some(adjusted),
result: EventResult::Ok,
details: if illegal {
@@ -312,6 +340,7 @@ fn validate_events(context: &RequestContext, batch: Batch) -> Result<Vec<Wrapped
events.push(WrappedEvent {
event,
uuid,
+ options: Options::default(),
adjusted_timestamp: None,
result: EventResult::Drop,
details: Some(err.tag()),
@@ -404,10 +433,10 @@ fn validate_event(event: &Event) -> Result<DateTime<Utc>, Error> {
fn normalize_timestamp(
context: &RequestContext,
- event: &Event,
+ disable_skew_correction: bool,
raw_event_ts: DateTime<Utc>,
) -> DateTime<Utc> {
- if event.options.disable_skew_correction.unwrap_or(false) {
+ if disable_skew_correction {
return raw_event_ts;
}
@@ -636,7 +665,7 @@ mod tests {
Pipeline, Restriction, RestrictionManager, RestrictionScope, RestrictionType,
};
use crate::v1::analytics::constants::CAPTURE_V1_PATH;
- use crate::v1::analytics::types::{Batch, Event, Options};
+ use crate::v1::analytics::types::{Batch, Event};
use crate::v1::sinks::{Destination, DEFAULT_SCATTER_GATHER_MIN_BATCH};
use crate::v1::test_utils::{
self, find_by_did, malformed_wrapped_event, raw_obj, valid_event, wrapped_event,
@@ -1074,6 +1103,104 @@ mod tests {
assert_eq!(event.details, Some("malformed_event_properties"));
}
+ #[test]
+ fn validate_events_invalid_options_drops_single_event() {
+ use crate::v1::analytics::types::RawOptions;
+
+ let ctx = test_utils::test_context();
+ let mut good = valid_event();
+ good.uuid = "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d".to_string();
+
+ let mut bad = valid_event();
+ bad.uuid = "b1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5e".to_string();
+ bad.options = RawOptions(serde_json::json!({"cookieless_mode": [1, 2, 3]}));
+
+ let batch = Batch {
+ created_at: "2026-03-19T14:30:00.000Z".to_string(),
+ historical_migration: false,
+ capture_internal: None,
+ batch: vec![good, bad],
+ };
+ let events = validate_events(&ctx, batch).unwrap();
+ assert_eq!(events.len(), 2);
+
+ assert_eq!(events[0].result, EventResult::Ok);
+ assert_eq!(events[0].details, None);
+
+ assert_eq!(events[1].result, EventResult::Drop);
+ assert_eq!(events[1].details, Some("invalid_options"));
+ }
+
+ #[test]
+ fn validate_events_invalid_options_does_not_fail_batch() {
+ use crate::v1::analytics::types::RawOptions;
+
+ let ctx = test_utils::test_context();
+ let mut ev1 = valid_event();
+ ev1.uuid = "c1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5f".to_string();
+ ev1.options = RawOptions(serde_json::json!({"disable_skew_correction": "not_a_bool"}));
+
+ let mut ev2 = valid_event();
+ ev2.uuid = "d1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c60".to_string();
+ ev2.options = RawOptions(serde_json::json!({"disable_skew_correction": true}));
+
+ let batch = Batch {
+ created_at: "2026-03-19T14:30:00.000Z".to_string(),
+ historical_migration: false,
+ capture_internal: None,
+ batch: vec![ev1, ev2],
+ };
+ let result = validate_events(&ctx, batch);
+ assert!(result.is_ok());
+ let events = result.unwrap();
+ assert_eq!(events[0].result, EventResult::Drop);
+ assert_eq!(events[1].result, EventResult::Ok);
+ }
+
+ #[test]
+ fn validate_events_coerced_options_used_for_skew_correction() {
+ use crate::v1::analytics::types::RawOptions;
+
+ let ctx = test_utils::test_context();
+ let mut ev = valid_event();
+ ev.uuid = "e1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c61".to_string();
+ ev.options = RawOptions(serde_json::json!({"disable_skew_correction": 1}));
+
+ let batch = Batch {
+ created_at: "2026-03-19T14:30:00.000Z".to_string(),
+ historical_migration: false,
+ capture_internal: None,
+ batch: vec![ev],
+ };
+ let events = validate_events(&ctx, batch).unwrap();
+ assert_eq!(events[0].result, EventResult::Ok);
+ assert_eq!(events[0].options.disable_skew_correction, Some(true));
+ }
+
+ #[test]
+ fn validate_events_structural_error_takes_precedence_over_invalid_options() {
+ use crate::v1::analytics::types::RawOptions;
+
+ // An event with BOTH a structural error (empty event name) and
+ // uncoercible options must drop for the structural reason: options
+ // validation only runs after validate_event() passes.
+ let ctx = test_utils::test_context();
+ let mut ev = valid_event();
+ ev.uuid = "f1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c62".to_string();
+ ev.event = String::new();
+ ev.options = RawOptions(serde_json::json!({"cookieless_mode": [1, 2, 3]}));
+
+ let batch = Batch {
+ created_at: "2026-03-19T14:30:00.000Z".to_string(),
+ historical_migration: false,
+ capture_internal: None,
+ batch: vec![ev],
+ };
+ let events = validate_events(&ctx, batch).unwrap();
+ assert_eq!(events[0].result, EventResult::Drop);
+ assert_eq!(events[0].details, Some("missing_event_name"));
+ }
+
// --- normalize_timestamp ---
fn dt(s: &str) -> DateTime<Utc> {
@@ -1102,31 +1229,12 @@ mod tests {
}
}
- fn event_with_disable_skew_correction(disable: bool) -> Event {
- Event {
- event: "$pageview".to_string(),
- uuid: Uuid::new_v4().to_string(),
- distinct_id: "user-1".to_string(),
- timestamp: "2026-03-19T11:00:00Z".to_string(),
- session_id: None,
- window_id: None,
- options: Options {
- cookieless_mode: None,
- disable_skew_correction: Some(disable),
- product_tour_id: None,
- process_person_profile: None,
- },
- properties: raw_obj("{}"),
- }
- }
-
#[test]
fn normalize_no_skew() {
let now = dt("2026-03-19T12:00:00Z");
let ctx = ctx_with_skew(now, Duration::zero());
- let event = valid_event();
let event_ts = dt("2026-03-19T11:00:00Z");
- let result = normalize_timestamp(&ctx, &event, event_ts);
+ let result = normalize_timestamp(&ctx, false, event_ts);
assert_eq!(result, event_ts);
}
@@ -1134,9 +1242,8 @@ mod tests {
fn normalize_positive_skew_client_ahead() {
let now = dt("2026-03-19T12:00:00Z");
let ctx = ctx_with_skew(now, Duration::seconds(10));
- let event = valid_event();
let event_ts = dt("2026-03-19T11:00:00Z");
- let result = normalize_timestamp(&ctx, &event, event_ts);
+ let result = normalize_timestamp(&ctx, false, event_ts);
assert_eq!(result, dt("2026-03-19T10:59:50Z"));
}
@@ -1144,9 +1251,8 @@ mod tests {
fn normalize_negative_skew_client_behind() {
let now = dt("2026-03-19T12:00:00Z");
let ctx = ctx_with_skew(now, Duration::seconds(-10));
- let event = valid_event();
let event_ts = dt("2026-03-19T11:00:00Z");
- let result = normalize_timestamp(&ctx, &event, event_ts);
+ let result = normalize_timestamp(&ctx, false, event_ts);
assert_eq!(result, dt("2026-03-19T11:00:10Z"));
}
@@ -1154,9 +1260,8 @@ mod tests {
fn normalize_clamps_far_future() {
let now = dt("2026-03-19T12:00:00Z");
let ctx = ctx_with_skew(now, Duration::zero());
- let event = valid_event();
let event_ts = dt("2026-03-21T12:00:00Z");
- let result = normalize_timestamp(&ctx, &event, event_ts);
+ let result = normalize_timestamp(&ctx, false, event_ts);
assert_eq!(result, now);
}
@@ -1164,9 +1269,8 @@ mod tests {
fn normalize_allows_near_future() {
let now = dt("2026-03-19T12:00:00Z");
let ctx = ctx_with_skew(now, Duration::zero());
- let event = valid_event();
let event_ts = dt("2026-03-20T10:00:00Z");
- let result = normalize_timestamp(&ctx, &event, event_ts);
+ let result = normalize_timestamp(&ctx, false, event_ts);
assert_eq!(result, event_ts);
}
@@ -1174,9 +1278,8 @@ mod tests {
fn normalize_disable_skew_correction_skips_adjustment() {
let now = dt("2026-03-19T12:00:00Z");
let ctx = ctx_with_skew(now, Duration::seconds(10));
- let event = event_with_disable_skew_correction(true);
let event_ts = dt("2026-03-19T11:00:00Z");
- let result = normalize_timestamp(&ctx, &event, event_ts);
+ let result = normalize_timestamp(&ctx, true, event_ts);
assert_eq!(result, event_ts);
}
@@ -1184,9 +1287,8 @@ mod tests {
fn normalize_disable_skew_correction_false_still_adjusts() {
let now = dt("2026-03-19T12:00:00Z");
let ctx = ctx_with_skew(now, Duration::seconds(10));
- let event = event_with_disable_skew_correction(false);
let event_ts = dt("2026-03-19T11:00:00Z");
- let result = normalize_timestamp(&ctx, &event, event_ts);
+ let result = normalize_timestamp(&ctx, false, event_ts);
assert_eq!(result, dt("2026-03-19T10:59:50Z"));
}
@@ -3080,10 +3182,11 @@ mod tests {
let payload = batch_payload(&events);
let batch: Batch = serde_json::from_slice(&payload).unwrap();
assert_eq!(batch.batch.len(), 1);
- assert_eq!(batch.batch[0].options.cookieless_mode, None);
- assert_eq!(batch.batch[0].options.disable_skew_correction, None);
- assert_eq!(batch.batch[0].options.product_tour_id, None);
- assert_eq!(batch.batch[0].options.process_person_profile, None);
+ let opts = batch.batch[0].options.validate().unwrap();
+ assert_eq!(opts.cookieless_mode, None);
+ assert_eq!(opts.disable_skew_correction, None);
+ assert_eq!(opts.product_tour_id, None);
+ assert_eq!(opts.process_person_profile, None);
}
#[test]
@@ -3092,13 +3195,11 @@ mod tests {
let payload = batch_payload(&events);
let batch: Batch = serde_json::from_slice(&payload).unwrap();
assert_eq!(batch.batch.len(), 1);
- assert_eq!(batch.batch[0].options.cookieless_mode, Some(true));
- assert_eq!(batch.batch[0].options.disable_skew_correction, Some(true));
- assert_eq!(
- batch.batch[0].options.product_tour_id.as_deref(),
- Some("tour-v2")
- );
- assert_eq!(batch.batch[0].options.process_person_profile, Some(false));
+ let opts = batch.batch[0].options.validate().unwrap();
+ assert_eq!(opts.cookieless_mode, Some(true));
+ assert_eq!(opts.disable_skew_correction, Some(true));
+ assert_eq!(opts.product_tour_id.as_deref(), Some("tour-v2"));
+ assert_eq!(opts.process_person_profile, Some(false));
}
#[cfg(test)]
diff --git a/rust/capture/src/v1/analytics/response.rs b/rust/capture/src/v1/analytics/response.rs
index c1d77f86dcd7..407ecce7a3c4 100644
--- a/rust/capture/src/v1/analytics/response.rs
+++ b/rust/capture/src/v1/analytics/response.rs
@@ -160,7 +160,7 @@ mod tests {
use uuid::Uuid;
use super::*;
- use crate::v1::analytics::types::{Event, EventResult, Options, WrappedEvent};
+ use crate::v1::analytics::types::{Event, EventResult, Options, RawOptions, WrappedEvent};
use crate::v1::sinks::Destination;
use crate::v1::test_utils;
@@ -174,15 +174,11 @@ mod tests {
timestamp: "2026-03-19T14:29:58.123Z".to_string(),
session_id: None,
window_id: None,
- options: Options {
- cookieless_mode: None,
- disable_skew_correction: None,
- product_tour_id: None,
- process_person_profile: None,
- },
+ options: RawOptions::default(),
properties: serde_json::value::RawValue::from_string("{}".to_owned()).unwrap(),
},
uuid,
+ options: Options::default(),
adjusted_timestamp: Some(Utc::now()),
result,
details,
diff --git a/rust/capture/src/v1/analytics/types.rs b/rust/capture/src/v1/analytics/types.rs
index a7f67c387deb..f3a9308f79c2 100644
--- a/rust/capture/src/v1/analytics/types.rs
+++ b/rust/capture/src/v1/analytics/types.rs
@@ -5,6 +5,7 @@ use chrono::{DateTime, SecondsFormat, Utc};
use common_types::{CapturedEventHeaders, HasEventName};
use serde::{Deserialize, Serialize};
use serde_json::value::RawValue;
+use serde_json::Value;
use uuid::Uuid;
/// Safe adapter for writing serde_json output into a `String` buffer.
@@ -80,6 +81,110 @@ pub struct Options {
pub process_person_profile: Option<bool>,
}
+/// Deserialize-tolerant wrapper for event options. Accepts any JSON value so
+/// that a single mistyped field cannot fail batch deserialization.
+#[derive(Debug, Default, Clone, Deserialize, Serialize)]
+#[serde(transparent)]
+pub struct RawOptions(pub Value);
+
+/// Error produced when `RawOptions::validate` cannot coerce one or more fields.
+/// Carries the offending field names for logging; the wire/metric tag is the
+/// static `DETAIL_INVALID_OPTIONS` constant applied at the drop site.
+#[derive(Debug)]
+pub struct OptionsError {
+ pub invalid_fields: Vec<&'static str>,
+}
+
+impl RawOptions {
+ /// Validate and coerce raw JSON into typed Options.
+ ///
+ /// - Null/absent -> Ok(default)
+ /// - Object -> coerce each known key, ignore unknown, collect invalid fields
+ /// - Non-object -> Err with no field names
+ pub fn validate(&self) -> Result<Options, OptionsError> {
+ match &self.0 {
+ Value::Null => Ok(Options::default()),
+ Value::Object(map) => {
+ let mut opts = Options::default();
+ let mut invalid_fields: Vec<&'static str> = Vec::new();
+
+ if let Some(v) = map.get("cookieless_mode") {
+ if !v.is_null() {
+ match coerce_bool(v) {
+ Some(b) => opts.cookieless_mode = Some(b),
+ None => invalid_fields.push("cookieless_mode"),
+ }
+ }
+ }
+ if let Some(v) = map.get("disable_skew_correction") {
+ if !v.is_null() {
+ match coerce_bool(v) {
+ Some(b) => opts.disable_skew_correction = Some(b),
+ None => invalid_fields.push("disable_skew_correction"),
+ }
+ }
+ }
+ if let Some(v) = map.get("process_person_profile") {
+ if !v.is_null() {
+ match coerce_bool(v) {
+ Some(b) => opts.process_person_profile = Some(b),
+ None => invalid_fields.push("process_person_profile"),
+ }
+ }
+ }
+ if let Some(v) = map.get("product_tour_id") {
+ if !v.is_null() {
+ match coerce_string(v) {
+ Some(s) => opts.product_tour_id = Some(s),
+ None => invalid_fields.push("product_tour_id"),
+ }
+ }
+ }
+
+ if invalid_fields.is_empty() {
+ Ok(opts)
+ } else {
+ Err(OptionsError { invalid_fields })
+ }
+ }
+ _ => Err(OptionsError {
+ invalid_fields: Vec::new(),
+ }),
+ }
+ }
+}
+
+/// Coerce a JSON value to bool with conservative rules:
+/// - native bool passes through
+/// - strings "true"/"false"/"1"/"0" (trimmed, case-insensitive)
+/// - any nonzero number -> true, 0 -> false
+fn coerce_bool(v: &Value) -> Option<bool> {
+ match v {
+ Value::Bool(b) => Some(*b),
+ Value::String(s) => match s.trim().to_ascii_lowercase().as_str() {
+ "true" | "1" => Some(true),
+ "false" | "0" => Some(false),
+ _ => None,
+ },
+ Value::Number(n) => n.as_f64().map(|f| f != 0.0),
+ _ => None,
+ }
+}
+
+/// Coerce a JSON value to string:
+/// - native string passes through
+/// - integer number -> its decimal string representation
+fn coerce_string(v: &Value) -> Option<String> {
+ match v {
+ Value::String(s) => Some(s.clone()),
+ Value::Number(n) => n
+ .as_i64()
+ .map(|i| i.to_string())
+ .or_else(|| n.as_u64().map(|u| u.to_string())),
+ _ => None,
+ }
+}
+
#[derive(Debug, Deserialize)]
pub struct Event {
pub event: String,
@@ -94,7 +199,7 @@ pub struct Event {
pub session_id: Option<String>,
pub window_id: Option<String>,
#[serde(default)]
- pub options: Options,
+ pub options: RawOptions,
#[serde(default = "empty_raw_object")]
pub properties: Box<RawValue>,
}
@@ -104,6 +209,8 @@ pub struct WrappedEvent {
pub event: Event,
/// Pre-parsed UUID from Event.uuid, set once during validate_events.
pub uuid: Uuid,
+ /// Typed options coerced from Event.options during validate_events.
+ pub options: Options,
// Post-skew-adjustment timestamp for Kafka export, None if event is malformed
pub adjusted_timestamp: Option<DateTime<Utc>>,
pub result: EventResult,
@@ -196,7 +303,7 @@ impl SinkEvent for WrappedEvent {
use std::fmt::Write;
let mut buf = String::with_capacity(128);
match (
- self.event.options.cookieless_mode == Some(true),
+ self.options.cookieless_mode == Some(true),
ctx.capture_internal,
) {
(true, true) => {
@@ -248,7 +355,7 @@ impl SinkEvent for WrappedEvent {
token: &ctx.api_token,
event: &self.event.event,
timestamp,
- is_cookieless_mode: self.event.options.cookieless_mode.unwrap_or(false),
+ is_cookieless_mode: self.options.cookieless_mode.unwrap_or(false),
historical_migration: ctx.historical_migration,
};
@@ -285,16 +392,16 @@ impl WrappedEvent {
if let Some(ref wid) = self.event.window_id {
inject!(buf, first, "$window_id", wid);
}
- if let Some(cm) = self.event.options.cookieless_mode {
+ if let Some(cm) = self.options.cookieless_mode {
inject!(buf, first, "$cookieless_mode", &cm);
}
- if let Some(dsa) = self.event.options.disable_skew_correction {
+ if let Some(dsa) = self.options.disable_skew_correction {
inject!(buf, first, "$ignore_sent_at", &dsa);
}
- if let Some(ref pti) = self.event.options.product_tour_id {
+ if let Some(ref pti) = self.options.product_tour_id {
inject!(buf, first, "$product_tour_id", pti);
}
- if let Some(ppp) = self.event.options.process_person_profile {
+ if let Some(ppp) = self.options.process_person_profile {
inject!(buf, first, "$process_person_profile", &ppp);
}
@@ -356,8 +463,8 @@ impl WrappedEvent {
///
/// The v1 capture pipeline does not deserialize event.properties -- they are
/// forwarded as raw JSON to Kafka. Property checks here are limited to fields
-/// that have been promoted to the typed Event::Options struct. If a new quota
-/// limiter predicate needs a property not in Options, add it there first.
+/// that have been promoted to WrappedEvent.options. If a new quota limiter
+/// predicate needs a property not in Options, add it there first.
impl HasEventName for WrappedEvent {
fn event_name(&self) -> &str {
&self.event.event
@@ -365,7 +472,7 @@ impl HasEventName for WrappedEvent {
fn has_property(&self, key: &str) -> bool {
match key {
- "product_tour_id" => self.event.options.product_tour_id.is_some(),
+ "product_tour_id" => self.options.product_tour_id.is_some(),
_ => false,
}
}
@@ -699,10 +806,11 @@ mod tests {
let event = &batch.batch[0];
assert_eq!(event.session_id.as_deref(), Some("sess-abc"));
assert_eq!(event.window_id.as_deref(), Some("win-xyz"));
- assert_eq!(event.options.cookieless_mode, Some(true));
- assert_eq!(event.options.disable_skew_correction, Some(true));
- assert_eq!(event.options.product_tour_id.as_deref(), Some("tour-123"));
- assert_eq!(event.options.process_person_profile, Some(false));
+ let opts = event.options.validate().unwrap();
+ assert_eq!(opts.cookieless_mode, Some(true));
+ assert_eq!(opts.disable_skew_correction, Some(true));
+ assert_eq!(opts.product_tour_id.as_deref(), Some("tour-123"));
+ assert_eq!(opts.process_person_profile, Some(false));
}
#[test]
@@ -718,10 +826,11 @@ mod tests {
}"#;
let batch: Batch = serde_json::from_str(json).unwrap();
let event = &batch.batch[0];
- assert_eq!(event.options.cookieless_mode, None);
- assert_eq!(event.options.disable_skew_correction, None);
- assert_eq!(event.options.product_tour_id, None);
- assert_eq!(event.options.process_person_profile, None);
+ let opts = event.options.validate().unwrap();
+ assert_eq!(opts.cookieless_mode, None);
+ assert_eq!(opts.disable_skew_correction, None);
+ assert_eq!(opts.product_tour_id, None);
+ assert_eq!(opts.process_person_profile, None);
}
#[test]
@@ -740,10 +849,11 @@ mod tests {
let event = &batch.batch[0];
assert_eq!(event.session_id, None);
assert_eq!(event.window_id, None);
- assert_eq!(event.options.cookieless_mode, None);
- assert_eq!(event.options.disable_skew_correction, None);
- assert_eq!(event.options.product_tour_id, None);
- assert_eq!(event.options.process_person_profile, None);
+ let opts = event.options.validate().unwrap();
+ assert_eq!(opts.cookieless_mode, None);
+ assert_eq!(opts.disable_skew_correction, None);
+ assert_eq!(opts.product_tour_id, None);
+ assert_eq!(opts.process_person_profile, None);
}
#[test]
@@ -752,6 +862,157 @@ mod tests {
assert!(serde_json::from_slice::<Batch>(garbage).is_err());
}
+ // --- RawOptions::validate coercion matrix ---
+
+ #[test]
+ fn raw_options_null_validates_to_defaults() {
+ let raw = RawOptions::default();
+ let opts = raw.validate().unwrap();
+ assert_eq!(opts.cookieless_mode, None);
+ assert_eq!(opts.disable_skew_correction, None);
+ assert_eq!(opts.product_tour_id, None);
+ assert_eq!(opts.process_person_profile, None);
+ }
+
+ #[test]
+ fn raw_options_empty_object_validates_to_defaults() {
+ let raw = RawOptions(serde_json::json!({}));
+ let opts = raw.validate().unwrap();
+ assert_eq!(opts.cookieless_mode, None);
+ assert_eq!(opts.disable_skew_correction, None);
+ }
+
+ #[rstest::rstest]
+ #[case::native_true(serde_json::json!(true), Some(true))]
+ #[case::native_false(serde_json::json!(false), Some(false))]
+ #[case::str_true(serde_json::json!("true"), Some(true))]
+ #[case::str_false(serde_json::json!("false"), Some(false))]
+ #[case::str_one(serde_json::json!("1"), Some(true))]
+ #[case::str_zero(serde_json::json!("0"), Some(false))]
+ #[case::str_uppercase(serde_json::json!("FALSE"), Some(false))]
+ #[case::str_padded(serde_json::json!(" true "), Some(true))]
+ #[case::num_one(serde_json::json!(1), Some(true))]
+ #[case::num_zero(serde_json::json!(0), Some(false))]
+ #[case::num_large(serde_json::json!(42), Some(true))]
+ #[case::num_negative(serde_json::json!(-1), Some(true))]
+ fn raw_options_bool_coercion_valid(
+ #[case] input: serde_json::Value,
+ #[case] expected: Option<bool>,
+ ) {
+ let raw = RawOptions(serde_json::json!({ "cookieless_mode": input }));
+ assert_eq!(raw.validate().unwrap().cookieless_mode, expected);
+ }
+
+ #[rstest::rstest]
+ #[case::array(serde_json::json!([1, 2, 3]))]
+ #[case::object(serde_json::json!({"nested": true}))]
+ #[case::yes(serde_json::json!("yes"))]
+ #[case::off(serde_json::json!("off"))]
+ #[case::empty_string(serde_json::json!(""))]
+ fn raw_options_bool_uncoercible(#[case] input: serde_json::Value) {
+ let raw = RawOptions(serde_json::json!({ "cookieless_mode": input }));
+ let err = raw.validate().unwrap_err();
+ assert_eq!(err.invalid_fields, vec!["cookieless_mode"]);
+ }
+
+ #[test]
+ fn raw_options_all_bool_fields_routed_to_correct_slot() {
+ let raw = RawOptions(serde_json::json!({
+ "cookieless_mode": "true",
+ "disable_skew_correction": 0,
+ "process_person_profile": false
+ }));
+ let opts = raw.validate().unwrap();
+ assert_eq!(opts.cookieless_mode, Some(true));
+ assert_eq!(opts.disable_skew_correction, Some(false));
+ assert_eq!(opts.process_person_profile, Some(false));
+ }
+
+ #[rstest::rstest]
+ #[case::string(serde_json::json!("tour-123"), Some("tour-123"))]
+ #[case::integer(serde_json::json!(999), Some("999"))]
+ #[case::negative_integer(serde_json::json!(-5), Some("-5"))]
+ fn raw_options_product_tour_id_coercion_valid(
+ #[case] input: serde_json::Value,
+ #[case] expected: Option<&str>,
+ ) {
+ let raw = RawOptions(serde_json::json!({ "product_tour_id": input }));
+ assert_eq!(raw.validate().unwrap().product_tour_id.as_deref(), expected);
+ }
+
+ #[rstest::rstest]
+ #[case::object(serde_json::json!({"nested": true}))]
+ #[case::array(serde_json::json!(["a"]))]
+ #[case::bool(serde_json::json!(true))]
+ #[case::float(serde_json::json!(1.5))]
+ fn raw_options_product_tour_id_uncoercible(#[case] input: serde_json::Value) {
+ let raw = RawOptions(serde_json::json!({ "product_tour_id": input }));
+ let err = raw.validate().unwrap_err();
+ assert_eq!(err.invalid_fields, vec!["product_tour_id"]);
+ }
+
+ #[test]
+ fn raw_options_multiple_invalid_fields_collected() {
+ let raw = RawOptions(serde_json::json!({
+ "cookieless_mode": {"bad": true},
+ "disable_skew_correction": [false],
+ "product_tour_id": "valid-string",
+ "process_person_profile": null
+ }));
+ let err = raw.validate().unwrap_err();
+ assert!(err.invalid_fields.contains(&"cookieless_mode"));
+ assert!(err.invalid_fields.contains(&"disable_skew_correction"));
+ assert!(!err.invalid_fields.contains(&"product_tour_id"));
+ }
+
+ #[test]
+ fn raw_options_non_object_value_returns_error() {
+ let raw = RawOptions(serde_json::json!("just a string"));
+ let err = raw.validate().unwrap_err();
+ assert!(err.invalid_fields.is_empty());
+ }
+
+ #[test]
+ fn raw_options_unknown_fields_ignored() {
+ let raw = RawOptions(serde_json::json!({
+ "cookieless_mode": true,
+ "some_unknown_future_field": 42
+ }));
+ let opts = raw.validate().unwrap();
+ assert_eq!(opts.cookieless_mode, Some(true));
+ }
+
+ #[test]
+ fn raw_options_null_field_treated_as_absent() {
+ let raw = RawOptions(serde_json::json!({
+ "cookieless_mode": null,
+ "disable_skew_correction": true
+ }));
+ let opts = raw.validate().unwrap();
+ assert_eq!(opts.cookieless_mode, None);
+ assert_eq!(opts.disable_skew_correction, Some(true));
+ }
+
+ #[test]
+ fn batch_deserialization_survives_mistyped_options() {
+ let json = r#"{
+ "created_at": "2026-03-19T14:30:00.000Z",
+ "batch": [{
+ "event": "$pageview",
+ "uuid": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
+ "distinct_id": "user-42",
+ "timestamp": "2026-03-19T14:29:58.123Z",
+ "options": {"disable_skew_correction": 999, "cookieless_mode": "banana"}
+ }]
+ }"#;
+ let batch: Batch = serde_json::from_str(json).unwrap();
+ assert_eq!(batch.batch.len(), 1);
+ // 999 coerces to true (nonzero), "banana" does not coerce
+ let err = batch.batch[0].options.validate().unwrap_err();
+ assert!(err.invalid_fields.contains(&"cookieless_mode"));
+ assert!(!err.invalid_fields.contains(&"disable_skew_correction"));
+ }
+
// --- SinkEvent impl for WrappedEvent ---
use crate::v1::sinks::event::Event as SinkEventTrait;
@@ -949,7 +1210,7 @@ mod tests {
fn partition_key_cookieless_mode() {
let ctx = test_utils::test_context();
let mut ev = ok_wrapped("$pageview", "user-42");
- ev.event.options.cookieless_mode = Some(true);
+ ev.options.cookieless_mode = Some(true);
assert_eq!(
ev.partition_key(&ctx),
format!("{}:{}", ctx.api_token, ctx.client_ip)
@@ -961,7 +1222,7 @@ mod tests {
let mut ctx = test_utils::test_context();
ctx.capture_internal = true;
let mut ev = ok_wrapped("$pageview", "user-42");
- ev.event.options.cookieless_mode = Some(true);
+ ev.options.cookieless_mode = Some(true);
assert_eq!(
ev.partition_key(&ctx),
format!("{}:127.0.0.1", ctx.api_token)
@@ -999,7 +1260,7 @@ mod tests {
#[test]
fn has_property_product_tour_id_some() {
let mut ev = ok_wrapped("survey sent", "user-1");
- ev.event.options.product_tour_id = Some("tour-123".into());
+ ev.options.product_tour_id = Some("tour-123".into());
assert!(ev.has_property("product_tour_id"));
}
@@ -1051,17 +1312,18 @@ mod tests {
timestamp: "2026-03-19T14:29:58.123Z".to_string(),
session_id: Some("sess-01jq9abc".to_string()),
window_id: Some("win-xyz789".to_string()),
- options: Options {
- cookieless_mode: Some(false),
- disable_skew_correction: None,
- product_tour_id: None,
- process_person_profile: Some(true),
- },
+ options: RawOptions::default(),
properties: raw_obj(
r#"{"$current_url":"https://app.example.com/dashboard","$browser":"Chrome","custom_prop":42}"#,
),
},
uuid,
+ options: Options {
+ cookieless_mode: Some(false),
+ disable_skew_correction: None,
+ product_tour_id: None,
+ process_person_profile: Some(true),
+ },
adjusted_timestamp: Some(dt("2026-03-19T14:29:53.123Z")),
result: EventResult::Ok,
details: None,
@@ -1234,15 +1496,16 @@ mod tests {
timestamp: "2026-03-19T14:29:58.123Z".to_string(),
session_id: Some("sess-01jq9abc".to_string()),
window_id: Some("win-xyz789".to_string()),
- options: Options {
- cookieless_mode: Some(true),
- disable_skew_correction: Some(true),
- product_tour_id: Some("tour-onboarding-v2".to_string()),
- process_person_profile: Some(false),
- },
+ options: RawOptions::default(),
properties: raw_obj(r#"{"existing":"value"}"#),
},
uuid,
+ options: Options {
+ cookieless_mode: Some(true),
+ disable_skew_correction: Some(true),
+ product_tour_id: Some("tour-onboarding-v2".to_string()),
+ process_person_profile: Some(false),
+ },
adjusted_timestamp: Some(dt("2026-03-19T14:29:53.123Z")),
result: EventResult::Ok,
details: None,
@@ -1275,15 +1538,16 @@ mod tests {
timestamp: "2026-03-19T14:29:58.123Z".to_string(),
session_id: Some("sess-abc".to_string()),
window_id: None,
- options: Options {
- cookieless_mode: Some(false),
- disable_skew_correction: None,
- product_tour_id: None,
- process_person_profile: None,
- },
+ options: RawOptions::default(),
properties: raw_obj(r#"{"x":1}"#),
},
uuid,
+ options: Options {
+ cookieless_mode: Some(false),
+ disable_skew_correction: None,
+ product_tour_id: None,
+ process_person_profile: None,
+ },
adjusted_timestamp: Some(dt("2026-03-19T14:29:53.123Z")),
result: EventResult::Ok,
details: None,
@@ -1315,15 +1579,16 @@ mod tests {
timestamp: "2026-03-19T14:29:58.123Z".to_string(),
session_id: None,
window_id: None,
- options: Options {
- cookieless_mode: None,
- disable_skew_correction: None,
- product_tour_id: None,
- process_person_profile: None,
- },
+ options: RawOptions::default(),
properties: raw_obj("{}"),
},
uuid,
+ options: Options {
+ cookieless_mode: None,
+ disable_skew_correction: None,
+ product_tour_id: None,
+ process_person_profile: None,
+ },
adjusted_timestamp: Some(dt("2026-03-19T14:29:53.123Z")),
result: EventResult::Ok,
details: None,
@@ -1352,15 +1617,16 @@ mod tests {
timestamp: "2026-03-19T14:29:58.123Z".to_string(),
session_id: Some("sess-abc".to_string()),
window_id: None,
- options: Options {
- cookieless_mode: Some(true),
- disable_skew_correction: None,
- product_tour_id: None,
- process_person_profile: None,
- },
+ options: RawOptions::default(),
properties: raw_obj("{}"),
},
uuid,
+ options: Options {
+ cookieless_mode: Some(true),
+ disable_skew_correction: None,
+ product_tour_id: None,
+ process_person_profile: None,
+ },
adjusted_timestamp: Some(dt("2026-03-19T14:29:53.123Z")),
result: EventResult::Ok,
details: None,
@@ -1390,17 +1656,18 @@ mod tests {
timestamp: "2026-03-19T14:29:58.123Z".to_string(),
session_id: Some("sess-abc".to_string()),
window_id: None,
- options: Options {
- cookieless_mode: None,
- disable_skew_correction: None,
- product_tour_id: None,
- process_person_profile: None,
- },
+ options: RawOptions::default(),
properties: raw_obj(
r#"{"$lib":"posthog-js","$lib_version":"1.150.0","$referrer":"https://google.com"}"#,
),
},
uuid,
+ options: Options {
+ cookieless_mode: None,
+ disable_skew_correction: None,
+ product_tour_id: None,
+ process_person_profile: None,
+ },
adjusted_timestamp: Some(dt("2026-03-19T14:29:53.123Z")),
result: EventResult::Ok,
details: None,
@@ -1423,7 +1690,7 @@ mod tests {
#[test]
fn serialize_is_cookieless_mode_true() {
let mut wrapped = pageview_event();
- wrapped.event.options.cookieless_mode = Some(true);
+ wrapped.options.cookieless_mode = Some(true);
let ctx = serialize_ctx();
let (captured, data) = serialize_and_parse(&wrapped, &ctx);
assert!(captured.is_cookieless_mode);
@@ -1433,7 +1700,7 @@ mod tests {
#[test]
fn serialize_is_cookieless_mode_false_skipped() {
let wrapped = pageview_event();
- assert_eq!(wrapped.event.options.cookieless_mode, Some(false));
+ assert_eq!(wrapped.options.cookieless_mode, Some(false));
let ctx = serialize_ctx();
let buf = wrapped.serialize(&ctx).unwrap();
let val: Value = serde_json::from_slice(&buf).unwrap();
@@ -1492,7 +1759,7 @@ mod tests {
#[test]
fn serialize_process_person_profile_in_properties() {
let mut wrapped = pageview_event();
- wrapped.event.options.process_person_profile = Some(false);
+ wrapped.options.process_person_profile = Some(false);
wrapped.force_disable_person_processing = false;
let ctx = serialize_ctx();
let (_, data) = serialize_and_parse(&wrapped, &ctx);
@@ -1510,15 +1777,16 @@ mod tests {
timestamp: "2026-03-19T14:29:58.123Z".to_string(),
session_id: None,
window_id: None,
- options: Options {
- cookieless_mode: None,
- disable_skew_correction: None,
- product_tour_id: None,
- process_person_profile: None,
- },
+ options: RawOptions::default(),
properties: raw_obj(r#"{"x":1}"#),
},
uuid,
+ options: Options {
+ cookieless_mode: None,
+ disable_skew_correction: None,
+ product_tour_id: None,
+ process_person_profile: None,
+ },
adjusted_timestamp: Some(dt("2026-03-19T14:29:53.123Z")),
result: EventResult::Ok,
details: None,
@@ -1552,15 +1820,16 @@ mod tests {
timestamp: "2026-03-19T14:30:00.000Z".to_string(),
session_id: None,
window_id: None,
- options: Options {
- cookieless_mode: None,
- disable_skew_correction: None,
- product_tour_id: None,
- process_person_profile: Some(true),
- },
+ options: RawOptions::default(),
properties: raw_obj(r#"{"$browser":"Safari","$os":"macOS"}"#),
},
uuid,
+ options: Options {
+ cookieless_mode: None,
+ disable_skew_correction: None,
+ product_tour_id: None,
+ process_person_profile: Some(true),
+ },
adjusted_timestamp: Some(dt("2026-03-19T14:29:55.000Z")),
result: EventResult::Ok,
details: None,
@@ -1592,15 +1861,16 @@ mod tests {
timestamp: "2026-03-19T14:29:58.123Z".to_string(),
session_id: Some("sess-abc".to_string()),
window_id: None,
- options: Options {
- cookieless_mode: None,
- disable_skew_correction: None,
- product_tour_id: None,
- process_person_profile: None,
- },
+ options: RawOptions::default(),
properties: raw_obj("[1,2,3]"),
},
uuid,
+ options: Options {
+ cookieless_mode: None,
+ disable_skew_correction: None,
+ product_tour_id: None,
+ process_person_profile: None,
+ },
adjusted_timestamp: Some(dt("2026-03-19T14:29:53.123Z")),
result: EventResult::Ok,
details: None,
@@ -1628,15 +1898,16 @@ mod tests {
timestamp: "2026-03-19T14:29:58.123Z".to_string(),
session_id: Some("sess-abc".to_string()),
window_id: None,
- options: Options {
- cookieless_mode: None,
- disable_skew_correction: None,
- product_tour_id: None,
- process_person_profile: None,
- },
+ options: RawOptions::default(),
properties: raw_obj("{ }"),
},
uuid,
+ options: Options {
+ cookieless_mode: None,
+ disable_skew_correction: None,
+ product_tour_id: None,
+ process_person_profile: None,
+ },
adjusted_timestamp: Some(dt("2026-03-19T14:29:53.123Z")),
result: EventResult::Ok,
details: None,
@@ -1785,7 +2056,7 @@ mod tests {
fn partition_key_parity_cookieless() {
let ctx = serialize_ctx();
let mut ev = realistic_pageview("user-42");
- ev.event.options.cookieless_mode = Some(true);
+ ev.options.cookieless_mode = Some(true);
let key = ev.partition_key(&ctx);
assert_eq!(key, format!("{}:{}", ctx.api_token, ctx.client_ip));
}
diff --git a/rust/capture/src/v1/quota_limiter_shim.rs b/rust/capture/src/v1/quota_limiter_shim.rs
index 5b23b19c8f59..a3ac342114dd 100644
--- a/rust/capture/src/v1/quota_limiter_shim.rs
+++ b/rust/capture/src/v1/quota_limiter_shim.rs
@@ -113,7 +113,7 @@ mod tests {
use crate::config::EnvelopeCompression;
use crate::config::{CaptureMode, Config, KafkaConfig};
- use crate::v1::analytics::types::{Event, Options};
+ use crate::v1::analytics::types::{Event, Options, RawOptions};
fn test_config() -> Config {
Config {
@@ -300,15 +300,19 @@ mod tests {
timestamp: "2026-03-26T12:00:00.000Z".to_string(),
session_id: None,
window_id: None,
- options: Options {
- cookieless_mode: None,
- disable_skew_correction: None,
- product_tour_id: product_tour_id.map(String::from),
- process_person_profile: None,
+ options: match product_tour_id {
+ Some(id) => RawOptions(serde_json::json!({"product_tour_id": id})),
+ None => RawOptions::default(),
},
properties: RawValue::from_string("{}".to_owned()).unwrap(),
},
uuid,
+ options: Options {
+ cookieless_mode: None,
+ disable_skew_correction: None,
+ product_tour_id: product_tour_id.map(String::from),
+ process_person_profile: None,
+ },
adjusted_timestamp: Some(
DateTime::parse_from_rfc3339("2026-03-26T12:00:00Z")
.unwrap()
diff --git a/rust/capture/src/v1/sinks/kafka/sink_tests.rs b/rust/capture/src/v1/sinks/kafka/sink_tests.rs
index 0847f20dc851..0060f87f83bc 100644
--- a/rust/capture/src/v1/sinks/kafka/sink_tests.rs
+++ b/rust/capture/src/v1/sinks/kafka/sink_tests.rs
@@ -1051,7 +1051,7 @@ async fn realistic_window_id_injected_into_properties() {
async fn realistic_cookieless_partition_key() {
let h = TestHarness::new();
let mut wrapped = test_utils::wrapped_event("$pageview", "user-1");
- wrapped.event.options.cookieless_mode = Some(true);
+ wrapped.options.cookieless_mode = Some(true);
let events = prepared(&[&wrapped], &h.ctx);
let results = h.sink.publish_batch(&h.ctx, &events).await;
diff --git a/rust/capture/src/v1/test_utils.rs b/rust/capture/src/v1/test_utils.rs
index c57408c4a480..c2e2e5e92466 100644
--- a/rust/capture/src/v1/test_utils.rs
+++ b/rust/capture/src/v1/test_utils.rs
@@ -10,7 +10,7 @@ use uuid::Uuid;
use crate::v1::analytics::constants::CAPTURE_V1_PATH;
use crate::v1::analytics::context::Context as AnalyticsContext;
use crate::v1::analytics::query::Query;
-use crate::v1::analytics::types::{Event, EventResult, Options, WrappedEvent};
+use crate::v1::analytics::types::{Event, EventResult, Options, RawOptions, WrappedEvent};
use crate::v1::context::RequestContext;
use crate::v1::sinks::event::Event as SinkEvent;
use crate::v1::sinks::types::PreparedEvent;
@@ -36,15 +36,6 @@ pub fn raw_obj(s: &str) -> Box<RawValue> {
RawValue::from_string(s.to_owned()).unwrap()
}
-pub fn default_options() -> Options {
- Options {
- cookieless_mode: None,
- disable_skew_correction: None,
- product_tour_id: None,
- process_person_profile: None,
- }
-}
-
pub fn test_context() -> RequestContext {
RequestContext {
api_token: "phc_test_token".to_string(),
@@ -84,7 +75,7 @@ pub fn valid_event() -> Event {
timestamp: "2026-03-19T14:29:58.123Z".to_string(),
session_id: None,
window_id: None,
- options: default_options(),
+ options: RawOptions::default(),
properties: raw_obj("{}"),
}
}
@@ -99,10 +90,11 @@ pub fn wrapped_event(event_name: &str, distinct_id: &str) -> WrappedEvent {
timestamp: "2026-03-19T14:29:58.123Z".to_string(),
session_id: None,
window_id: None,
- options: default_options(),
+ options: RawOptions::default(),
properties: raw_obj("{}"),
},
uuid,
+ options: Options::default(),
adjusted_timestamp: Some(
DateTime::parse_from_rfc3339("2026-03-19T14:29:58.123Z")
.unwrap()
@@ -126,10 +118,11 @@ pub fn wrapped_event_at(timestamp: DateTime<Utc>) -> WrappedEvent {
timestamp: timestamp.to_rfc3339(),
session_id: None,
window_id: None,
- options: default_options(),
+ options: RawOptions::default(),
properties: raw_obj("{}"),
},
uuid,
+ options: Options::default(),
adjusted_timestamp: Some(timestamp),
result: EventResult::Ok,
details: None,
@@ -149,10 +142,11 @@ pub fn malformed_wrapped_event() -> WrappedEvent {
timestamp: "bad".to_string(),
session_id: None,
window_id: None,
- options: default_options(),
+ options: RawOptions::default(),
properties: raw_obj("{}"),
},
uuid,
+ options: Options::default(),
adjusted_timestamp: None,
result: EventResult::Drop,
details: Some("missing_event_name"),
@@ -201,17 +195,21 @@ pub fn realistic_pageview(distinct_id: &str) -> WrappedEvent {
timestamp: "2026-03-19T14:29:58.123Z".to_string(),
session_id: Some("01jq9abc-def0-1234-5678-9abcdef01234".to_string()),
window_id: Some("01jq9xyz-0000-4321-8765-fedcba987654".to_string()),
- options: Options {
- cookieless_mode: Some(false),
- disable_skew_correction: None,
- product_tour_id: None,
- process_person_profile: Some(true),
- },
+ options: RawOptions(serde_json::json!({
+ "cookieless_mode": false,
+ "process_person_profile": true
+ })),
properties: raw_obj(
r#"{"$current_url":"https://app.example.com/dashboard","$referrer":"https://google.com","$browser":"Chrome","$browser_version":"120.0","$os":"Mac OS X","$lib":"posthog-js","$lib_version":"1.150.0","custom_prop":42}"#,
),
},
uuid,
+ options: Options {
+ cookieless_mode: Some(false),
+ disable_skew_correction: None,
+ product_tour_id: None,
+ process_person_profile: Some(true),
+ },
adjusted_timestamp: Some(
DateTime::parse_from_rfc3339("2026-03-19T14:29:53.123Z")
.unwrap()
@@ -236,17 +234,20 @@ pub fn realistic_identify(distinct_id: &str) -> WrappedEvent {
timestamp: "2026-03-19T14:30:01.000Z".to_string(),
session_id: Some("01jq9abc-def0-1234-5678-9abcdef01234".to_string()),
window_id: None,
- options: Options {
- cookieless_mode: None,
- disable_skew_correction: None,
- product_tour_id: None,
- process_person_profile: Some(true),
- },
+ options: RawOptions(serde_json::json!({
+ "process_person_profile": true
+ })),
properties: raw_obj(
r#"{"$set":{"email":"[email protected]","name":"Test User"},"$set_once":{"created_at":"2026-01-01"},"$browser":"Safari","$os":"iOS"}"#,
),
},
uuid,
+ options: Options {
+ cookieless_mode: None,
+ disable_skew_correction: None,
+ product_tour_id: None,
+ process_person_profile: Some(true),
+ },
adjusted_timestamp: Some(
DateTime::parse_from_rfc3339("2026-03-19T14:29:56.000Z")
.unwrap()
@@ -271,17 +272,20 @@ pub fn realistic_custom(distinct_id: &str, event_name: &str) -> WrappedEvent {
timestamp: "2026-03-19T14:30:05.500Z".to_string(),
session_id: Some("01jq9abc-def0-1234-5678-9abcdef01234".to_string()),
window_id: Some("01jq9xyz-0000-4321-8765-fedcba987654".to_string()),
- options: Options {
- cookieless_mode: None,
- disable_skew_correction: None,
- product_tour_id: None,
- process_person_profile: Some(true),
- },
+ options: RawOptions(serde_json::json!({
+ "process_person_profile": true
+ })),
properties: raw_obj(
r#"{"button_id":"cta-signup","$current_url":"https://app.example.com/pricing"}"#,
),
},
uuid,
+ options: Options {
+ cookieless_mode: None,
+ disable_skew_correction: None,
+ product_tour_id: None,
+ process_person_profile: Some(true),
+ },
adjusted_timestamp: Some(
DateTime::parse_from_rfc3339("2026-03-19T14:30:00.500Z")
.unwrap()
@@ -349,12 +353,10 @@ pub fn realistic_dup_uuid_pair() -> (Event, Event) {
timestamp: "2026-03-19T14:29:58.123Z".to_string(),
session_id: Some("01jq9abc-def0-1234-5678-9abcdef01234".to_string()),
window_id: Some("01jq9xyz-0000-4321-8765-fedcba987654".to_string()),
- options: Options {
- cookieless_mode: Some(false),
- disable_skew_correction: None,
- product_tour_id: None,
- process_person_profile: Some(true),
- },
+ options: RawOptions(serde_json::json!({
+ "cookieless_mode": false,
+ "process_person_profile": true
+ })),
properties: raw_obj(r#"{"$current_url":"https://app.example.com/dashboard"}"#),
};
let second = Event {
@@ -364,7 +366,7 @@ pub fn realistic_dup_uuid_pair() -> (Event, Event) {
timestamp: "2026-03-19T14:30:01.000Z".to_string(),
session_id: Some("01jq9abc-def0-1234-5678-9abcdef01234".to_string()),
window_id: None,
- options: default_options(),
+ options: RawOptions::default(),
properties: raw_obj(r#"{"$set":{"email":"[email protected]"}}"#),
};
(first, second)
@@ -517,12 +519,12 @@ pub fn event_with_all_options() -> Event {
timestamp: "2026-03-19T14:29:58.123Z".to_string(),
session_id: Some("sess-all".to_string()),
window_id: Some("win-all".to_string()),
- options: Options {
- cookieless_mode: Some(true),
- disable_skew_correction: Some(true),
- product_tour_id: Some("tour-v2".to_string()),
- process_person_profile: Some(false),
- },
+ options: RawOptions(serde_json::json!({
+ "cookieless_mode": true,
+ "disable_skew_correction": true,
+ "product_tour_id": "tour-v2",
+ "process_person_profile": false
+ })),
properties: raw_obj(r#"{"existing":"prop"}"#),
}
}
@@ -536,7 +538,7 @@ pub fn event_with_empty_options() -> Event {
timestamp: "2026-03-19T14:29:58.123Z".to_string(),
session_id: None,
window_id: None,
- options: default_options(),
+ options: RawOptions::default(),
properties: raw_obj("{}"),
}
}
diff --git a/rust/capture/tests/v1_sink_integration.rs b/rust/capture/tests/v1_sink_integration.rs
index 0e0747aaf1fb..fbc0b3bec0a6 100644
--- a/rust/capture/tests/v1_sink_integration.rs
+++ b/rust/capture/tests/v1_sink_integration.rs
@@ -304,7 +304,7 @@ async fn v1_cookieless_mode_partition_key() -> Result<()> {
let mut wrapped = test_utils::realistic_pageview("integ-user-cookieless");
wrapped.uuid = uuid;
wrapped.event.uuid = uuid.to_string();
- wrapped.event.options.cookieless_mode = Some(true);
+ wrapped.options.cookieless_mode = Some(true);
let events: Vec<&(dyn Event + Send + Sync)> = vec![&wrapped];
let results = sink.publish_batch(&ctx, &prepared(&events, &ctx)).await;
@@ -335,7 +335,7 @@ async fn v1_all_options_property_injection() -> Result<()> {
let mut wrapped = test_utils::realistic_pageview("integ-user-all-opts");
wrapped.uuid = uuid;
wrapped.event.uuid = uuid.to_string();
- wrapped.event.options = capture::v1::analytics::types::Options {
+ wrapped.options = capture::v1::analytics::types::Options {
cookieless_mode: Some(true),
disable_skew_correction: Some(true),
product_tour_id: Some("tour_abc123".to_string()),
@@ -378,7 +378,7 @@ async fn v1_empty_options_no_injection() -> Result<()> {
let mut wrapped = test_utils::realistic_pageview("integ-user-no-opts");
wrapped.uuid = uuid;
wrapped.event.uuid = uuid.to_string();
- wrapped.event.options = capture::v1::analytics::types::Options {
+ wrapped.options = capture::v1::analytics::types::Options {
cookieless_mode: None,
disable_skew_correction: None,
product_tour_id: None,