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

fix(profiling): Re-encode the Typescript payload to normalize #1372

Merged
Merged
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Treat "unknown" transaction source as low cardinality for safe SDKs. ([#1352](https://github.com/getsentry/relay/pull/1352), [#1356](https://github.com/getsentry/relay/pull/1356))
- Conditionally write a default transaction source to the transaction payload. ([#1354](https://github.com/getsentry/relay/pull/1354))
- Change to the internals of the healthcheck endpoint. ([#1374](https://github.com/getsentry/relay/pull/1374))
- Re-encode the Typescript payload to normalize. ([#1372](https://github.com/getsentry/relay/pull/1372))

**Bug Fixes**:

Expand Down
59 changes: 57 additions & 2 deletions relay-profiling/src/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,18 @@ pub fn parse_typescript_profile(payload: &[u8]) -> Result<Vec<u8>, ProfileError>
return Err(ProfileError::NotEnoughSamples);
}

Ok(payload.to_vec())
match serde_json::to_vec(&profile) {
Ok(payload) => Ok(payload),
Err(_) => Err(ProfileError::CannotSerializePayload),
}
}

#[cfg(test)]
mod tests {
use super::*;
use serde::Deserialize;

use crate::parse_typescript_profile;
use crate::ProfileError;

#[test]
fn test_roundtrip_typescript() {
Expand All @@ -53,4 +59,53 @@ mod tests {
assert!(data.is_ok());
assert!(parse_typescript_profile(&data.unwrap()[..]).is_ok());
}

#[derive(Debug, Deserialize)]
struct MinimalTypescriptProfile {
duration_ns: u64,
}

fn minimal_profile_from_json(data: &[u8]) -> Result<MinimalTypescriptProfile, ProfileError> {
serde_json::from_slice(data).map_err(ProfileError::InvalidJson)
}

#[test]
fn test_normalization() {
let payload = r#"
{
"profile": [
{
"name": "process_name",
"args": {
"name": "tsc"
},
"cat": "__metadata",
"ph": "M",
"ts": 189644.04201507568,
"pid": 1,
"tid": 1
}
],
"device_locale": "en_CA.UTF-8",
"device_manufacturer": "GitHub",
"device_model": "GitHub Actions",
"device_os_name": "darwin",
"device_os_version": "21.4.0",
"device_is_emulator": false,
"transaction_name": "typescript.compile",
"version_code": "1",
"version_name": "0.1",
"duration_ns": "87880000000",
"trace_id": "a882b1448a1c446a910063f6e9e374c2",
"transaction_id": "616fd15cb7ff4143a5d8d8e1cb74d141",
"platform": "typescript",
"environment": "ci",
"profile_id": "74c735d8d1f342559bf6b387703c2fd6"
}
"#;
let data = parse_typescript_profile(payload.as_bytes());
let minimal_profile = minimal_profile_from_json(&data.unwrap()[..]);
assert!(minimal_profile.is_ok());
assert!(minimal_profile.unwrap().duration_ns == 87880000000);
}
}
31 changes: 0 additions & 31 deletions relay-server/tests/fixtures/profiles/android.json

This file was deleted.

Loading