Skip to content

Commit

Permalink
feat(js): Return "sourcemap origin" (#1447)
Browse files Browse the repository at this point in the history
This adds a sourcemap_origin field to JsFrameData that contains information about where exactly the sourcemap that was used to symbolicate the frame came from. See test snapshots for examples of what that looks like.
  • Loading branch information
loewenheim committed Apr 30, 2024
1 parent 8bcaa73 commit 287e9ec
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- fix(proguard): Correctly compute source file name (#1441) by @loewenheim
- Do a `cargo update` (#1439) by @Swatinem
- ref(proguard): Increase in-memory cache size to 5GiB (#1438) by @loewenheim
- feat(js): JS frames have a new field `data.sourcemap_origin` containing information about where the sourcemap used to symbolicate the frame came frmo (#1447) by @loewenheim

## 24.4.0

Expand Down
4 changes: 4 additions & 0 deletions crates/symbolicator-js/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use symbolicator_service::caching::CacheError;
use symbolicator_service::types::{RawObjectInfo, Scope, ScrapingConfig};
use symbolicator_sources::{SentryFileId, SentrySourceConfig};

use crate::lookup::CachedFileUri;

#[derive(Debug, Clone)]
pub struct SymbolicateJsStacktraces {
pub scope: Scope,
Expand Down Expand Up @@ -212,6 +214,8 @@ pub struct JsFrameData {
#[serde(skip_serializing_if = "Option::is_none")]
pub sourcemap: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub sourcemap_origin: Option<CachedFileUri>,
#[serde(skip_serializing_if = "Option::is_none")]
pub resolved_with: Option<ResolvedWith>,
#[serde(default)]
pub symbolicated: bool,
Expand Down
10 changes: 8 additions & 2 deletions crates/symbolicator-js/src/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use std::sync::Arc;
use std::time::SystemTime;

use reqwest::Url;
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use symbolic::common::{ByteView, DebugId, SelfCell};
use symbolic::debuginfo::js::discover_sourcemaps_location;
Expand Down Expand Up @@ -326,16 +327,20 @@ impl SourceMapUrl {
pub type ArtifactBundle = SelfCell<Arc<ObjectHandle>, SourceBundleDebugSession<'static>>;

/// The lookup key of an arbitrary file.
#[derive(Debug, Hash, PartialEq, Eq, Clone)]
#[derive(Debug, Hash, PartialEq, Eq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum FileKey {
/// This key represents a [`SourceFileType::MinifiedSource`].
MinifiedSource {
abs_path: String,
#[serde(skip_serializing_if = "Option::is_none")]
debug_id: Option<DebugId>,
},
/// This key represents a [`SourceFileType::SourceMap`].
SourceMap {
#[serde(skip_serializing_if = "Option::is_none")]
abs_path: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
debug_id: Option<DebugId>,
},
/// This key represents a [`SourceFileType::Source`].
Expand Down Expand Up @@ -377,7 +382,8 @@ impl FileKey {
}

/// The source of an individual file.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum CachedFileUri {
/// The file was an individual artifact fetched using its own URI.
IndividualFile(RemoteFileUri),
Expand Down
6 changes: 4 additions & 2 deletions crates/symbolicator-js/src/symbolication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,14 @@ async fn symbolicate_js_frame(
.flatten()
.unwrap_or_else(|| raw_frame.abs_path.clone());

let (smcache, resolved_with) = match &module.smcache {
let (smcache, resolved_with, sourcemap_origin) = match &module.smcache {
Some(smcache) => match &smcache.entry {
Ok(entry) => (entry, smcache.resolved_with),
Ok(entry) => (entry, smcache.resolved_with, smcache.uri.clone()),
Err(CacheError::Malformed(_)) => {
// If we successfully resolved the sourcemap but it's broken somehow,
// We should still record that we resolved it.
raw_frame.data.resolved_with = Some(smcache.resolved_with);
raw_frame.data.sourcemap_origin = Some(smcache.uri.clone());
return Err(JsModuleErrorKind::MalformedSourcemap {
url: sourcemap_label.to_owned(),
});
Expand All @@ -169,6 +170,7 @@ async fn symbolicate_js_frame(
};

frame.data.sourcemap = Some(sourcemap_label.clone());
frame.data.sourcemap_origin = Some(sourcemap_origin);
frame.data.resolved_with = Some(resolved_with);

let sp = SourcePosition::new(line - 1, col.saturating_sub(1));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: crates/symbolicator-js/tests/integration/sourcemap.rs
assertion_line: 631
expression: response
---
stacktraces:
Expand All @@ -24,6 +25,7 @@ stacktraces:
- " if (data.failed) {"
data:
sourcemap: "http://localhost:<port>/files/app.js.map"
sourcemap_origin: "http://localhost:<port>/files/app.js.map"
resolved_with: scraping
symbolicated: true
raw_stacktraces:
Expand All @@ -43,4 +45,3 @@ scraping_attempts:
status: success
- url: "http://localhost:<port>/files/app.js.map"
status: success

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: crates/symbolicator-js/tests/integration/sourcemap.rs
assertion_line: 544
expression: response
---
stacktraces:
Expand All @@ -18,6 +19,12 @@ stacktraces:
context_line: "Sentry.captureException(new Error(\"Errör\"));"
data:
sourcemap: /Users/lucaforstner/code/github/getsentry/sentry-javascript-bundler-plugins/packages/playground/öut path/rollup/entrypoint1.js.map
sourcemap_origin:
bundled:
- "sentry://project_debug_file/1"
- source_map:
abs_path: /Users/lucaforstner/code/github/getsentry/sentry-javascript-bundler-plugins/packages/playground/öut path/rollup/entrypoint1.js.map
debug_id: 2f259f80-58b7-44cb-d7cd-de1505e7e718
resolved_with: debug-id
symbolicated: true
raw_stacktraces:
Expand All @@ -44,4 +51,3 @@ scraping_attempts:
status: not_attempted
- url: /Users/lucaforstner/code/github/getsentry/sentry-javascript-bundler-plugins/packages/playground/öut path/rollup/entrypoint1.js.map
status: not_attempted

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: crates/symbolicator-js/tests/integration/sourcemap.rs
assertion_line: 608
expression: response
---
stacktraces:
Expand All @@ -18,6 +19,7 @@ stacktraces:
in_app: true
data:
sourcemap: "app:///index.android.bundle.map"
sourcemap_origin: "sentry://project_debug_file/2"
resolved_with: release
symbolicated: true
raw_stacktraces:
Expand All @@ -30,4 +32,3 @@ scraping_attempts:
status: not_attempted
- url: "app:///index.android.bundle.map"
status: not_attempted

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: crates/symbolicator-js/tests/integration/sourcemap.rs
assertion_line: 574
expression: response
---
stacktraces:
Expand All @@ -25,6 +26,11 @@ stacktraces:
in_app: true
data:
sourcemap: "app:///_next/server/pages/test.min.js.map"
sourcemap_origin:
bundled:
- "sentry://project_debug_file/1"
- source_map:
abs_path: "app:///_next/server/pages/test.min.js.map"
resolved_with: release
symbolicated: true
raw_stacktraces:
Expand All @@ -41,4 +47,3 @@ scraping_attempts:
status: not_attempted
- url: "app:///_next/server/pages/test.min.js.map"
status: not_attempted

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: crates/symbolicator-js/tests/integration/sourcemap.rs
assertion_line: 343
expression: response
---
stacktraces:
Expand All @@ -18,6 +19,7 @@ stacktraces:
- "}"
data:
sourcemap: "http://example.com/indexed.min.js.map"
sourcemap_origin: "sentry://project_debug_file/2"
resolved_with: release-old
symbolicated: true
- function: multiply
Expand All @@ -38,6 +40,7 @@ stacktraces:
- "\t\treturn multiply(add(a, b), a, b) / c;"
data:
sourcemap: "http://example.com/indexed.min.js.map"
sourcemap_origin: "sentry://project_debug_file/2"
resolved_with: release-old
symbolicated: true
raw_stacktraces:
Expand Down Expand Up @@ -68,4 +71,3 @@ scraping_attempts:
status: not_attempted
- url: "http://example.com/file2.js"
status: not_attempted

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: crates/symbolicator-js/tests/integration/sourcemap.rs
assertion_line: 261
expression: response
---
stacktraces:
Expand All @@ -13,6 +14,7 @@ stacktraces:
context_line: "console.log('hello, World!')"
data:
sourcemap: "http://example.com/test.min.js"
sourcemap_origin: embedded
resolved_with: release
symbolicated: true
raw_stacktraces:
Expand All @@ -28,4 +30,3 @@ raw_stacktraces:
scraping_attempts:
- url: "http://example.com/test.min.js"
status: not_attempted

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: crates/symbolicator-js/tests/integration/sourcemap.rs
assertion_line: 552
assertion_line: 553
expression: response
---
stacktraces:
Expand All @@ -19,6 +19,7 @@ stacktraces:
colno: 9
data:
sourcemap: "http://example.com/embedded.js.map"
sourcemap_origin: "sentry://project_debug_file/2"
resolved_with: release
symbolicated: true
raw_stacktraces:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: crates/symbolicator-js/tests/integration/sourcemap.rs
assertion_line: 204
expression: response
---
stacktraces:
Expand All @@ -24,6 +25,7 @@ stacktraces:
- "}"
data:
sourcemap: "http://example.com/embedded.js.map"
sourcemap_origin: "sentry://project_debug_file/2"
resolved_with: release
symbolicated: true
raw_stacktraces:
Expand Down Expand Up @@ -52,4 +54,3 @@ scraping_attempts:
status: not_attempted
- url: "http://example.com/embedded.js.map"
status: not_attempted

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: crates/symbolicator-js/tests/integration/sourcemap.rs
assertion_line: 113
expression: response
---
stacktraces:
Expand Down Expand Up @@ -29,6 +30,7 @@ stacktraces:
- "})();"
data:
sourcemap: "http://example.com/test.min.js.map"
sourcemap_origin: "sentry://project_debug_file/2"
resolved_with: release
symbolicated: true
- function: invoke
Expand All @@ -52,6 +54,7 @@ stacktraces:
- " invoke(data);"
data:
sourcemap: "http://example.com/test.min.js.map"
sourcemap_origin: "sentry://project_debug_file/2"
resolved_with: release
symbolicated: true
- function: onFailure
Expand All @@ -74,6 +77,7 @@ stacktraces:
- " if (data.failed) {"
data:
sourcemap: "http://example.com/test.min.js.map"
sourcemap_origin: "sentry://project_debug_file/2"
resolved_with: release
symbolicated: true
raw_stacktraces:
Expand Down Expand Up @@ -118,4 +122,3 @@ scraping_attempts:
status: not_attempted
- url: "http://example.com/test.min.js.map"
status: not_attempted

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: crates/symbolicator-js/tests/integration/sourcemap.rs
assertion_line: 293
expression: response
---
stacktraces:
Expand All @@ -16,6 +17,7 @@ stacktraces:
- "}"
data:
sourcemap: "app:///nofiles.js.map"
sourcemap_origin: "sentry://project_debug_file/2"
resolved_with: release
symbolicated: true
raw_stacktraces:
Expand All @@ -35,4 +37,3 @@ scraping_attempts:
status: not_attempted
- url: "app:///nofiles.js.map"
status: not_attempted

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: crates/symbolicator-js/tests/integration/sourcemap.rs
assertion_line: 164
expression: response
---
stacktraces:
Expand All @@ -24,6 +25,7 @@ stacktraces:
- "}"
data:
sourcemap: "http://example.com/file.min.js.map"
sourcemap_origin: "sentry://project_debug_file/2"
resolved_with: release-old
symbolicated: true
raw_stacktraces:
Expand Down Expand Up @@ -54,4 +56,3 @@ scraping_attempts:
status: not_attempted
- url: "http://example.com/file1.js"
status: not_attempted

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: crates/symbolicator-js/tests/integration/sourcemap.rs
assertion_line: 475
expression: response
---
stacktraces:
Expand All @@ -25,6 +26,7 @@ stacktraces:
in_app: true
data:
sourcemap: "http://example.com/test1.min.js.map"
sourcemap_origin: "sentry://project_debug_file/2"
resolved_with: release-old
symbolicated: true
- function: test
Expand All @@ -48,6 +50,7 @@ stacktraces:
in_app: false
data:
sourcemap: "http://example.com/test2.min.js.map"
sourcemap_origin: "sentry://project_debug_file/4"
resolved_with: release-old
symbolicated: true
raw_stacktraces:
Expand Down Expand Up @@ -77,4 +80,3 @@ scraping_attempts:
status: not_attempted
- url: "http://example.com/test2.min.js.map"
status: not_attempted

0 comments on commit 287e9ec

Please sign in to comment.