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(cymbal): match the SDK asset host for suspicious frames (#83885)

Aleksander Błaszkiewiczb05b87496bb2
diff --git a/rust/cymbal/src/core/types/langs/js.rs b/rust/cymbal/src/core/types/langs/js.rs
index ee89dd9a85d2..d8d674677586 100644
--- a/rust/cymbal/src/core/types/langs/js.rs
+++ b/rust/cymbal/src/core/types/langs/js.rs
@@ -180,9 +180,20 @@ impl RawJSFrame {
}
pub fn is_suspicious(&self) -> bool {
- self.source_url
- .as_ref()
- .is_some_and(|s| s.contains("posthog.com/static/"))
+ // posthog-js is served from a regional asset CDN whose host is
+ // `{region}-assets.i.posthog.com` (the `assets` target in the SDK's request router).
+ // Matching that host rather than a `posthog.com/static/` substring keeps PostHog's own
+ // app bundles out of the count: they are served from hosts like
+ // `app-static-prod.posthog.com` under the same `/static/` path, so a substring match
+ // marks every error in the PostHog app itself as an SDK exception.
+ const SDK_ASSET_HOST_SUFFIX: &str = "-assets.i.posthog.com";
+
+ let Ok(url) = self.source_url() else {
+ return false;
+ };
+
+ url.host_str()
+ .is_some_and(|host| host.ends_with(SDK_ASSET_HOST_SUFFIX))
}
}
@@ -373,4 +384,48 @@ mod test {
"http://example.com/path/to/file.js".parse().unwrap()
);
}
+
+ fn frame_from(source_url: Option<&str>) -> super::RawJSFrame {
+ super::RawJSFrame {
+ location: None,
+ source_url: source_url.map(str::to_string),
+ fn_name: "main".to_string(),
+ chunk_id: None,
+ meta: Default::default(),
+ }
+ }
+
+ #[test]
+ fn only_the_sdk_asset_cdn_is_suspicious() {
+ let cases = [
+ ("https://us-assets.i.posthog.com/static/array.js", true),
+ ("https://eu-assets.i.posthog.com/static/recorder.js", true),
+ // Frame filenames often carry a trailing `:line:column`, so this has to match after
+ // the same parsing the resolution path does, not on the raw string.
+ ("https://us-assets.i.posthog.com/static/array.js:1:2", true),
+ (
+ "https://app-static-prod.posthog.com/static/chunk-ABC12345.js",
+ false,
+ ),
+ (
+ "https://app-static.eu.posthog.com/static/chunk-DEF67890.js",
+ false,
+ ),
+ // The legacy host served both the app and the pre-CDN snippet, so a frame here
+ // cannot be attributed to the SDK.
+ ("https://app.posthog.com/static/array.js", false),
+ ("https://example.com/static/bundle.js", false),
+ ("/static/relative.js", false),
+ ];
+
+ for (source_url, expected) in cases {
+ assert_eq!(
+ frame_from(Some(source_url)).is_suspicious(),
+ expected,
+ "{source_url}"
+ );
+ }
+
+ assert!(!frame_from(None).is_suspicious());
+ }
}