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): Extract client sdk for profiles #3915

Merged
merged 6 commits into from
Aug 12, 2024
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 @@ -19,6 +19,7 @@
- Make the tcp listen backlog configurable and raise the default to 1024. ([#3899](https://github.com/getsentry/relay/pull/3899))
- Extract `user.geo.country_code` into span indexed. ([#3911](https://github.com/getsentry/relay/pull/3911))
- Add `span.system` tag to span metrics ([#3913](https://github.com/getsentry/relay/pull/3913))
- Extract client sdk from transaction into profiles. ([#3915](https://github.com/getsentry/relay/pull/3915))

## 24.7.1

Expand Down
19 changes: 19 additions & 0 deletions relay-profiling/src/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ pub struct ProfileMetadata {

#[serde(skip_serializing_if = "Option::is_none")]
debug_meta: Option<DebugMeta>,

#[serde(skip_serializing_if = "Option::is_none")]
client_sdk: Option<ClientSdk>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ClientSdk {
name: String,
version: String,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
Expand Down Expand Up @@ -237,6 +246,16 @@ pub fn parse_android_profile(
}
}

profile.metadata.client_sdk = match (
transaction_metadata.get("client_sdk.name"),
transaction_metadata.get("client_sdk.version"),
) {
(Some(name), Some(version)) => Some(ClientSdk {
name: name.to_owned(),
version: version.to_owned(),
}),
_ => None,
};
profile.metadata.transaction_metadata = transaction_metadata;
profile.metadata.transaction_tags = transaction_tags;

Expand Down
19 changes: 17 additions & 2 deletions relay-profiling/src/extract_from_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ pub fn extract_transaction_metadata(event: &Event) -> BTreeMap<String, String> {
}
}

if let Some(client_sdk) = event.client_sdk.value() {
if let Some(sdk_name) = client_sdk.name.value() {
tags.insert("client_sdk.name".to_owned(), sdk_name.to_owned());
}
if let Some(sdk_version) = client_sdk.version.value() {
tags.insert("client_sdk.version".to_owned(), sdk_version.to_owned());
}
}

tags
}

Expand Down Expand Up @@ -125,14 +134,20 @@ mod tests {
},
"timestamp": "2011-05-02T17:41:36Z",
"start_timestamp": "2011-05-02T17:40:36Z",
"sdk": {
"name": "sentry.python",
"version": "2.10.7",
},
})
.into(),
);

let metadata = extract_transaction_metadata(&event.0.unwrap());
insta::assert_debug_snapshot!(metadata, @r#"
insta::assert_debug_snapshot!(metadata, @r###"
{
"app.identifier": "io.sentry.myexample",
"client_sdk.name": "sentry.python",
"client_sdk.version": "2.10.7",
"dist": "mydist",
"environment": "myenvironment",
"http.method": "GET",
Expand All @@ -143,6 +158,6 @@ mod tests {
"transaction.start": "2011-05-02T17:40:36.000000000+00:00",
"transaction.status": "ok",
}
"#);
"###);
}
}
20 changes: 20 additions & 0 deletions relay-profiling/src/sample/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,15 @@ pub struct ProfileMetadata {

#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
transaction_tags: BTreeMap<String, String>,

#[serde(skip_serializing_if = "Option::is_none")]
pub client_sdk: Option<ClientSdk>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ClientSdk {
name: String,
version: String,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
Expand Down Expand Up @@ -354,6 +363,16 @@ pub fn parse_sample_profile(
}
}

profile.metadata.client_sdk = match (
transaction_metadata.get("client_sdk.name"),
transaction_metadata.get("client_sdk.version"),
) {
(Some(name), Some(version)) => Some(ClientSdk {
name: name.to_owned(),
version: version.to_owned(),
}),
_ => None,
};
profile.metadata.transaction_metadata = transaction_metadata;
profile.metadata.transaction_tags = transaction_tags;

Expand Down Expand Up @@ -410,6 +429,7 @@ mod tests {
dist: "9999".to_string(),
transaction_metadata: BTreeMap::new(),
transaction_tags: BTreeMap::new(),
client_sdk: None,
},
profile: SampleProfile {
queue_metadata: Some(HashMap::new()),
Expand Down
Loading