Skip to main content

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