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 4 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
14 changes: 14 additions & 0 deletions relay-profiling/src/android.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::client_sdk::ClientSdk;
use crate::measurements::Measurement;
use crate::native_debug_image::NativeDebugImage;
use crate::sample::v1::SampleProfile;
Expand Down Expand Up @@ -91,6 +92,9 @@ 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)]
Expand Down Expand Up @@ -237,6 +241,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
7 changes: 7 additions & 0 deletions relay-profiling/src/client_sdk.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ClientSdk {
Zylphrex marked this conversation as resolved.
Show resolved Hide resolved
Zylphrex marked this conversation as resolved.
Show resolved Hide resolved
pub name: String,
pub version: String,
}
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",
}
"#);
"###);
}
}
1 change: 1 addition & 0 deletions relay-profiling/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub use crate::error::ProfileError;
pub use crate::outcomes::discard_reason;

mod android;
mod client_sdk;
mod error;
mod extract_from_transaction;
mod measurements;
Expand Down
15 changes: 15 additions & 0 deletions relay-profiling/src/sample/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use itertools::Itertools;
use relay_event_schema::protocol::{EventId, SpanId};
use serde::{Deserialize, Serialize};

use crate::client_sdk::ClientSdk;
use crate::error::ProfileError;
use crate::measurements::Measurement;
use crate::sample::{DebugMeta, Frame, ThreadMetadata, Version};
Expand Down Expand Up @@ -255,6 +256,9 @@ 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)]
Expand Down Expand Up @@ -354,6 +358,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,
};
Dav1dde marked this conversation as resolved.
Show resolved Hide resolved
profile.metadata.transaction_metadata = transaction_metadata;
profile.metadata.transaction_tags = transaction_tags;

Expand Down Expand Up @@ -410,6 +424,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
7 changes: 1 addition & 6 deletions relay-profiling/src/sample/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use serde::{Deserialize, Serialize};
use relay_event_schema::protocol::EventId;
use relay_metrics::FiniteF64;

use crate::client_sdk::ClientSdk;
use crate::error::ProfileError;
use crate::measurements::Measurement;
use crate::sample::{DebugMeta, Frame, ThreadMetadata, Version};
Expand All @@ -42,12 +43,6 @@ pub struct ProfileMetadata {
pub version: Version,
}

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

#[derive(Debug, Serialize, Deserialize)]
pub struct Sample {
/// Unix timestamp in seconds with millisecond precision when the sample
Expand Down
Loading