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(protocol): Add sourcemap debug image type to protocol #1869

Merged
merged 4 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

**Features**:

- Protocol validation for source map image type. ([#1869](https://github.com/getsentry/relay/pull/1869))

## 23.2.0

**Features**:
Expand Down
67 changes: 67 additions & 0 deletions relay-general/src/protocol/debugmeta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,43 @@ pub struct NativeDebugImage {
pub other: Object<Value>,
}

/// A debug image pointing to a source map.
///
/// Examples:
///
/// ```json
/// {
/// "type": "sourcemap",
/// "code_file": "https://example.com/static/js/main.min.js",
/// "debug_id": "395835f4-03e0-4436-80d3-136f0749a893"
/// }
/// ```
///
/// **Note:** Stack frames and the correlating entries in the debug image here
/// for `code_file`/`abs_path` are not PII stripped as they need to line up
/// perfectly for source map processing.
#[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, IntoValue, ProcessValue)]
#[cfg_attr(feature = "jsonschema", derive(JsonSchema))]
pub struct SourceMapDebugImage {
/// Path and name of the image file as URL. (required).
///
/// The absolute path to the minified JavaScript file. This helps to correlate the file to the stack trace.
#[metastructure(required = "true")]
pub code_file: Annotated<String>,

/// Unique debug identifier of the source map.
#[metastructure(required = "true")]
pub debug_id: Annotated<DebugId>,

/// Path and name of the associated source map.
#[metastructure(pii = "maybe")]
pub debug_file: Annotated<String>,

/// Additional arbitrary fields for forwards compatibility.
#[metastructure(additional_properties)]
pub other: Object<Value>,
}

/// Proguard mapping file.
///
/// Proguard images refer to `mapping.txt` files generated when Proguard obfuscates function names. The Java SDK integrations assign this file a unique identifier, which has to be included in the list of images.
Expand Down Expand Up @@ -449,6 +486,8 @@ pub enum DebugImage {
Proguard(Box<ProguardDebugImage>),
/// WASM debug image.
Wasm(Box<NativeDebugImage>),
/// Source map debug image.
SourceMap(Box<SourceMapDebugImage>),
/// A debug image that is unknown to this protocol specification.
#[metastructure(fallback_variant)]
Other(Object<Value>),
Expand Down Expand Up @@ -824,6 +863,34 @@ mod tests {
assert_eq!(json, image.to_json_pretty().unwrap());
}

#[test]
fn test_source_map_image_roundtrip() {
let json = r#"{
"code_file": "https://mycdn.invalid/foo.js.min",
"debug_id": "971f98e5-ce60-41ff-b2d7-235bbeb34578",
"debug_file": "https://mycdn.invalid/foo.js.map",
"other": "value",
"type": "sourcemap"
}"#;

let image = Annotated::new(DebugImage::SourceMap(Box::new(SourceMapDebugImage {
code_file: Annotated::new("https://mycdn.invalid/foo.js.min".into()),
debug_file: Annotated::new("https://mycdn.invalid/foo.js.map".into()),
debug_id: Annotated::new("971f98e5-ce60-41ff-b2d7-235bbeb34578".parse().unwrap()),
other: {
let mut map = Object::new();
map.insert(
"other".to_string(),
Annotated::new(Value::String("value".to_string())),
);
map
},
})));

assert_eq!(image, Annotated::from_json(json).unwrap());
assert_eq!(json, image.to_json_pretty().unwrap());
}

#[test]
fn test_debug_image_other_roundtrip() {
let json = r#"{"other":"value","type":"mytype"}"#;
Expand Down
45 changes: 44 additions & 1 deletion relay-general/tests/snapshots/test_fixtures__event_schema.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: relay-general/tests/test_fixtures.rs
assertion_line: 109
expression: "relay_general::protocol::event_json_schema()"
---
{
Expand Down Expand Up @@ -1013,6 +1012,9 @@ expression: "relay_general::protocol::event_json_schema()"
{
"$ref": "#/definitions/NativeDebugImage"
},
{
"$ref": "#/definitions/SourceMapDebugImage"
},
{
"type": "object",
"additionalProperties": true
Expand Down Expand Up @@ -2905,6 +2907,47 @@ expression: "relay_general::protocol::event_json_schema()"
}
]
},
"SourceMapDebugImage": {
"description": " A debug image pointing to a source map.\n\n Examples:\n\n ```json\n {\n \"type\": \"sourcemap\",\n \"code_file\": \"https://example.com/static/js/main.min.js\",\n \"debug_id\": \"395835f4-03e0-4436-80d3-136f0749a893\"\n }\n ```\n\n **Note:** Stack frames and the correlating entries in the debug image here\n for `code_file`/`abs_path` are not PII stripped as they need to line up\n perfectly for source map processing.",
"anyOf": [
{
"type": "object",
"required": [
"code_file",
"debug_id"
],
"properties": {
"code_file": {
"description": " Path and name of the image file as URL. (required).\n\n The absolute path to the minified JavaScript file. This helps to correlate the file to the stack trace.",
"type": [
"string",
"null"
]
},
"debug_file": {
"description": " Path and name of the associated source map.",
"default": null,
"type": [
"string",
"null"
]
},
"debug_id": {
"description": " Unique debug identifier of the source map.",
"anyOf": [
{
"$ref": "#/definitions/DebugId"
},
{
"type": "null"
}
]
}
},
"additionalProperties": false
}
]
},
"SpanId": {
"description": " A 16-character hex string as described in the W3C trace context spec.",
"anyOf": [
Expand Down