Skip to content

Commit

Permalink
High-level API: Improve Sentry support
Browse files Browse the repository at this point in the history
  • Loading branch information
helgoboss committed Dec 20, 2024
1 parent 6169b1e commit c474919
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 24 deletions.
16 changes: 11 additions & 5 deletions main/high/src/crash_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ pub struct CrashHandlerConfig {
}

/// Information about the plug-in, to be shown in crash logs.
#[derive(Clone, Debug)]
pub struct PluginInfo {
/// Name of the plug-in.
pub plugin_name: String,
/// Just the version number, for example, "2.15.0".
pub plugin_version: String,
/// Longer version info, maybe including the commit hash.
pub plugin_version_long: String,
/// Email address to which the user should send crash-related info.
pub support_email_address: String,
/// URL which is presented to the user with the request to try with the latest version before reporting the error.
pub update_url: String,
}

Expand Down Expand Up @@ -144,7 +150,7 @@ impl CrashFormatter for DefaultConsoleMessageFormatter {
let reaper_version = Reaper::get().version();
let update_url = &crash_info.plugin_info.update_url;
let plugin_name = &crash_info.plugin_info.plugin_name;
let plugin_version = &crash_info.plugin_info.plugin_version;
let plugin_version_long = &crash_info.plugin_info.plugin_version_long;
let email_address = &crash_info.plugin_info.support_email_address;
let panic_message = extract_panic_message(crash_info.panic_info);
let intro = format!("
Expand Down Expand Up @@ -176,7 +182,7 @@ Message: {panic_message}
REAPER version: {reaper_version}
Module name: {plugin_name}
Module version: {plugin_version}
Module version: {plugin_version_long}
Module path: {module_path}
Module base address: {module_base_address_label}
Module size: {module_size_label}
Expand Down Expand Up @@ -345,9 +351,9 @@ fn hyphen() -> String {
mod sentry_impl {
use super::*;
use sentry::integrations::backtrace::backtrace_to_stacktrace;
use sentry::integrations::panic::{message_from_panic_info, PanicIntegration};
use sentry::protocol::{Event, Exception, Mechanism, Uuid};
use sentry::{Hub, Level, User};
use sentry::integrations::panic::message_from_panic_info;
use sentry::protocol::{Event, Exception, Mechanism};
use sentry::{Hub, Level};

impl CrashHandler {
/// Returns the error ID.
Expand Down
18 changes: 16 additions & 2 deletions main/high/src/reaper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,12 @@ impl Reaper {
}

pub(crate) fn show_console_msg_thread_safe<'a>(&self, msg: impl Into<ReaperStringArg<'a>>) {
// TODO-high CONTINUE Check if REAPER version already supports thread-safe console messaging!
if self.is_in_main_thread() {
if self
.medium_reaper
.features()
.show_console_msg_from_any_thread
|| self.is_in_main_thread()
{
self.show_console_msg(msg);
} else {
let _ = self.helper_task_sender.try_send(HelperTask::ShowConsoleMsg(
Expand Down Expand Up @@ -744,6 +748,16 @@ mod sentry_impl {
)
.into(),
),
// We don't want default integrations because we have our own panic handler that uses the
// Sentry panic handler.
default_integrations: false,
integrations: vec![
Arc::new(sentry::integrations::backtrace::AttachStacktraceIntegration),
Arc::new(sentry::integrations::debug_images::DebugImagesIntegration::default()),
Arc::new(sentry::integrations::contexts::ContextIntegration::default()),
// Skip the panic integration
Arc::new(sentry::integrations::backtrace::ProcessStacktraceIntegration),
],
attach_stacktrace: false,
send_default_pii: false,
in_app_include: config.in_app_include,
Expand Down
1 change: 1 addition & 0 deletions main/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ fn generate_high_level_plugin_code(
let plugin_info = ::reaper_high::PluginInfo {
plugin_name: #plugin_name.to_string(),
plugin_version: #plugin_version.to_string(),
plugin_version_long: #plugin_version.to_string(),
support_email_address: #support_email_address.to_string(),
update_url: #update_url.to_string(),
};
Expand Down
62 changes: 46 additions & 16 deletions main/medium/src/reaper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,13 @@ impl AnyThread for RealTimeAudioThreadScope {}
/// [`MainThreadOnly`]: trait.MainThreadOnly.html
/// [`RealTimeAudioThreadOnly`]: trait.RealTimeAudioThreadOnly.html
/// [`Reaper`]: struct.Reaper.html
#[derive(Debug, Default)]
#[derive(Clone, Debug, Default)]
pub struct Reaper<UsageScope = MainThreadScope> {
low: reaper_low::Reaper,
features: ReaperFeatures,
p: PhantomData<UsageScope>,
}

impl<UsageScope> Clone for Reaper<UsageScope> {
fn clone(&self) -> Self {
Self {
low: self.low,
p: Default::default(),
}
}
}

// This is safe (see https://doc.rust-lang.org/std/sync/struct.Once.html#examples-1).
static mut INSTANCE: Option<Reaper<MainThreadScope>> = None;

Expand Down Expand Up @@ -212,12 +204,34 @@ impl Reaper<MainThreadScope> {
}
}

impl<UsageScope> Reaper<UsageScope> {
/// Features of a particular REAPER version.
#[derive(Clone, Eq, PartialEq, Debug, Default)]
pub struct ReaperFeatures {
/// Whether it is safe to call [`Reaper::show_console_msg`] from any thread (vs. just the main thread).
pub show_console_msg_from_any_thread: bool,
}

impl ReaperFeatures {
fn from_reaper_version(version: &ReaperVersion) -> Self {
Self {
show_console_msg_from_any_thread: version.revision() >= "7",
}
}
}

impl<UsageScope> Reaper<UsageScope>
where
UsageScope: AnyThread,
{
pub(crate) fn new(low: reaper_low::Reaper) -> Reaper<UsageScope> {
Reaper {
let mut reaper = Reaper {
low,
p: PhantomData,
}
features: Default::default(),
};
let version = reaper.get_app_version();
reaper.features = ReaperFeatures::from_reaper_version(&version);
reaper
}

/// Gives access to the low-level Reaper instance.
Expand All @@ -230,6 +244,11 @@ impl<UsageScope> Reaper<UsageScope> {
PluginContext::new(self.low.plugin_context())
}

/// Returns the features supported by this REAPER version.
pub fn features(&self) -> &ReaperFeatures {
&self.features
}

/// Returns the requested project and optionally its file name.
///
/// With `buffer_size` you can tell REAPER how many bytes of the file name you want. If you
Expand Down Expand Up @@ -502,11 +521,22 @@ impl<UsageScope> Reaper<UsageScope> {
/// Shows a message to the user in the ReaScript console.
///
/// This is also useful for debugging. Send "\n" for newline and "" to clear the console.
///
/// The message supports the following prefixes:
///
/// - `!SHOW:`: Text will be added to console without opening the window
/// - `!SHOWERR:` Displays error indicator in main menu bar if ReaScript Console not already visible
///
/// # Panics
///
/// In REAPER versions < 7, this panics when not called from the main thread.
pub fn show_console_msg<'a>(&self, message: impl Into<ReaperStringArg<'a>>)
where
UsageScope: MainThreadOnly,
UsageScope: AnyThread,
{
self.require_main_thread();
if !self.features.show_console_msg_from_any_thread {
self.require_main_thread();
}
unsafe { self.low.ShowConsoleMsg(message.into().as_ptr()) }
}

Expand Down Expand Up @@ -8846,7 +8876,7 @@ impl<UsageScope> Reaper<UsageScope> {

fn require_main_thread(&self)
where
UsageScope: MainThreadOnly,
UsageScope: AnyThread,
{
assert!(
self.low.plugin_context().is_in_main_thread(),
Expand Down
4 changes: 3 additions & 1 deletion test/test-vst-plugin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,13 @@ impl TestVstPlugin {
|| {
let context =
PluginContext::from_vst_plugin(&self.host, static_plugin_context()).unwrap();
let version = env!("CARGO_PKG_VERSION").to_string();
Reaper::setup_with_defaults(
context,
PluginInfo {
plugin_name: "reaper-rs test VST plug-in".to_string(),
plugin_version: env!("CARGO_PKG_VERSION").to_string(),
plugin_version: version.clone(),
plugin_version_long: version,
support_email_address: "[email protected]".to_string(),
update_url: "https://www.helgoboss.org/projects/helgobox".to_string(),
},
Expand Down

0 comments on commit c474919

Please sign in to comment.