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(profiling): add support for proguard images and refactor NativeDebugImage to DebugImage #4418

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions relay-profiling/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ serde_json = { workspace = true }
serde_path_to_error = { workspace = true }
thiserror = { workspace = true }
url = { workspace = true }
uuid = { workspace = true }

[dev-dependencies]
insta = { workspace = true }
9 changes: 9 additions & 0 deletions relay-profiling/src/android/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use data_encoding::BASE64_NOPAD;
use relay_event_schema::protocol::EventId;
use serde::{Deserialize, Serialize};

use crate::debug_image::get_proguard_image;
use crate::measurements::ChunkMeasurement;
use crate::sample::v2::ProfileData;
use crate::types::{ClientSdk, DebugMeta};
Expand Down Expand Up @@ -128,6 +129,14 @@ fn parse_chunk(payload: &[u8]) -> Result<Chunk, ProfileError> {
)
.as_secs_f64();

// If build_id is not empty but we don't have any DebugImage set,
// we create the proper Proguard image and set the uuid.
if !profile.metadata.build_id.is_empty() && profile.metadata.debug_meta.is_none() {
profile.metadata.debug_meta = Some(DebugMeta {
images: vec![get_proguard_image(&profile.metadata.build_id)?],
})
}

Ok(profile)
}

Expand Down
9 changes: 9 additions & 0 deletions relay-profiling/src/android/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use data_encoding::BASE64_NOPAD;
use relay_event_schema::protocol::{EventId, SpanId};
use serde::{Deserialize, Serialize};

use crate::debug_image::get_proguard_image;
use crate::measurements::LegacyMeasurement;
use crate::sample::v1::SampleProfile;
use crate::transaction_metadata::TransactionMetadata;
Expand Down Expand Up @@ -254,6 +255,14 @@ pub fn parse_android_profile(
profile.metadata.transaction_metadata = transaction_metadata;
profile.metadata.transaction_tags = transaction_tags;

// If build_id is not empty but we don't have any DebugImage set,
// we create the proper Proguard image and set the uuid.
if !profile.metadata.build_id.is_empty() && profile.metadata.debug_meta.is_none() {
profile.metadata.debug_meta = Some(DebugMeta {
images: vec![get_proguard_image(&profile.metadata.build_id)?],
})
}

serde_json::to_vec(&profile).map_err(|_| ProfileError::CannotSerializePayload)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use std::str::FromStr;

use relay_event_schema::protocol::{Addr, DebugId, NativeImagePath};
use serde::{Deserialize, Serialize};
use uuid::{Error as UuidError, Uuid};

use crate::utils;

Expand All @@ -9,14 +12,15 @@ enum ImageType {
MachO,
Symbolic,
Sourcemap,
Proguard,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
pub struct NativeDebugImage {
#[serde(alias = "name")]
code_file: NativeImagePath,
#[serde(alias = "id")]
debug_id: DebugId,
pub struct DebugImage {
#[serde(skip_serializing_if = "Option::is_none", alias = "name")]
code_file: Option<NativeImagePath>,
#[serde(skip_serializing_if = "Option::is_none", alias = "id")]
debug_id: Option<DebugId>,
#[serde(rename = "type")]
image_type: ImageType,

Expand All @@ -32,19 +36,36 @@ pub struct NativeDebugImage {
skip_serializing_if = "utils::is_zero"
)]
image_size: u64,

#[serde(skip_serializing_if = "Option::is_none", alias = "build_id")]
uuid: Option<Uuid>,
}

pub fn get_proguard_image(uuid: &str) -> Result<DebugImage, UuidError> {
Ok(DebugImage {
code_file: None,
debug_id: None,
image_type: ImageType::Proguard,
image_addr: None,
image_vmaddr: None,
image_size: 0,
uuid: Some(Uuid::from_str(uuid)?),
})
}

#[cfg(test)]
mod tests {
use relay_event_schema::protocol::{Addr, DebugImage, NativeDebugImage as SchemaImage};
use relay_event_schema::protocol::{
Addr, DebugImage, NativeDebugImage as SchemaImage, ProguardDebugImage,
};
use relay_protocol::{Annotated, Map};

use super::NativeDebugImage;
use crate::debug_image::DebugImage as ProfDebugImage;

#[test]
fn test_native_debug_image_compatibility() {
let image_json = r#"{"debug_id":"32420279-25E2-34E6-8BC7-8A006A8F2425","image_addr":"0x000000010258c000","code_file":"/private/var/containers/Bundle/Application/C3511752-DD67-4FE8-9DA2-ACE18ADFAA61/TrendingMovies.app/TrendingMovies","type":"macho","image_size":1720320,"image_vmaddr":"0x0000000100000000"}"#;
let image: NativeDebugImage = serde_json::from_str(image_json).unwrap();
let image: ProfDebugImage = serde_json::from_str(image_json).unwrap();
let json = serde_json::to_string(&image).unwrap();
let annotated = Annotated::from_json(&json[..]).unwrap();
assert_eq!(
Expand All @@ -61,4 +82,19 @@ mod tests {
other: Map::new(),
}))), annotated);
}

#[test]
fn test_android_image_compatibility() {
let image_json = r#"{"uuid":"32420279-25E2-34E6-8BC7-8A006A8F2425","type":"proguard"}"#;
let image: ProfDebugImage = serde_json::from_str(image_json).unwrap();
let json = serde_json::to_string(&image).unwrap();
let annotated = Annotated::from_json(&json[..]).unwrap();
assert_eq!(
Annotated::new(DebugImage::Proguard(Box::new(ProguardDebugImage {
uuid: Annotated::new("32420279-25E2-34E6-8BC7-8A006A8F2425".parse().unwrap()),
other: Map::new(),
}))),
annotated
);
}
}
2 changes: 2 additions & 0 deletions relay-profiling/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub enum ProfileError {
DurationIsZero,
#[error("filtered profile")]
Filtered(FilterStatKey),
#[error(transparent)]
InvalidBuildID(#[from] uuid::Error),
}

impl ProfileError {
Expand Down
2 changes: 1 addition & 1 deletion relay-profiling/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ pub use crate::error::ProfileError;
pub use crate::outcomes::discard_reason;

mod android;
mod debug_image;
mod error;
mod extract_from_transaction;
mod measurements;
mod native_debug_image;
mod outcomes;
mod sample;
mod transaction_metadata;
Expand Down
1 change: 1 addition & 0 deletions relay-profiling/src/outcomes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ pub fn discard_reason(err: ProfileError) -> &'static str {
ProfileError::DurationIsTooLong => "profiling_duration_is_too_long",
ProfileError::DurationIsZero => "profiling_duration_is_zero",
ProfileError::Filtered(_) => "profiling_filtered",
ProfileError::InvalidBuildID(_) => "invalid_build_id",
}
}
4 changes: 2 additions & 2 deletions relay-profiling/src/sample/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};

use crate::native_debug_image::NativeDebugImage;
use crate::debug_image::DebugImage;
use relay_event_schema::protocol::Addr;

pub mod v1;
Expand Down Expand Up @@ -90,7 +90,7 @@ impl Frame {
pub struct DebugMeta {
/// A list of debug files needed to symbolicate/deobfuscate this profile.
/// Useful to pass source maps, ProGuard files or image libraries.
pub images: Vec<NativeDebugImage>,
pub images: Vec<DebugImage>,
}

impl DebugMeta {
Expand Down
4 changes: 2 additions & 2 deletions relay-profiling/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use serde::{Deserialize, Serialize};

use crate::native_debug_image::NativeDebugImage;
use crate::debug_image::DebugImage;

/// This is a serde-friendly version of <https://github.com/getsentry/relay/blob/52bc345871b4e5cca19ed73c17730eeef092028b/relay-event-schema/src/protocol/debugmeta.rs#L516>
#[derive(Default, Debug, Serialize, Deserialize, Clone)]
pub struct DebugMeta {
images: Vec<NativeDebugImage>,
pub(crate) images: Vec<DebugImage>,
}

/// This is a serde-friendly version of <https://github.com/getsentry/relay/blob/52bc345871b4e5cca19ed73c17730eeef092028b/relay-event-schema/src/protocol/clientsdk.rs#L8>
Expand Down
Loading