Skip to content

Commit

Permalink
feat(js): Return "sourcemap origin"
Browse files Browse the repository at this point in the history
  • Loading branch information
loewenheim committed Apr 26, 2024
1 parent b30b564 commit ef215f2
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 15 deletions.
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 @@ -139,13 +139,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 @@ -161,6 +162,7 @@ async fn symbolicate_js_frame(

let mut frame = raw_frame.clone();
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,8 @@ stacktraces:
- " if (data.failed) {"
data:
sourcemap: "http://localhost:<port>/files/app.js.map"
sourcemap_origin:
scraped_file: "http://localhost:64973/files/app.js.map#1714123653"
resolved_with: scraping
symbolicated: true
raw_stacktraces:
Expand All @@ -43,4 +46,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,8 @@ stacktraces:
in_app: true
data:
sourcemap: "app:///index.android.bundle.map"
sourcemap_origin:
individual_file: "sentry://project_debug_file/2"
resolved_with: release
symbolicated: true
raw_stacktraces:
Expand All @@ -30,4 +33,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,8 @@ stacktraces:
- "}"
data:
sourcemap: "http://example.com/indexed.min.js.map"
sourcemap_origin:
individual_file: "sentry://project_debug_file/2"
resolved_with: release-old
symbolicated: true
- function: multiply
Expand All @@ -38,6 +41,8 @@ stacktraces:
- "\t\treturn multiply(add(a, b), a, b) / c;"
data:
sourcemap: "http://example.com/indexed.min.js.map"
sourcemap_origin:
individual_file: "sentry://project_debug_file/2"
resolved_with: release-old
symbolicated: true
raw_stacktraces:
Expand Down Expand Up @@ -68,4 +73,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,5 +1,6 @@
---
source: crates/symbolicator-js/tests/integration/sourcemap.rs
assertion_line: 204
expression: response
---
stacktraces:
Expand All @@ -24,6 +25,8 @@ stacktraces:
- "}"
data:
sourcemap: "http://example.com/embedded.js.map"
sourcemap_origin:
individual_file: "sentry://project_debug_file/2"
resolved_with: release
symbolicated: true
raw_stacktraces:
Expand Down Expand Up @@ -52,4 +55,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,8 @@ stacktraces:
- "})();"
data:
sourcemap: "http://example.com/test.min.js.map"
sourcemap_origin:
individual_file: "sentry://project_debug_file/2"
resolved_with: release
symbolicated: true
- function: invoke
Expand All @@ -52,6 +55,8 @@ stacktraces:
- " invoke(data);"
data:
sourcemap: "http://example.com/test.min.js.map"
sourcemap_origin:
individual_file: "sentry://project_debug_file/2"
resolved_with: release
symbolicated: true
- function: onFailure
Expand All @@ -74,6 +79,8 @@ stacktraces:
- " if (data.failed) {"
data:
sourcemap: "http://example.com/test.min.js.map"
sourcemap_origin:
individual_file: "sentry://project_debug_file/2"
resolved_with: release
symbolicated: true
raw_stacktraces:
Expand Down Expand Up @@ -118,4 +125,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,8 @@ stacktraces:
- "}"
data:
sourcemap: "app:///nofiles.js.map"
sourcemap_origin:
individual_file: "sentry://project_debug_file/2"
resolved_with: release
symbolicated: true
raw_stacktraces:
Expand All @@ -35,4 +38,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,8 @@ stacktraces:
- "}"
data:
sourcemap: "http://example.com/file.min.js.map"
sourcemap_origin:
individual_file: "sentry://project_debug_file/2"
resolved_with: release-old
symbolicated: true
raw_stacktraces:
Expand Down Expand Up @@ -54,4 +57,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,8 @@ stacktraces:
in_app: true
data:
sourcemap: "http://example.com/test1.min.js.map"
sourcemap_origin:
individual_file: "sentry://project_debug_file/2"
resolved_with: release-old
symbolicated: true
- function: test
Expand All @@ -48,6 +51,8 @@ stacktraces:
in_app: false
data:
sourcemap: "http://example.com/test2.min.js.map"
sourcemap_origin:
individual_file: "sentry://project_debug_file/4"
resolved_with: release-old
symbolicated: true
raw_stacktraces:
Expand Down Expand Up @@ -77,4 +82,3 @@ scraping_attempts:
status: not_attempted
- url: "http://example.com/test2.min.js.map"
status: not_attempted

0 comments on commit ef215f2

Please sign in to comment.