relay_profiling/sample/mod.rs
1use serde::{Deserialize, Serialize};
2
3use crate::debug_image::DebugImage;
4use relay_event_schema::protocol::Addr;
5
6pub mod v1;
7pub mod v2;
8
9/// Possible values for the version field of the Sample Format.
10#[derive(Debug, Serialize, Deserialize, Copy, Clone, Default, PartialEq, Eq)]
11pub enum Version {
12 #[default]
13 Unknown,
14 #[serde(rename = "1")]
15 V1,
16 #[serde(rename = "2")]
17 V2,
18}
19
20/// Holds information about a single stacktrace frame.
21///
22/// Each object should contain **at least** a `filename`, `function` or `instruction_addr`
23/// attribute. All values are optional, but recommended.
24#[derive(Clone, Debug, Default, Deserialize, Serialize)]
25pub struct Frame {
26 /// Absolute path to the source file.
27 #[serde(skip_serializing_if = "Option::is_none")]
28 pub abs_path: Option<String>,
29
30 /// Column number within the source file, starting at 1.
31 #[serde(alias = "column", skip_serializing_if = "Option::is_none")]
32 pub colno: Option<u32>,
33
34 /// The source file name (basename only).
35 #[serde(alias = "file", skip_serializing_if = "Option::is_none")]
36 pub filename: Option<String>,
37
38 /// Name of the frame's function. This might include the name of a class.
39 ///
40 /// This function name may be shortened or demangled. If not, Sentry will demangle and shorten
41 /// it for some platforms. The original function name will be stored in `raw_function`.
42 #[serde(alias = "name", skip_serializing_if = "Option::is_none")]
43 pub function: Option<String>,
44
45 /// Override whether this frame should be considered part of application code, or part of
46 /// libraries/frameworks/dependencies.
47 ///
48 /// Setting this attribute to `false` causes the frame to be hidden/collapsed by default and
49 /// mostly ignored during issue grouping.
50 #[serde(skip_serializing_if = "Option::is_none")]
51 pub in_app: Option<bool>,
52
53 /// (C/C++/Native) An optional instruction address for symbolication.
54 ///
55 /// This should be a string with a hexadecimal number that includes a 0x prefix.
56 /// If this is set and a known image is defined in the
57 /// [Debug Meta Interface]({%- link _documentation/development/sdk-dev/event-payloads/debugmeta.md -%}),
58 /// then symbolication can take place.
59 #[serde(skip_serializing_if = "Option::is_none")]
60 pub instruction_addr: Option<Addr>,
61
62 /// Line number within the source file, starting at 1.
63 #[serde(alias = "line", skip_serializing_if = "Option::is_none")]
64 pub lineno: Option<u32>,
65
66 /// Name of the module the frame is contained in.
67 ///
68 /// Note that this might also include a class name if that is something the
69 /// language natively considers to be part of the stack (for instance in Java).
70 #[serde(skip_serializing_if = "Option::is_none")]
71 pub module: Option<String>,
72
73 /// Which platform this frame is from.
74 ///
75 /// This can override the platform for a single frame. Otherwise, the platform of the event is
76 /// assumed. This can be used for multi-platform stack traces, such as in React Native.
77 #[serde(skip_serializing_if = "Option::is_none")]
78 pub platform: Option<String>,
79}
80
81impl Frame {
82 pub fn strip_pointer_authentication_code(&mut self, pac_code: u64) {
83 if let Some(address) = self.instruction_addr {
84 self.instruction_addr = Some(Addr(address.0 & pac_code));
85 }
86 }
87}
88
89#[derive(Default, Debug, Serialize, Deserialize, Clone)]
90pub struct DebugMeta {
91 /// A list of debug files needed to symbolicate/deobfuscate this profile.
92 /// Useful to pass source maps, ProGuard files or image libraries.
93 pub images: Vec<DebugImage>,
94}
95
96impl DebugMeta {
97 pub fn is_empty(&self) -> bool {
98 self.images.is_empty()
99 }
100}
101
102#[derive(Debug, Serialize, Deserialize, Clone)]
103pub struct ThreadMetadata {
104 /// This contains the name of the thread or queue.
105 #[serde(default, skip_serializing_if = "Option::is_none")]
106 pub name: Option<String>,
107 /// This contains the given priority of a thread if needed.
108 #[serde(default, skip_serializing_if = "Option::is_none")]
109 pub priority: Option<u32>,
110}