Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(js): Parse debug ids from scraped source files #1534

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions crates/symbolicator-js/src/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use reqwest::Url;
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use symbolic::common::{ByteView, DebugId, SelfCell};
use symbolic::debuginfo::js::discover_sourcemaps_location;
use symbolic::debuginfo::js::{discover_debug_id, discover_sourcemaps_location};
use symbolic::debuginfo::sourcebundle::{
SourceBundleDebugSession, SourceFileDescriptor, SourceFileType,
};
Expand Down Expand Up @@ -447,6 +447,7 @@ impl<T> CachedFileEntry<T> {
pub struct CachedFile {
pub contents: Option<ByteViewString>,
sourcemap_url: Option<Arc<SourceMapUrl>>,
debug_id: Option<DebugId>,
}

impl fmt::Debug for CachedFile {
Expand Down Expand Up @@ -484,6 +485,8 @@ impl CachedFile {
None => None,
};

let debug_id = descriptor.debug_id();

let contents = descriptor
.into_contents()
.ok_or_else(|| CacheError::Malformed("descriptor should have `contents`".into()))?
Expand All @@ -493,6 +496,7 @@ impl CachedFile {
Ok(Self {
contents,
sourcemap_url: sourcemap_url.map(Arc::new),
debug_id,
})
}

Expand Down Expand Up @@ -580,12 +584,17 @@ impl ArtifactFetcher {
self.metrics.record_not_found(SourceFileType::Source);
}

// Then fetch the corresponding sourcemap if we have a sourcemap reference
let sourcemap_url = match &minified_source.entry {
Ok(minified_source) => minified_source.sourcemap_url.as_deref(),
Err(_) => None,
// Then fetch the corresponding sourcemap reference and debug_id
let (sourcemap_url, source_debug_id) = match &minified_source.entry {
Ok(minified_source) => (
minified_source.sourcemap_url.as_deref(),
minified_source.debug_id,
),
Err(_) => (None, None),
};

let debug_id = debug_id.or(source_debug_id);
timfish marked this conversation as resolved.
Show resolved Hide resolved

// If we don't have sourcemap reference, nor a `DebugId`, we skip creating `SourceMapCache`.
if sourcemap_url.is_none() && debug_id.is_none() {
self.metrics.record_sourcemap_not_needed();
Expand All @@ -600,6 +609,7 @@ impl ArtifactFetcher {
entry: Ok(CachedFile {
contents: Some(data.clone()),
sourcemap_url: None,
debug_id,
}),
resolved_with: minified_source.resolved_with,
},
Expand Down Expand Up @@ -781,12 +791,15 @@ impl ArtifactFetcher {
.and_then(|sm_ref| SourceMapUrl::parse_with_prefix(abs_path, sm_ref).ok())
.map(Arc::new);

let debug_id = discover_debug_id(&contents);

self.scraping_attempts
.push(JsScrapingAttempt::success(abs_path.to_owned()));

Ok(CachedFile {
contents: Some(contents),
sourcemap_url,
debug_id,
})
}
Err(e) => {
Expand Down Expand Up @@ -931,9 +944,11 @@ impl ArtifactFetcher {

// Get the sourcemap reference from the artifact, either from metadata, or file contents
let sourcemap_url = resolve_sourcemap_url(abs_path, &artifact.headers, &contents);
let debug_id = discover_debug_id(&contents);
CachedFile {
contents: Some(contents),
sourcemap_url: sourcemap_url.map(Arc::new),
debug_id,
timfish marked this conversation as resolved.
Show resolved Hide resolved
}
}),
resolved_with: artifact.resolved_with,
Expand Down
Loading