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(error-tracking): show spiking notification trigger (#72226)

Hugues Pouillot5815063ae204
diff --git a/frontend/src/scenes/hog-functions/filters/HogFunctionFiltersInternal.tsx b/frontend/src/scenes/hog-functions/filters/HogFunctionFiltersInternal.tsx
index db08552e0103..82f96c8c5e01 100644
--- a/frontend/src/scenes/hog-functions/filters/HogFunctionFiltersInternal.tsx
+++ b/frontend/src/scenes/hog-functions/filters/HogFunctionFiltersInternal.tsx
@@ -33,6 +33,10 @@ export const getProductEventFilterOptions = (contextId: HogFunctionConfiguration
label: 'Error tracking issue reopened',
value: '$error_tracking_issue_reopened',
},
+ {
+ label: 'Error tracking issue spiking',
+ value: '$error_tracking_issue_spiking',
+ },
]
case 'insight-alerts':
return [
diff --git a/nodejs/src/cdp/utils.test.ts b/nodejs/src/cdp/utils.test.ts
index 209ae3f14956..f7921b78479e 100644
--- a/nodejs/src/cdp/utils.test.ts
+++ b/nodejs/src/cdp/utils.test.ts
@@ -1,9 +1,59 @@
import { DateTime } from 'luxon'
+import { Team } from '../types'
+import { CdpInternalEvent } from './schema'
import { LogEntry } from './types'
-import { fixLogDeduplication, gzipObject, sanitizeLogMessage, unGzipObject } from './utils'
+import {
+ convertInternalEventToHogFunctionInvocationGlobals,
+ fixLogDeduplication,
+ gzipObject,
+ sanitizeLogMessage,
+ unGzipObject,
+} from './utils'
describe('Utils', () => {
+ test.each(['$error_tracking_issue_created', '$error_tracking_issue_reopened', '$error_tracking_issue_spiking'])(
+ 'flattens exception properties for %s',
+ (eventName) => {
+ const data: CdpInternalEvent = {
+ team_id: 1,
+ event: {
+ uuid: '018f0000-0000-7000-8000-000000000000',
+ event: eventName,
+ distinct_id: '018f0000-0000-7000-8000-000000000001',
+ properties: {
+ name: 'Test issue',
+ issue_description: 'Test description',
+ first_seen: '2026-07-20T09:00:00Z',
+ assignee: '{"type":"user","id":42}',
+ fingerprint: 'server-fingerprint',
+ exception_props: {
+ $exception_types: ['TypeError'],
+ assignee: 'untrusted-assignee',
+ fingerprint: 'untrusted-fingerprint',
+ },
+ },
+ timestamp: '2026-07-20T10:00:00Z',
+ },
+ }
+
+ const globals = convertInternalEventToHogFunctionInvocationGlobals(
+ data,
+ { id: 1, name: 'Test project' } as Team,
+ 'https://us.posthog.com'
+ )
+
+ expect(globals.event.properties).toEqual({
+ name: 'Test issue',
+ issue_description: 'Test description',
+ first_seen: '2026-07-20T09:00:00Z',
+ assignee: '{"type":"user","id":42}',
+ fingerprint: 'server-fingerprint',
+ $exception_types: ['TypeError'],
+ })
+ }
+ )
+
describe('gzip compressions', () => {
it("should compress and decompress a string using gzip's sync functions", async () => {
const input = { foo: 'bar', foo2: 'bar' }
diff --git a/nodejs/src/cdp/utils.ts b/nodejs/src/cdp/utils.ts
index 42adc8ab4c9a..ee5473143d63 100644
--- a/nodejs/src/cdp/utils.ts
+++ b/nodejs/src/cdp/utils.ts
@@ -155,7 +155,7 @@ export function convertInternalEventToHogFunctionInvocationGlobals(
'exception_props' in properties &&
typeof properties.exception_props === 'object'
) {
- properties = { ...properties, ...properties.exception_props }
+ properties = { ...properties.exception_props, ...properties }
delete properties.exception_props
}
@@ -245,7 +245,11 @@ export function isNativeHogFunction(hogFunction: Pick<HogFunctionType, 'template
}
export function isInternalErrorTrackingEvent(event: CdpInternalEvent['event']): boolean {
- return ['$error_tracking_issue_created', '$error_tracking_issue_reopened'].includes(event.event)
+ return [
+ '$error_tracking_issue_created',
+ '$error_tracking_issue_reopened',
+ '$error_tracking_issue_spiking',
+ ].includes(event.event)
}
export function filterExists<T>(value: T): value is NonNullable<T> {
diff --git a/rust/cymbal/src/core/types/notification.rs b/rust/cymbal/src/core/types/notification.rs
index a89efd05cab6..1a0b9bb82133 100644
--- a/rust/cymbal/src/core/types/notification.rs
+++ b/rust/cymbal/src/core/types/notification.rs
@@ -163,6 +163,8 @@ pub struct IssueSpiking {
pub issue: IssueNotificationContext,
pub computed_baseline: f64,
pub current_bucket_value: f64,
+ #[serde(default)]
+ pub assignee: Option<String>,
}
/// Issue state captured when the ingestion transition happened.
diff --git a/rust/cymbal/src/modes/notifications/issue_handler.rs b/rust/cymbal/src/modes/notifications/issue_handler.rs
index 5b9bef17f7e1..78203d71f422 100644
--- a/rust/cymbal/src/modes/notifications/issue_handler.rs
+++ b/rust/cymbal/src/modes/notifications/issue_handler.rs
@@ -111,6 +111,7 @@ pub async fn handle_issue_spiking(
issue,
computed_baseline,
current_bucket_value,
+ assignee,
} = notification;
let IssueNotificationContext {
issue_id,
@@ -159,7 +160,8 @@ pub async fn handle_issue_spiking(
&context.internal_events_topic,
meta.notification_id,
&issue,
- event_properties.fingerprint(),
+ assignee,
+ &event_properties,
detected_at,
computed_baseline,
current_bucket_value,
diff --git a/rust/cymbal/src/modes/notifications/side_effects.rs b/rust/cymbal/src/modes/notifications/side_effects.rs
index 5581f70ccbc3..381915edf118 100644
--- a/rust/cymbal/src/modes/notifications/side_effects.rs
+++ b/rust/cymbal/src/modes/notifications/side_effects.rs
@@ -163,7 +163,8 @@ pub async fn send_issue_spiking_internal_event<I: NotificationIssue>(
internal_events_topic: &str,
notification_id: Uuid,
issue: &I,
- fingerprint: &str,
+ assignee: Option<String>,
+ processed_properties: &ProcessedExceptionProperties,
detected_at: DateTime<Utc>,
computed_baseline: f64,
current_bucket_value: f64,
@@ -181,6 +182,17 @@ pub async fn send_issue_spiking_internal_event<I: NotificationIssue>(
event
.insert_prop("description", issue.description())
.expect("insert_prop for description should never fail");
+ event
+ .insert_prop("issue_description", issue.description())
+ .expect("insert_prop for issue_description should never fail");
+ event
+ .insert_prop("first_seen", issue.created_at())
+ .expect("insert_prop for first_seen should never fail");
+ if let Some(assignee) = assignee {
+ event
+ .insert_prop("assignee", assignee)
+ .expect("insert_prop for assignee should never fail");
+ }
event
.insert_prop("computed_baseline", computed_baseline)
.expect("insert_prop for computed_baseline should never fail");
@@ -188,25 +200,16 @@ pub async fn send_issue_spiking_internal_event<I: NotificationIssue>(
.insert_prop("current_bucket_value", current_bucket_value)
.expect("insert_prop for current_bucket_value should never fail");
event
- .insert_prop("fingerprint", fingerprint)
+ .insert_prop("fingerprint", processed_properties.fingerprint())
.expect("insert_prop for fingerprint should never fail");
// Spikes are detected on live traffic, so detection time is a good anchor for finding
// example events.
event
.insert_prop("exception_timestamp", detected_at)
.expect("insert_prop for exception_timestamp should never fail");
+ event.insert_prop("exception_props", processed_properties)?;
- let iter = [InternalEvent {
- team_id: issue.team_id(),
- event,
- person: None,
- }];
-
- send_iter_to_kafka(producer, internal_events_topic, &iter)
- .await
- .into_iter()
- .collect::<Result<Vec<_>, _>>()?;
- Ok(())
+ send_internal_event_with_fallback(producer, internal_events_topic, issue.team_id(), event).await
}
async fn send_internal_event_with_producer<I: NotificationIssue>(
@@ -231,6 +234,8 @@ async fn send_internal_event_with_producer<I: NotificationIssue>(
event
.insert_prop("description", issue.description())
.expect("Strings are serializable");
+ event.insert_prop("issue_description", issue.description())?;
+ event.insert_prop("first_seen", issue.created_at())?;
event.insert_prop("status", issue.status())?;
event.insert_prop("fingerprint", processed_properties.fingerprint())?;
event.insert_prop("exception_timestamp", event_timestamp)?;
@@ -242,13 +247,22 @@ async fn send_internal_event_with_producer<I: NotificationIssue>(
.expect("Strings are serializable");
}
- let iter = [InternalEvent {
- team_id: issue.team_id(),
+ send_internal_event_with_fallback(producer, internal_events_topic, issue.team_id(), event).await
+}
+
+async fn send_internal_event_with_fallback(
+ producer: &FutureProducer<KafkaContext>,
+ internal_events_topic: &str,
+ team_id: i32,
+ event: InternalEventEvent,
+) -> Result<(), UnhandledError> {
+ let mut events = [InternalEvent {
+ team_id,
event,
person: None,
}];
- let res = send_iter_to_kafka(producer, internal_events_topic, &iter)
+ let res = send_iter_to_kafka(producer, internal_events_topic, &events)
.await
.into_iter()
.collect::<Result<Vec<_>, _>>();
@@ -261,10 +275,8 @@ async fn send_internal_event_with_producer<I: NotificationIssue>(
Some(RDKafkaErrorCode::MessageSizeTooLarge)
) =>
{
- let mut iter = iter;
- iter[0].event.properties.remove("exception_props");
- iter[0].event.insert_prop("message_was_too_large", true)?;
- send_iter_to_kafka(producer, internal_events_topic, &iter)
+ remove_oversized_exception_props(&mut events[0].event)?;
+ send_iter_to_kafka(producer, internal_events_topic, &events)
.await
.into_iter()
.collect::<Result<Vec<_>, _>>()?;
@@ -274,6 +286,12 @@ async fn send_internal_event_with_producer<I: NotificationIssue>(
}
}
+fn remove_oversized_exception_props(event: &mut InternalEventEvent) -> Result<(), UnhandledError> {
+ event.properties.remove("exception_props");
+ event.insert_prop("message_was_too_large", true)?;
+ Ok(())
+}
+
#[cfg(test)]
mod tests {
use super::*;
@@ -351,4 +369,32 @@ mod tests {
Some("disabled_sdk")
);
}
+
+ #[test]
+ fn oversized_internal_event_fallback_removes_only_exception_properties() {
+ let mut event = InternalEventEvent::new(
+ "$error_tracking_issue_spiking",
+ Uuid::nil(),
+ Utc::now(),
+ None,
+ );
+ event
+ .insert_prop("fingerprint", "server-fingerprint")
+ .unwrap();
+ event
+ .insert_prop("exception_props", serde_json::json!({"large": "payload"}))
+ .unwrap();
+
+ remove_oversized_exception_props(&mut event).unwrap();
+
+ assert!(!event.properties.contains_key("exception_props"));
+ assert_eq!(
+ event.properties.get("fingerprint"),
+ Some(&Value::String("server-fingerprint".to_string()))
+ );
+ assert_eq!(
+ event.properties.get("message_was_too_large"),
+ Some(&Value::Bool(true))
+ );
+ }
}
diff --git a/rust/cymbal/src/modes/processing/issue_resolution.rs b/rust/cymbal/src/modes/processing/issue_resolution.rs
index 54dc16dedec8..d47982f1e942 100644
--- a/rust/cymbal/src/modes/processing/issue_resolution.rs
+++ b/rust/cymbal/src/modes/processing/issue_resolution.rs
@@ -411,6 +411,12 @@ pub async fn send_issue_spiking_notification(
computed_baseline: f64,
current_bucket_value: f64,
) -> Result<(), UnhandledError> {
+ let assignment = issue
+ .get_assignments(&context.posthog_pool)
+ .await?
+ .into_iter()
+ .next();
+
publish_ingestion_notification(
context,
IngestionNotification::IssueSpiking(IssueSpiking {
@@ -418,6 +424,7 @@ pub async fn send_issue_spiking_notification(
issue: issue_notification_context(issue, processed_properties),
computed_baseline,
current_bucket_value,
+ assignee: assignment_to_string(assignment)?,
}),
)
.await