Skip to content

Commit 2001144

Browse files
authored
feat(profiling): Add profile context to transaction. (#538)
* Add profile context to transaction. As per RFC 0047
1 parent 2d2f934 commit 2001144

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

sentry-core/src/performance.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::sync::Mutex;
33

44
#[cfg(all(feature = "profiling", target_family = "unix"))]
55
use crate::profiling;
6+
67
use crate::{protocol, Hub};
78

89
#[cfg(feature = "client")]
@@ -552,7 +553,7 @@ impl Transaction {
552553
// then call finish_profiling to return the profile
553554
#[cfg(all(feature = "profiling", target_family = "unix"))]
554555
let sample_profile = inner.profiler_guard.take().and_then(|profiler_guard| {
555-
profiling::finish_profiling(&transaction, profiler_guard, inner.context.trace_id)
556+
profiling::finish_profiling(&mut transaction, profiler_guard, inner.context.trace_id)
556557
});
557558
drop(inner);
558559

sentry-core/src/profiling.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use std::sync::atomic::{AtomicBool, Ordering};
55

66
use findshlibs::{SharedLibrary, SharedLibraryId, TargetSharedLibrary, TARGET_SUPPORTED};
77

8+
use sentry_types::protocol::latest::Context;
9+
use sentry_types::protocol::latest::ProfileContext;
810
use sentry_types::protocol::v7::Profile;
911
use sentry_types::protocol::v7::{
1012
DebugImage, DebugMeta, DeviceMetadata, OSMetadata, RuntimeMetadata, RustFrame, Sample,
@@ -60,12 +62,21 @@ pub(crate) fn start_profiling(client: &Client) -> Option<ProfilerGuard> {
6062
}
6163

6264
pub(crate) fn finish_profiling(
63-
transaction: &Transaction,
65+
transaction: &mut Transaction,
6466
profiler_guard: ProfilerGuard,
6567
trace_id: TraceId,
6668
) -> Option<SampleProfile> {
6769
let sample_profile = match profiler_guard.0.report().build_unresolved() {
68-
Ok(report) => Some(get_profile_from_report(&report, trace_id, transaction)),
70+
Ok(report) => {
71+
let prof = get_profile_from_report(&report, trace_id, transaction);
72+
transaction.contexts.insert(
73+
"profile".to_string(),
74+
Context::Profile(Box::new(ProfileContext {
75+
profile_id: prof.event_id,
76+
})),
77+
);
78+
Some(prof)
79+
}
6980
Err(err) => {
7081
sentry_debug!(
7182
"could not build the profile result due to the error: {}",

sentry-types/src/protocol/v7.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,8 @@ pub enum Context {
11081108
Trace(Box<TraceContext>),
11091109
/// GPU data
11101110
Gpu(Box<GpuContext>),
1111+
/// Profiling data
1112+
Profile(Box<ProfileContext>),
11111113
/// Generic other context data.
11121114
#[serde(rename = "unknown")]
11131115
Other(Map<String, Value>),
@@ -1124,6 +1126,7 @@ impl Context {
11241126
Context::Browser(..) => "browser",
11251127
Context::Trace(..) => "trace",
11261128
Context::Gpu(..) => "gpu",
1129+
Context::Profile(..) => "profile",
11271130
Context::Other(..) => "unknown",
11281131
}
11291132
}
@@ -1342,6 +1345,13 @@ pub struct GpuContext {
13421345
pub other: Map<String, Value>,
13431346
}
13441347

1348+
/// Profile context.
1349+
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
1350+
pub struct ProfileContext {
1351+
/// The profile ID.
1352+
pub profile_id: Uuid,
1353+
}
1354+
13451355
/// Holds the identifier for a Span
13461356
#[derive(Serialize, Deserialize, Debug, Copy, Clone, Eq, PartialEq, Hash)]
13471357
#[serde(try_from = "String", into = "String")]
@@ -1474,6 +1484,7 @@ into_context!(Runtime, RuntimeContext);
14741484
into_context!(Browser, BrowserContext);
14751485
into_context!(Trace, TraceContext);
14761486
into_context!(Gpu, GpuContext);
1487+
into_context!(Profile, ProfileContext);
14771488

14781489
mod event {
14791490
use super::*;

0 commit comments

Comments
 (0)