Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion sentry-core/src/performance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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);

Expand Down
15 changes: 13 additions & 2 deletions sentry-core/src/profiling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -60,12 +62,21 @@ pub(crate) fn start_profiling(client: &Client) -> Option<ProfilerGuard> {
}

pub(crate) fn finish_profiling(
transaction: &Transaction,
transaction: &mut Transaction,
profiler_guard: ProfilerGuard,
trace_id: TraceId,
) -> Option<SampleProfile> {
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: {}",
Expand Down
11 changes: 11 additions & 0 deletions sentry-types/src/protocol/v7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,8 @@ pub enum Context {
Trace(Box<TraceContext>),
/// GPU data
Gpu(Box<GpuContext>),
/// Profiling data
Profile(Box<ProfileContext>),
/// Generic other context data.
#[serde(rename = "unknown")]
Other(Map<String, Value>),
Expand All @@ -1124,6 +1126,7 @@ impl Context {
Context::Browser(..) => "browser",
Context::Trace(..) => "trace",
Context::Gpu(..) => "gpu",
Context::Profile(..) => "profile",
Context::Other(..) => "unknown",
}
}
Expand Down Expand Up @@ -1342,6 +1345,13 @@ pub struct GpuContext {
pub other: Map<String, Value>,
}

/// 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")]
Expand Down Expand Up @@ -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::*;
Expand Down