diff --git a/sentry-core/src/performance.rs b/sentry-core/src/performance.rs index 14f820c1e..bcfb235da 100644 --- a/sentry-core/src/performance.rs +++ b/sentry-core/src/performance.rs @@ -3,6 +3,7 @@ use std::sync::Mutex; #[cfg(all(feature = "profiling", target_family = "unix"))] use crate::profiling; + use crate::{protocol, Hub}; #[cfg(feature = "client")] @@ -552,7 +553,7 @@ impl Transaction { // then call finish_profiling to return the profile #[cfg(all(feature = "profiling", target_family = "unix"))] let sample_profile = inner.profiler_guard.take().and_then(|profiler_guard| { - profiling::finish_profiling(&transaction, profiler_guard, inner.context.trace_id) + profiling::finish_profiling(&mut transaction, profiler_guard, inner.context.trace_id) }); drop(inner); diff --git a/sentry-core/src/profiling.rs b/sentry-core/src/profiling.rs index 5d421bee2..27dda5dfa 100644 --- a/sentry-core/src/profiling.rs +++ b/sentry-core/src/profiling.rs @@ -5,6 +5,8 @@ use std::sync::atomic::{AtomicBool, Ordering}; use findshlibs::{SharedLibrary, SharedLibraryId, TargetSharedLibrary, TARGET_SUPPORTED}; +use sentry_types::protocol::latest::Context; +use sentry_types::protocol::latest::ProfileContext; use sentry_types::protocol::v7::Profile; use sentry_types::protocol::v7::{ DebugImage, DebugMeta, DeviceMetadata, OSMetadata, RuntimeMetadata, RustFrame, Sample, @@ -60,12 +62,21 @@ pub(crate) fn start_profiling(client: &Client) -> Option { } pub(crate) fn finish_profiling( - transaction: &Transaction, + transaction: &mut Transaction, profiler_guard: ProfilerGuard, trace_id: TraceId, ) -> Option { let sample_profile = match profiler_guard.0.report().build_unresolved() { - Ok(report) => Some(get_profile_from_report(&report, trace_id, transaction)), + Ok(report) => { + let prof = get_profile_from_report(&report, trace_id, transaction); + transaction.contexts.insert( + "profile".to_string(), + Context::Profile(Box::new(ProfileContext { + profile_id: prof.event_id, + })), + ); + Some(prof) + } Err(err) => { sentry_debug!( "could not build the profile result due to the error: {}", diff --git a/sentry-types/src/protocol/v7.rs b/sentry-types/src/protocol/v7.rs index dcf083884..cdf1f9830 100644 --- a/sentry-types/src/protocol/v7.rs +++ b/sentry-types/src/protocol/v7.rs @@ -1108,6 +1108,8 @@ pub enum Context { Trace(Box), /// GPU data Gpu(Box), + /// Profiling data + Profile(Box), /// Generic other context data. #[serde(rename = "unknown")] Other(Map), @@ -1124,6 +1126,7 @@ impl Context { Context::Browser(..) => "browser", Context::Trace(..) => "trace", Context::Gpu(..) => "gpu", + Context::Profile(..) => "profile", Context::Other(..) => "unknown", } } @@ -1342,6 +1345,13 @@ pub struct GpuContext { pub other: Map, } +/// Profile context. +#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq)] +pub struct ProfileContext { + /// The profile ID. + pub profile_id: Uuid, +} + /// Holds the identifier for a Span #[derive(Serialize, Deserialize, Debug, Copy, Clone, Eq, PartialEq, Hash)] #[serde(try_from = "String", into = "String")] @@ -1474,6 +1484,7 @@ into_context!(Runtime, RuntimeContext); into_context!(Browser, BrowserContext); into_context!(Trace, TraceContext); into_context!(Gpu, GpuContext); +into_context!(Profile, ProfileContext); mod event { use super::*;