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): honor source map ignore lists (#111769)

Hugues Pouillot82c412a4ff1e
diff --git a/rust/cymbal/src/core/metric_consts.rs b/rust/cymbal/src/core/metric_consts.rs
index 5dc385a0287f..5fe3614edcd6 100644
--- a/rust/cymbal/src/core/metric_consts.rs
+++ b/rust/cymbal/src/core/metric_consts.rs
@@ -22,6 +22,8 @@ pub const SAVED_SYMBOL_SET_ERROR_RETURNED: &str = "cymbal_saved_symbol_set_error
pub const SYMBOL_SET_NEGATIVE_CACHE_HIT: &str = "cymbal_symbol_set_negative_cache_hit";
pub const SYMBOL_SET_FETCH_RETRY: &str = "cymbal_symbol_set_fetch_retry";
pub const FRAME_RESOLVED: &str = "cymbal_frame_resolved";
+// Source-map ignore-list matches, labelled by `runtime` (`browser` / `node`).
+pub const SOURCEMAP_IGNORED_FRAME: &str = "cymbal_sourcemap_ignored_frame";
pub const FRAME_CACHE_HITS: &str = "cymbal_frame_cache_hits";
pub const FRAME_CACHE_MISSES: &str = "cymbal_frame_cache_misses";
pub const FRAME_DB_HITS: &str = "cymbal_frame_db_hits";
diff --git a/rust/cymbal/src/core/symbolication/symbol_store/sourcemap.rs b/rust/cymbal/src/core/symbolication/symbol_store/sourcemap.rs
index f6e7691870ca..f900d44f034c 100644
--- a/rust/cymbal/src/core/symbolication/symbol_store/sourcemap.rs
+++ b/rust/cymbal/src/core/symbolication/symbol_store/sourcemap.rs
@@ -1,4 +1,9 @@
-use std::{collections::HashMap, net::IpAddr, sync::Arc, time::Duration};
+use std::{
+ collections::{HashMap, HashSet},
+ net::IpAddr,
+ sync::Arc,
+ time::Duration,
+};
use async_trait::async_trait;
use base64::Engine;
@@ -6,8 +11,10 @@ use bytes::Bytes;
use futures::StreamExt;
use posthog_symbol_data::{read_symbol_data_with_byte_count, write_symbol_data, SourceAndMap};
use reqwest::Url;
+use serde::Deserialize;
+use sourcemap::{DecodedMap, SourceMap};
use sqlx::PgPool;
-use symbolic::sourcemapcache::{SourceMapCache, SourceMapCacheWriter};
+use symbolic::sourcemapcache::{SourceMapCache, SourceMapCacheWriter, SourcePosition};
use tracing::{debug, info, warn};
use crate::{
@@ -86,6 +93,9 @@ pub struct ChunkIdRescue {
#[derive(Debug)]
pub struct OwnedSourceMapCache {
data: Vec<u8>,
+ // symbolic's source-map cache drops `ignoreList`; this side index avoids reparsing the map
+ // for every lookup.
+ ignored_source_ranges: Vec<(SourcePosition, bool)>,
/// dart2js minified names mapping (minified -> original) for Flutter Web support.
/// Parsed from the x_org_dartlang_dart2js.minified_names.global extension.
dart_minified_names: Option<HashMap<String, String>>,
@@ -101,6 +111,7 @@ impl OwnedSourceMapCache {
let decompressed_bytes = data.len();
Ok(Self {
data,
+ ignored_source_ranges: Vec::new(),
dart_minified_names: None,
decompressed_bytes,
})
@@ -110,7 +121,7 @@ impl OwnedSourceMapCache {
sam: SourceAndMap,
decompressed_bytes: usize,
) -> Result<Self, symbolic::sourcemapcache::SourceMapCacheWriterError> {
- // Parse dart2js minified names before we lose access to the raw JSON
+ let ignored_source_ranges = parse_ignored_source_ranges(&sam.sourcemap);
let dart_minified_names = parse_dart_minified_names(&sam.sourcemap);
let mut data = Vec::with_capacity(sam.minified_source.len() + sam.sourcemap.len() + 16);
@@ -118,6 +129,7 @@ impl OwnedSourceMapCache {
smcw.serialize(&mut data).unwrap();
Ok(Self {
data,
+ ignored_source_ranges,
dart_minified_names,
decompressed_bytes,
})
@@ -128,6 +140,16 @@ impl OwnedSourceMapCache {
SourceMapCache::parse(&self.data).unwrap()
}
+ pub fn is_source_ignored(&self, position: SourcePosition) -> bool {
+ let insertion = self
+ .ignored_source_ranges
+ .partition_point(|(start, _)| *start <= position);
+ insertion
+ .checked_sub(1)
+ .and_then(|index| self.ignored_source_ranges.get(index))
+ .is_some_and(|(_, ignored)| *ignored)
+ }
+
/// Returns the dart2js minified names map if this sourcemap has the extension.
/// Used for remapping Flutter Web minified exception types like "minified:BA".
pub fn get_dart_minified_names(&self) -> Option<&HashMap<String, String>> {
@@ -137,10 +159,138 @@ impl OwnedSourceMapCache {
impl Countable for OwnedSourceMapCache {
fn byte_count(&self) -> usize {
- self.decompressed_bytes
+ self.decompressed_bytes.saturating_add(
+ self.ignored_source_ranges
+ .capacity()
+ .saturating_mul(std::mem::size_of::<(SourcePosition, bool)>()),
+ )
+ }
+}
+
+#[cfg(test)]
+pub(crate) mod test_support {
+ use async_trait::async_trait;
+
+ use crate::symbolication::symbol_store::{chunk_id::OrChunkId, SymbolCatalog};
+
+ use super::*;
+
+ pub struct StaticSourceMapCatalog(Arc<OwnedSourceMapCache>);
+
+ #[async_trait]
+ impl SymbolCatalog<OrChunkId<Url>, OwnedSourceMapCache> for StaticSourceMapCatalog {
+ async fn lookup(
+ &self,
+ _team_id: i32,
+ _reference: OrChunkId<Url>,
+ ) -> Result<Arc<OwnedSourceMapCache>, ResolveError> {
+ Ok(Arc::clone(&self.0))
+ }
+ }
+
+ pub fn source_map_catalog() -> StaticSourceMapCatalog {
+ let sourcemap = r#"{"version":3,"file":"bundle.js","sources":["vendor.js","app.js"],"sourcesContent":["export function vendor() {}","export function app() {}"],"names":[],"mappings":"AAAA,UCAA","ignoreList":[0]}"#.to_string();
+ let decompressed_bytes = sourcemap.len();
+ let source_map = OwnedSourceMapCache::from_source_and_map(
+ SourceAndMap {
+ minified_source: "function vendor(){} function app(){}".to_string(),
+ sourcemap,
+ },
+ decompressed_bytes,
+ )
+ .unwrap();
+ StaticSourceMapCatalog(Arc::new(source_map))
+ }
+}
+
+#[derive(Default, Deserialize)]
+struct IgnoreListMetadata {
+ #[serde(default, rename = "ignoreList")]
+ ignore_list: Vec<u32>,
+ #[serde(default, rename = "x_google_ignoreList")]
+ legacy_ignore_list: Vec<u32>,
+ #[serde(default)]
+ sections: Vec<IgnoreListSection>,
+}
+
+#[derive(Default, Deserialize)]
+struct IgnoreListSection {
+ map: Option<Box<IgnoreListMetadata>>,
+}
+
+fn parse_ignored_source_ranges(sourcemap: &str) -> Vec<(SourcePosition, bool)> {
+ if !sourcemap.contains("\"ignoreList\"") && !sourcemap.contains("\"x_google_ignoreList\"") {
+ return Vec::new();
+ }
+
+ let Ok(metadata) = serde_json::from_str::<IgnoreListMetadata>(sourcemap) else {
+ return Vec::new();
+ };
+ let Ok(mut decoded) = sourcemap::decode_slice(sourcemap.as_bytes()) else {
+ return Vec::new();
+ };
+ apply_ignore_lists(&mut decoded, &metadata);
+
+ match decoded {
+ DecodedMap::Regular(map) => ignored_source_ranges(&map),
+ DecodedMap::Index(index) => index
+ .flatten()
+ .map(|map| ignored_source_ranges(&map))
+ .unwrap_or_default(),
+ DecodedMap::Hermes(map) => ignored_source_ranges(&map),
+ }
+}
+
+fn apply_ignore_lists(decoded: &mut DecodedMap, metadata: &IgnoreListMetadata) {
+ match decoded {
+ DecodedMap::Regular(map) => add_ignore_lists(map, metadata),
+ DecodedMap::Hermes(map) => add_ignore_lists(map, metadata),
+ DecodedMap::Index(index) => {
+ for (section_index, section_metadata) in metadata.sections.iter().enumerate() {
+ let Some((map, metadata)) = index
+ .get_section_mut(section_index as u32)
+ .and_then(|section| section.get_sourcemap_mut())
+ .zip(section_metadata.map.as_deref())
+ else {
+ continue;
+ };
+ apply_ignore_lists(map, metadata);
+ }
+ }
}
}
+fn add_ignore_lists(map: &mut SourceMap, metadata: &IgnoreListMetadata) {
+ for source_id in metadata
+ .ignore_list
+ .iter()
+ .chain(&metadata.legacy_ignore_list)
+ {
+ map.add_to_ignore_list(*source_id);
+ }
+}
+
+fn ignored_source_ranges(map: &SourceMap) -> Vec<(SourcePosition, bool)> {
+ let ignored_sources: HashSet<u32> = map.ignore_list().copied().collect();
+ if ignored_sources.is_empty() {
+ return Vec::new();
+ }
+
+ let mut ranges = Vec::new();
+ let mut previous = false;
+ for token in map.tokens() {
+ let ignored = ignored_sources.contains(&token.get_src_id());
+ if ignored != previous {
+ ranges.push((
+ SourcePosition::new(token.get_dst_line(), token.get_dst_col()),
+ ignored,
+ ));
+ previous = ignored;
+ }
+ }
+ ranges
+}
+
impl SourcemapProvider {
pub fn new(config: &ResolverConfig) -> Self {
let timeout = Duration::from_secs(config.sourcemap_timeout_seconds);
@@ -680,6 +830,7 @@ fn assert_is_sourcemap(data: &str) -> Result<(), ResolveError> {
mod test {
use crate::error::FrameError;
use httpmock::MockServer;
+ use sourcemap::SourceMapBuilder;
const MINIFIED: &[u8] = include_bytes!("../../../../tests/static/chunk-PGUQKT6S.js");
const MAP: &[u8] = include_bytes!("../../../../tests/static/chunk-PGUQKT6S.js.map");
@@ -689,6 +840,97 @@ mod test {
use super::*;
+ fn source_map_with_ignore_list(field: &str) -> String {
+ let mut builder = SourceMapBuilder::new(Some("bundle.js"));
+ let vendor = builder.add_source("vendor.js");
+ builder.set_source_contents(vendor, Some("export function vendor() {}"));
+ builder.add(0, 0, 0, 0, Some("vendor.js"), Some("vendor"), false);
+
+ let app = builder.add_source("app.js");
+ builder.set_source_contents(app, Some("export function app() {}"));
+ builder.add(0, 10, 0, 0, Some("app.js"), Some("app"), false);
+ builder.add_to_ignore_list(vendor);
+
+ let mut encoded = Vec::new();
+ builder.into_sourcemap().to_writer(&mut encoded).unwrap();
+ String::from_utf8(encoded)
+ .unwrap()
+ .replace("\"ignoreList\"", &format!("\"{field}\""))
+ }
+
+ fn parsed_source_map(field: &str) -> OwnedSourceMapCache {
+ let sourcemap = source_map_with_ignore_list(field);
+ let decompressed_bytes = sourcemap.len();
+ OwnedSourceMapCache::from_source_and_map(
+ SourceAndMap {
+ minified_source: "function vendor(){} function app(){}".to_string(),
+ sourcemap,
+ },
+ decompressed_bytes,
+ )
+ .unwrap()
+ }
+
+ #[test]
+ fn standard_ignore_list_classifies_generated_ranges() {
+ let source_map = parsed_source_map("ignoreList");
+
+ assert!(source_map.is_source_ignored(SourcePosition::new(0, 0)));
+ assert!(source_map.is_source_ignored(SourcePosition::new(0, 9)));
+ assert!(!source_map.is_source_ignored(SourcePosition::new(0, 10)));
+ }
+
+ #[test]
+ fn legacy_google_ignore_list_classifies_generated_ranges() {
+ let source_map = parsed_source_map("x_google_ignoreList");
+
+ assert!(source_map.is_source_ignored(SourcePosition::new(0, 0)));
+ assert!(!source_map.is_source_ignored(SourcePosition::new(0, 10)));
+ }
+
+ #[test]
+ fn indexed_maps_apply_nested_legacy_ignore_lists() {
+ let sourcemap = r#"{
+ "version": 3,
+ "sections": [
+ {
+ "offset": {"line": 0, "column": 0},
+ "map": {
+ "version": 3,
+ "sources": ["vendor.js"],
+ "sourcesContent": ["export function vendor() {}"],
+ "names": [],
+ "mappings": "AAAA",
+ "x_google_ignoreList": [0]
+ }
+ },
+ {
+ "offset": {"line": 0, "column": 10},
+ "map": {
+ "version": 3,
+ "sources": ["app.js"],
+ "sourcesContent": ["export function app() {}"],
+ "names": [],
+ "mappings": "AAAA"
+ }
+ }
+ ]
+ }"#
+ .to_string();
+ let decompressed_bytes = sourcemap.len();
+ let source_map = OwnedSourceMapCache::from_source_and_map(
+ SourceAndMap {
+ minified_source: "function vendor(){} function app(){}".to_string(),
+ sourcemap,
+ },
+ decompressed_bytes,
+ )
+ .unwrap();
+
+ assert!(source_map.is_source_ignored(SourcePosition::new(0, 0)));
+ assert!(!source_map.is_source_ignored(SourcePosition::new(0, 10)));
+ }
+
#[tokio::test]
async fn find_sourcemap_url_in_body_test() {
let server = MockServer::start();
diff --git a/rust/cymbal/src/core/types/langs/js.rs b/rust/cymbal/src/core/types/langs/js.rs
index 2dd74571a20d..4dc7dc89d6ee 100644
--- a/rust/cymbal/src/core/types/langs/js.rs
+++ b/rust/cymbal/src/core/types/langs/js.rs
@@ -9,6 +9,7 @@ use crate::{
error::{FrameError, JsResolveErr, ResolveError, UnhandledError},
frames::{record_frame_resolution_failure, Frame},
langs::CommonFrameMetadata,
+ metric_consts::SOURCEMAP_IGNORED_FRAME,
sanitize_string,
symbolication::symbol_store::{
chunk_id::OrChunkId, sourcemap::OwnedSourceMapCache, SymbolCatalog,
@@ -86,8 +87,8 @@ impl RawJSFrame {
let smc = sourcemap.get_smc();
// Note: javascript stack frame lines are 1-indexed, so we have to subtract 1
- let Some(location) = smc.lookup(SourcePosition::new(location.line - 1, location.column))
- else {
+ let generated_position = SourcePosition::new(location.line - 1, location.column);
+ let Some(location) = smc.lookup(generated_position) else {
return Err(JsResolveErr::TokenNotFound(
self.fn_name.clone(),
location.line,
@@ -96,7 +97,12 @@ impl RawJSFrame {
.into());
};
- Ok(Frame::from((self, location, context_lines)))
+ let mut frame = Frame::from((self, location, context_lines));
+ if sourcemap.is_source_ignored(generated_position) {
+ frame.in_app = false;
+ metrics::counter!(SOURCEMAP_IGNORED_FRAME, "runtime" => "browser").increment(1);
+ }
+ Ok(frame)
}
// JS frames can only handle JS resolution errors - errors at the network level
@@ -357,7 +363,46 @@ fn is_dependency_source(source: &str) -> bool {
#[cfg(test)]
mod test {
- use super::is_dependency_source;
+ use crate::{
+ langs::CommonFrameMetadata,
+ symbolication::symbol_store::sourcemap::test_support::source_map_catalog,
+ };
+
+ use super::{is_dependency_source, FrameLocation, RawJSFrame};
+
+ fn resolvable_frame(column: u32) -> RawJSFrame {
+ RawJSFrame {
+ location: Some(FrameLocation { line: 1, column }),
+ source_url: Some("https://example.com/bundle.js".to_string()),
+ fn_name: "minified".to_string(),
+ chunk_id: None,
+ meta: CommonFrameMetadata {
+ in_app: true,
+ synthetic: false,
+ },
+ }
+ }
+
+ #[tokio::test]
+ async fn source_map_ignore_list_demotes_only_ignored_sources() {
+ let catalog = source_map_catalog();
+
+ let vendor = resolvable_frame(0)
+ .resolve_frame(1, &catalog, 0)
+ .await
+ .unwrap();
+ assert!(vendor.resolved);
+ assert_eq!(vendor.source.as_deref(), Some("vendor.js"));
+ assert!(!vendor.in_app);
+
+ let app = resolvable_frame(10)
+ .resolve_frame(1, &catalog, 0)
+ .await
+ .unwrap();
+ assert!(app.resolved);
+ assert_eq!(app.source.as_deref(), Some("app.js"));
+ assert!(app.in_app);
+ }
#[test]
fn detects_dependency_sources() {
diff --git a/rust/cymbal/src/core/types/langs/node.rs b/rust/cymbal/src/core/types/langs/node.rs
index 5cac3bf98408..0926f4dbe98a 100644
--- a/rust/cymbal/src/core/types/langs/node.rs
+++ b/rust/cymbal/src/core/types/langs/node.rs
@@ -2,6 +2,7 @@ use crate::{
error::{FrameError, JsResolveErr, ResolveError, UnhandledError},
frames::{record_frame_resolution_failure, Context, ContextLine, Frame},
langs::CommonFrameMetadata,
+ metric_consts::SOURCEMAP_IGNORED_FRAME,
sanitize_string,
symbolication::symbol_store::{
chunk_id::OrChunkId, sourcemap::OwnedSourceMapCache, SymbolCatalog,
@@ -87,10 +88,14 @@ impl RawNodeFrame {
let sourcemap = catalog.lookup(team_id, chunk_ref).await?;
let smc = sourcemap.get_smc();
// Note: javascript stack frame lines are 1-indexed, so we have to subtract 1
- if let Some(location) =
- smc.lookup(SourcePosition::new(location.line - 1, location.column))
- {
- Ok(Frame::from((self, location, context_lines)))
+ let generated_position = SourcePosition::new(location.line - 1, location.column);
+ if let Some(location) = smc.lookup(generated_position) {
+ let mut frame = Frame::from((self, location, context_lines));
+ if sourcemap.is_source_ignored(generated_position) {
+ frame.in_app = false;
+ metrics::counter!(SOURCEMAP_IGNORED_FRAME, "runtime" => "node").increment(1);
+ }
+ Ok(frame)
} else {
Err(JsResolveErr::TokenNotFound(
self.function.clone(),
@@ -325,8 +330,43 @@ fn is_dependency_source(source: &str) -> bool {
#[cfg(test)]
mod test {
+ use crate::symbolication::symbol_store::sourcemap::test_support::source_map_catalog;
+
use super::RawNodeFrame;
+ fn resolvable_frame(column: u32) -> RawNodeFrame {
+ serde_json::from_value(serde_json::json!({
+ "filename": "bundle.js",
+ "function": "minified",
+ "lineno": 1,
+ "colno": column,
+ "chunk_id": "test-chunk",
+ "in_app": true,
+ }))
+ .unwrap()
+ }
+
+ #[tokio::test]
+ async fn source_map_ignore_list_demotes_only_ignored_sources() {
+ let catalog = source_map_catalog();
+
+ let vendor = resolvable_frame(0)
+ .resolve_frame(1, &catalog, 0)
+ .await
+ .unwrap();
+ assert!(vendor.resolved);
+ assert_eq!(vendor.source.as_deref(), Some("vendor.js"));
+ assert!(!vendor.in_app);
+
+ let app = resolvable_frame(10)
+ .resolve_frame(1, &catalog, 0)
+ .await
+ .unwrap();
+ assert!(app.resolved);
+ assert_eq!(app.source.as_deref(), Some("app.js"));
+ assert!(app.in_app);
+ }
+
#[test]
fn frame_id_distinguishes_columns_on_the_same_line() {
// Minified bundles put every frame on line 1 of the same file with an anonymized