Skip to content

Commit

Permalink
feat(profiling): Extract client sdk for profiles (#3915)
Browse files Browse the repository at this point in the history
Similar to #3882, but for the existing formats. Extract the sdk info
from the transaction event.
  • Loading branch information
Zylphrex committed Aug 12, 2024
1 parent 609dc91 commit 2aa4253
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
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

0 comments on commit 2aa4253

Please sign in to comment.