: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(cymbal): route resolution by symbol set (#69434)
Hugues Pouillot6b01fe2d0734
diff --git a/rust/cymbal/README.md b/rust/cymbal/README.mdindex a0b711d2bfcd..3352c4310d15 100644--- a/rust/cymbal/README.md+++ b/rust/cymbal/README.md@@ -18,14 +18,16 @@ rollout, configuration, and operator guidance.The public HTTP contract stays `POST /process`: callers send an array ofevents and receive an equally sized array in the same order, with `null` in aslot only when the normal cymbal pipeline suppresses that event. The-Node.js error-tracking consumer can keep using its existing DNS/team routing+Node.js error-tracking consumer can keep using its existing DNS routingand HTTP body-size chunking because remote symbol resolution happens behindthe same cymbal HTTP boundary.When remote resolution is enabled, `CYMBAL_REMOTE_RESOLUTION_SAMPLE_RATE`controls a deterministic event-level rollout. Events selected for remote-processing are grouped per team, flattened into exception-level `ResolveItem`s,-and submitted over a bidirectional `Resolve` stream. Each item carries JSON+processing are flattened into exception-level `ResolveItem`s, grouped by a+symbol-set routing key when one is available, and submitted over a+bidirectional `Resolve` stream. Items without a symbol-set reference fall back+to the existing per-team key. Each item carries JSON`metadata` bytes for resolver-specific context such as`debug_images_json`, and each terminal `ResolveOutcome` is correlated byitem id. Sampled remote attempts do not fall back to local resolution if thediff --git a/rust/cymbal/docs/compatibility.md b/rust/cymbal/docs/compatibility.mdindex 33738a528191..f8fdf51b5f83 100644--- a/rust/cymbal/docs/compatibility.md+++ b/rust/cymbal/docs/compatibility.md@@ -27,7 +27,7 @@ No generated type changes are needed:- `CYMBAL_REMOTE_RESOLUTION_SAMPLE_RATE` deterministically chooses remote vs local resolution per event.- Sampled events use the remote pool and do not silently fall back to local resolution on remote failures.- Unsampled events use the local exception and frame resolvers.-- Sampled remote exceptions are grouped per team, flattened into `ResolveItem`s, and submitted over per-endpoint bidirectional `Resolve` streams.+- Sampled remote events are flattened into exception-level `ResolveItem`s. Items are grouped by their first symbol-set reference when available, with a per-team fallback, then submitted over per-endpoint bidirectional `Resolve` streams.- Resolver-specific context is carried in `ResolveItem.metadata` as JSON bytes. The native symbolication convention uses a `debug_images_json` key.- Per-item `ResolveOutcome.Error.kind` is the control-flow surface. `ERROR_KIND_OVERLOADED` is result-only backpressure and triggers item reroute. Accepted items emit `ResolveOutcome.Accepted` before their terminal outcome; cymbal releases its routing permit on that acceptance signal. If `CYMBAL_REMOTE_RESOLUTION_OVERLOAD_EJECTION_MS` is non-zero, the overloaded endpoint is also temporarily excluded from new routing in that cymbal process. Repeated overloads double that cooldown up to `CYMBAL_REMOTE_RESOLUTION_OVERLOAD_EJECTION_MAX_MS`, and a quiet `CYMBAL_REMOTE_RESOLUTION_OVERLOAD_EJECTION_DECAY_MS` window resets it. `CYMBAL_REMOTE_RESOLUTION_ROUTING_JITTER` controls how much routing flattens across the load-adjusted rendezvous-ranked candidate list (`0.0` strict top load-adjusted candidate, `1.0` load-weighted across candidates). `LoadEvent` carries endpoint freshness/draining state plus `in_flight` / `max_in_flight` as a soft routing load signal.diff --git a/rust/cymbal/src/modes/processing/stages/resolution/remote/resolver.rs b/rust/cymbal/src/modes/processing/stages/resolution/remote/resolver.rsindex 6d67b477cf04..62b660837872 100644--- a/rust/cymbal/src/modes/processing/stages/resolution/remote/resolver.rs+++ b/rust/cymbal/src/modes/processing/stages/resolution/remote/resolver.rs@@ -1,3 +1,4 @@+use std::collections::BTreeMap;use std::sync::Arc;use std::time::{Duration, Instant};@@ -23,7 +24,7 @@ mod chunk;mod partition;mod retry;-use chunk::group_events_by_key;+use chunk::routing_keys_for_event;use partition::partition_batch;use retry::resolve_work_item;@@ -56,8 +57,9 @@ impl RemoteResolutionContext {/// Flow:/// 1. Partition the batch into errored / empty-passthrough / local / remote./// 2. Resolve local events inline (same path as no-remote mode).-/// 3. Group remote events by routing key, submit one logical work item per-/// exception, and let each item reroute independently through the mux.+/// 3. Build one logical work item per exception, grouped by routing key for+/// deterministic submission, and let each item reroute independently+/// through the mux./// 4. Assemble back into the original batch order.////// Each event passes through exactly one bucket and writes itself into the@@ -256,27 +258,31 @@ fn build_work_items(events: Vec<RemoteEvent>,) -> Result<(Vec<RemoteEventSlot>, Vec<RemoteWorkItem>), UnhandledError> {let mut event_slots = Vec::new();- let mut work_items = Vec::new();+ let mut work_items_by_key: BTreeMap<String, Vec<RemoteWorkItem>> = BTreeMap::new();let mut next_token = 1u64;- for (routing_key, events_for_key) in group_events_by_key(events) {- for event in events_for_key {- let event_slot = event_slots.len();- let item_count = event.item_count();- let team_id = event.evt.team_id;-- for (exception_slot, exception_json) in- event.exception_jsons.iter().cloned().enumerate()- {- let token = next_token;- next_token = next_token.checked_add(1).ok_or_else(|| {- UnhandledError::Other(- "remote resolution work item token overflowed".to_string(),- )- })?;- work_items.push(RemoteWorkItem {+ for event in events {+ let event_slot = event_slots.len();+ let item_count = event.item_count();+ let team_id = event.evt.team_id;+ let routing_keys = routing_keys_for_event(&event.evt);++ for (exception_slot, exception_json) in event.exception_jsons.iter().cloned().enumerate() {+ let routing_key = routing_keys.get(exception_slot).cloned().ok_or_else(|| {+ UnhandledError::Other(format!(+ "remote resolution missing routing key for event slot {event_slot} exception slot {exception_slot}",+ ))+ })?;+ let token = next_token;+ next_token = next_token.checked_add(1).ok_or_else(|| {+ UnhandledError::Other("remote resolution work item token overflowed".to_string())+ })?;+ work_items_by_key+ .entry(routing_key.clone())+ .or_default()+ .push(RemoteWorkItem {token,- routing_key: routing_key.clone(),+ routing_key,event_slot,exception_slot,item: ResolveItem {@@ -287,16 +293,17 @@ fn build_work_items(deadline_ms: 0,},});- }-- event_slots.push(RemoteEventSlot {- batch_index: event.batch_index,- evt: event.evt,- resolved: (0..item_count).map(|_| None).collect(),- });}++ event_slots.push(RemoteEventSlot {+ batch_index: event.batch_index,+ evt: event.evt,+ resolved: (0..item_count).map(|_| None).collect(),+ });}+ let work_items = work_items_by_key.into_values().flatten().collect();+Ok((event_slots, work_items))}@@ -314,28 +321,98 @@ mod tests {assert_eq!(event_slots.len(), 2);assert_eq!(work_items.len(), 3);+ let mut tokens = work_items.iter().map(|item| item.token).collect::<Vec<_>>();+ tokens.sort_unstable();+ assert_eq!(tokens, vec![1, 2, 3]);assert_eq!(- work_items.iter().map(|item| item.token).collect::<Vec<_>>(),- vec![1, 2, 3]+ work_items+ .iter()+ .map(|item| item.routing_key.as_str())+ .collect::<Vec<_>>(),+ vec!["team:1", "team:2", "team:2"]);assert_eq!(work_items.iter().map(|item| (item.event_slot, item.exception_slot)).collect::<Vec<_>>(),- vec![(0, 0), (1, 0), (1, 1)]+ vec![(1, 0), (0, 0), (0, 1)]);assert!(work_items.iter().all(|item| item.item.deadline_ms == 0));}+ #[test]+ fn build_work_items_routes_each_exception_by_symbol_set_ref() {+ let events = vec![fake_remote_event_from_exceptions(+ 7,+ 3,+ vec![+ json!({+ "type": "Error",+ "value": "boom-b",+ "stacktrace": {+ "type": "raw",+ "frames": [{+ "platform": "web:javascript",+ "filename": "https://example.com/app-b.js",+ "function": "minified",+ "lineno": 1,+ "colno": 2,+ "chunk_id": "chunk-b"+ }]+ }+ }),+ json!({+ "type": "Error",+ "value": "boom-a",+ "stacktrace": {+ "type": "raw",+ "frames": [{+ "platform": "web:javascript",+ "filename": "https://example.com/app-a.js",+ "function": "minified",+ "lineno": 1,+ "colno": 2,+ "chunk_id": "chunk-a"+ }]+ }+ }),+ ],+ )];++ let (_event_slots, work_items) = build_work_items(events).expect("build work items");++ assert_eq!(+ work_items+ .iter()+ .map(|item| (item.exception_slot, item.routing_key.as_str()))+ .collect::<Vec<_>>(),+ vec![(1, "team:7:symbol:chunk-a"), (0, "team:7:symbol:chunk-b"),]+ );+ }+fn fake_remote_event(team_id: i32, batch_index: usize, n_exceptions: usize) -> RemoteEvent {+ fake_remote_event_from_exceptions(+ team_id,+ batch_index,+ (0..n_exceptions)+ .map(|i| {+ json!({+ "type": "Error",+ "value": format!("boom-{i}"),+ })+ })+ .collect(),+ )+ }++ fn fake_remote_event_from_exceptions(+ team_id: i32,+ batch_index: usize,+ exceptions: Vec<serde_json::Value>,+ ) -> RemoteEvent {let mut evt: ExceptionProperties = serde_json::from_value(json!({- "$exception_list": (0..n_exceptions)- .map(|i| json!({- "type": "Error",- "value": format!("boom-{i}"),- }))- .collect::<Vec<_>>()+ "$exception_list": exceptions,})).expect("valid exception properties");evt.team_id = team_id;diff --git a/rust/cymbal/src/modes/processing/stages/resolution/remote/resolver/chunk.rs b/rust/cymbal/src/modes/processing/stages/resolution/remote/resolver/chunk.rsindex 446949eeaf4f..060ae3625af4 100644--- a/rust/cymbal/src/modes/processing/stages/resolution/remote/resolver/chunk.rs+++ b/rust/cymbal/src/modes/processing/stages/resolution/remote/resolver/chunk.rs@@ -1,42 +1,46 @@-//! Group remote events by routing key. Work is submitted per exception; this-//! module keeps only the routing-key helpers shared with the pool.+//! Build remote routing keys. Work is submitted per exception; this module+//! keeps only the routing-key helpers shared with the pool.-use std::collections::BTreeMap;+use crate::{+ langs::native::DebugImage,+ types::{exception_properties::ExceptionProperties, Exception},+};-use crate::types::exception_properties::ExceptionProperties;--use super::RemoteEvent;+/// Return one routing key per exception in event order.+pub(super) fn routing_keys_for_event(evt: &ExceptionProperties) -> Vec<String> {+ evt.exception_list+ .iter()+ .map(|exception| {+ routing_key_for_exception(evt.team_id, exception, evt.debug_images.as_ref())+ })+ .collect()+}-/// Group events by their per-team routing key. `BTreeMap` keeps the key-/// iteration order deterministic.-pub(super) fn group_events_by_key(events: Vec<RemoteEvent>) -> BTreeMap<String, Vec<RemoteEvent>> {- let mut by_key: BTreeMap<String, Vec<RemoteEvent>> = BTreeMap::new();- for event in events {- by_key- .entry(routing_key_for_event(&event.evt))- .or_default()- .push(event);- }- by_key+fn routing_key_for_exception(+ team_id: i32,+ exception: &Exception,+ debug_images: &[DebugImage],+) -> String {+ exception+ .get_raw_frame()+ .iter()+ .find_map(|frame| frame.symbol_set_ref(debug_images))+ .map(|symbol_set_ref| format!("team:{team_id}:symbol:{symbol_set_ref}"))+ .unwrap_or_else(|| team_routing_key(team_id))}-fn routing_key_for_event(evt: &ExceptionProperties) -> String {- // Per-team routing: every exception of an event hashes to the same pod- // via rendezvous selection in `EndpointPool::select_for_key`. One team's- // bursts land on one preferred pod. Overload spillover is driven by- // per-item outcomes from the resolver.- format!("team:{}", evt.team_id)+fn team_routing_key(team_id: i32) -> String {+ format!("team:{team_id}")}#[cfg(test)]mod tests {use serde_json::json;- use uuid::Uuid;use super::*;#[test]- fn routing_key_is_per_team_regardless_of_exception_internals() {+ fn routing_key_uses_first_symbol_set_ref() {let mut evt: ExceptionProperties = serde_json::from_value(json!({"$exception_list": [{"type": "Error",@@ -56,47 +60,64 @@ mod tests {})).expect("valid exception properties");evt.team_id = 7;- assert_eq!(routing_key_for_event(&evt), "team:7");+ assert_eq!(routing_keys_for_event(&evt), vec!["team:7:symbol:chunk-a"]);}#[test]- fn group_events_by_key_separates_events_by_team() {- let events = vec![- fake_remote_event(1, 0, 1),- fake_remote_event(2, 1, 1),- fake_remote_event(1, 2, 1),- fake_remote_event(2, 3, 1),- ];- let grouped = group_events_by_key(events);- let keys: Vec<&String> = grouped.keys().collect();- assert_eq!(keys, vec!["team:1", "team:2"]);- assert_eq!(grouped["team:1"].len(), 2);- assert_eq!(grouped["team:2"].len(), 2);+ fn routing_key_falls_back_to_team_without_symbol_set_ref() {+ let mut evt: ExceptionProperties = serde_json::from_value(json!({+ "$exception_list": [{+ "type": "Error",+ "value": "boom"+ }]+ }))+ .expect("valid exception properties");+ evt.team_id = 7;+ assert_eq!(routing_keys_for_event(&evt), vec!["team:7"]);}- fn fake_remote_event(team_id: i32, batch_index: usize, n_exceptions: usize) -> RemoteEvent {+ #[test]+ fn routing_keys_are_per_exception() {let mut evt: ExceptionProperties = serde_json::from_value(json!({- "$exception_list": (0..n_exceptions)- .map(|i| json!({- "type": "Error",- "value": format!("boom-{i}"),- }))- .collect::<Vec<_>>()+ "$exception_list": [{+ "type": "Error",+ "value": "boom-a",+ "stacktrace": {+ "type": "raw",+ "frames": [{+ "platform": "web:javascript",+ "filename": "https://example.com/app-a.js",+ "function": "minified",+ "lineno": 1,+ "colno": 2,+ "chunk_id": "chunk-a"+ }]+ }+ }, {+ "type": "Error",+ "value": "boom-b",+ "stacktrace": {+ "type": "raw",+ "frames": [{+ "platform": "web:javascript",+ "filename": "https://example.com/app-b.js",+ "function": "minified",+ "lineno": 1,+ "colno": 2,+ "chunk_id": "chunk-b"+ }]+ }+ }, {+ "type": "Error",+ "value": "boom-c"+ }]})).expect("valid exception properties");- evt.team_id = team_id;- evt.uuid = Uuid::from_u128(0xABCD_0000_0000_0000 ^ (batch_index as u128));+ evt.team_id = 7;- let exception_jsons = evt- .exception_list- .iter()- .map(|exc| serde_json::to_vec(exc).expect("serialize exception"))- .collect();- RemoteEvent {- batch_index,- evt,- exception_jsons,- metadata: Vec::new(),- }+ assert_eq!(+ routing_keys_for_event(&evt),+ vec!["team:7:symbol:chunk-a", "team:7:symbol:chunk-b", "team:7",]+ );}}diff --git a/rust/cymbal/src/modes/resolution/README.md b/rust/cymbal/src/modes/resolution/README.mdindex a866a53347fd..5899600b2b2a 100644--- a/rust/cymbal/src/modes/resolution/README.md+++ b/rust/cymbal/src/modes/resolution/README.md@@ -84,7 +84,15 @@ Remote resolution is opt-in on the cymbal side. There is intentionally **no sile### Routing affinity and reroute behavior-Routing is per team. The caller's `EndpointPool` rendezvous-hashes `team:{team_id}` against the pod set so every exception from a given team prefers a small, stable part of the pod set, maximizing warm-cache locality without coupling the caller to symbol-set internals. The rendezvous score is adjusted by the latest server load snapshot and the caller's own local in-flight count, so highly loaded pods become less likely to receive new work before they return overload outcomes.+Routing is per exception. The caller derives a routing key from the first+symbol-set reference in the exception's raw frames and rendezvous-hashes+`team:{team_id}:symbol:{symbol_set_ref}` against the pod set. Exceptions+without a symbol-set reference fall back to `team:{team_id}`. This keeps work+that needs the same symbol set sticky to a small, stable part of the pod set+while preserving the previous team-level fallback for frames that do not use+symbol stores. The rendezvous score is adjusted by the latest server load+snapshot and the caller's own local in-flight count, so highly loaded pods+become less likely to receive new work before they return overload outcomes.Each endpoint owns one bidirectional Resolve mux with a bounded outbound queue and one waiter per in-flight item. Queue admission failure, stream break, endpoint drain, and endpoint eviction all fail affected items as `ERROR_KIND_OVERLOADED`; the per-item retry layer excludes that endpoint and reroutes only those items. A `Retry` outcome uses the generic retry policy. Cymbal also holds a process-local routing semaphore for items trying to find an accepting pod; a permit is acquired before routing, released on `Accepted`, and otherwise held until routing exhausts or fails terminally. Terminal `ErrorKind`s fail the current all-or-nothing rollout path.