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

ref(profiling): add segment_id to the profile #3265

Merged
merged 7 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -36,6 +36,7 @@
- Filter null values from metrics summary tags. ([#3204](https://github.com/getsentry/relay/pull/3204))
- Emit a usage metric for every span seen. ([#3209](https://github.com/getsentry/relay/pull/3209))
- Add namespace for profile metrics. ([#3229](https://github.com/getsentry/relay/pull/3229))
- Add segment_id to the profile ([#3265](https://github.com/getsentry/relay/pull/3265))
viglia marked this conversation as resolved.
Show resolved Hide resolved

## 24.2.0

Expand Down
15 changes: 14 additions & 1 deletion relay-event-schema/src/protocol/contexts/trace.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#[cfg(feature = "jsonschema")]
use relay_jsonschema_derive::JsonSchema;
use relay_protocol::{Annotated, Empty, Error, FromValue, IntoValue, Object, Value};
use serde::{Deserialize, Serialize};

use crate::processor::ProcessValue;
use crate::protocol::{OperationType, OriginType, SpanStatus};
Expand Down Expand Up @@ -39,7 +40,19 @@ impl AsRef<str> for TraceId {
}

/// A 16-character hex string as described in the W3C trace context spec.
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq, Empty, IntoValue, ProcessValue)]
#[derive(
Clone,
Debug,
Default,
Eq,
Hash,
PartialEq,
Empty,
IntoValue,
ProcessValue,
Serialize,
Deserialize,
)]
viglia marked this conversation as resolved.
Show resolved Hide resolved
#[cfg_attr(feature = "jsonschema", derive(JsonSchema))]
pub struct SpanId(pub String);

Expand Down
8 changes: 7 additions & 1 deletion relay-profiling/src/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::{BTreeMap, HashMap};
use android_trace_log::chrono::{DateTime, Utc};
use android_trace_log::{AndroidTraceLog, Clock, Vm};
use data_encoding::BASE64_NOPAD;
use relay_event_schema::protocol::EventId;
use relay_event_schema::protocol::{EventId, SpanId};
use serde::{Deserialize, Serialize};

use crate::measurements::Measurement;
Expand Down Expand Up @@ -217,6 +217,12 @@ pub fn parse_android_profile(
profile.metadata.environment = environment.to_owned();
}

if let Some(segment_id) = transaction_metadata.get("segment_id") {
if let Some(transaction_metadata) = profile.metadata.transaction.as_mut() {
transaction_metadata.segment_id = SpanId(segment_id.to_owned());
viglia marked this conversation as resolved.
Show resolved Hide resolved
}
}

profile.metadata.transaction_metadata = transaction_metadata;
profile.metadata.transaction_tags = transaction_tags;

Expand Down
4 changes: 4 additions & 0 deletions relay-profiling/src/extract_from_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ pub fn extract_transaction_metadata(event: &Event) -> BTreeMap<String, String> {
if let Some(op) = trace_context.op.value() {
tags.insert("transaction.op".to_owned(), op.to_owned());
}

if let Some(segment_id) = trace_context.span_id.value() {
tags.insert("segment_id".to_owned(), segment_id.to_owned().0);
}
}

if let Some(http_method) = extract_http_method(event) {
Expand Down
18 changes: 16 additions & 2 deletions relay-profiling/src/sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::ops::Range;

use chrono::{DateTime, Utc};
use itertools::Itertools;
use relay_event_schema::protocol::{Addr, EventId};
use relay_event_schema::protocol::{Addr, EventId, SpanId};
use serde::{Deserialize, Serialize};

use crate::error::ProfileError;
Expand Down Expand Up @@ -393,6 +393,12 @@ pub fn parse_sample_profile(
profile.metadata.environment = environment.to_owned();
}

if let Some(segment_id) = transaction_metadata.get("segment_id") {
if let Some(transaction_metadata) = profile.metadata.transaction.as_mut() {
transaction_metadata.segment_id = SpanId(segment_id.to_owned());
}
}

profile.metadata.transaction_metadata = transaction_metadata;
profile.metadata.transaction_tags = transaction_tags;

Expand All @@ -401,6 +407,8 @@ pub fn parse_sample_profile(

#[cfg(test)]
mod tests {
use relay_event_schema::protocol::SpanId;

use super::*;
use std::time::Duration;

Expand Down Expand Up @@ -549,6 +557,7 @@ mod tests {
relative_end_ns: 30,
relative_start_ns: 10,
trace_id: EventId::new(),
segment_id: SpanId("bd2eb23da2beb459".to_string()),
});
profile.profile.stacks.push(vec![0]);
profile.profile.samples.extend(vec![
Expand Down Expand Up @@ -600,6 +609,7 @@ mod tests {
relative_end_ns: 100,
relative_start_ns: 50,
trace_id: EventId::new(),
segment_id: SpanId("bd2eb23da2beb459".to_string()),
});
profile.profile.stacks.push(vec![0]);
profile.profile.samples.extend(vec![
Expand Down Expand Up @@ -647,6 +657,7 @@ mod tests {
relative_end_ns: 100,
relative_start_ns: 0,
trace_id: EventId::new(),
segment_id: SpanId("bd2eb23da2beb459".to_string()),
};

profile.metadata.transactions.push(transaction.clone());
Expand Down Expand Up @@ -707,6 +718,7 @@ mod tests {
relative_end_ns: 100,
relative_start_ns: 0,
trace_id: EventId::new(),
segment_id: SpanId("bd2eb23da2beb459".to_string()),
};

profile.metadata.transaction = Some(transaction);
Expand Down Expand Up @@ -820,6 +832,7 @@ mod tests {
relative_end_ns: 100,
relative_start_ns: 0,
trace_id: EventId::new(),
segment_id: SpanId("bd2eb23da2beb459".to_string()),
};

profile.metadata.transaction = Some(transaction);
Expand Down Expand Up @@ -990,7 +1003,8 @@ mod tests {
"active_thread_id": 1,
"id":"9789498b-6970-4dda-b2a1-f9cb91d1a445",
"name":"blah",
"trace_id":"809ff2c0-e185-4c21-8f21-6a6fef009352"
"trace_id":"809ff2c0-e185-4c21-8f21-6a6fef009352",
"segment_id":"bd2eb23da2beb459"
},
"dist":"9999",
"profile":{
Expand Down
6 changes: 5 additions & 1 deletion relay-profiling/src/transaction_metadata.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use relay_event_schema::protocol::EventId;
use relay_event_schema::protocol::{EventId, SpanId};
use serde::{Deserialize, Serialize};

use crate::utils::{deserialize_number_from_string, is_zero};
Expand All @@ -8,6 +8,7 @@ pub struct TransactionMetadata {
pub id: EventId,
pub name: String,
pub trace_id: EventId,
pub segment_id: SpanId,

#[serde(default, deserialize_with = "deserialize_number_from_string")]
pub active_thread_id: u64,
Expand Down Expand Up @@ -65,6 +66,7 @@ mod tests {
relative_end_ns: 133,
relative_start_ns: 1,
trace_id: "4705BD13-368A-499A-AA48-439DAFD9CFB0".parse().unwrap(),
segment_id: SpanId("bd2eb23da2beb459".to_string()),
};
assert!(metadata.valid());
}
Expand All @@ -80,6 +82,7 @@ mod tests {
relative_end_ns: 133,
relative_start_ns: 1,
trace_id: "4705BD13-368A-499A-AA48-439DAFD9CFB0".parse().unwrap(),
segment_id: SpanId("bd2eb23da2beb459".to_string()),
};
assert!(!metadata.valid());
}
Expand All @@ -95,6 +98,7 @@ mod tests {
relative_end_ns: 0,
relative_start_ns: 0,
trace_id: "4705BD13-368A-499A-AA48-439DAFD9CFB0".parse().unwrap(),
segment_id: SpanId("bd2eb23da2beb459".to_string()),
};
assert!(metadata.valid());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"trace_id": "7D6DB784-355E-4D7D-BF98-671C69CBCC77",
"relative_start_ns": 2000000000,
"relative_end_ns": 3000000000,
"active_thread_id": 12345
"active_thread_id": 12345,
"segment_id": "bd2eb23da2beb459"
}
]
}
11 changes: 8 additions & 3 deletions relay-profiling/tests/fixtures/profiles/sample/roundtrip.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@
}
],
"stacks": [
[0],
[1]
[
0
],
[
1
]
],
"frames": [
{
Expand Down Expand Up @@ -89,7 +93,8 @@
"id": "30976f2ddbe04ac9b6bffe6e35d4710c",
"active_thread_id": "259",
"relative_start_ns": "500500",
"relative_end_ns": "50500500"
"relative_end_ns": "50500500",
"segment_id": "bd2eb23da2beb459"
}
]
}
1 change: 1 addition & 0 deletions tests/integration/test_dynamic_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,7 @@ def get_profile_payload(transaction):
"id": transaction["event_id"],
"name": "/api/0/organizations/{organization_slug}/broadcasts/",
"trace_id": transaction["contexts"]["trace"]["trace_id"],
"segment_id": "bd2eb23da2beb459",
},
"version": "1",
}
Expand Down
1 change: 1 addition & 0 deletions tests/integration/test_outcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ def _get_profile_payload(metadata_only=True):
"active_thread_id": "259",
"relative_start_ns": "500500",
"relative_end_ns": "50500500",
"segment_id": "bd2eb23da2beb459",
}
],
}
Expand Down
Loading