diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b797e5..e6a2bff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased + +- Add auto debug mode ([#73](https://github.com/getsentry/sentry-godot/pull/73)) + ## 0.1.1 ### Fixes diff --git a/project/project.godot b/project/project.godot index da1dc0d..c9e75d7 100644 --- a/project/project.godot +++ b/project/project.godot @@ -37,5 +37,4 @@ ui/toolbar/run_overall=true [sentry] config/dsn="https://3f1e095cf2e14598a0bd5b4ff324f712@o447951.ingest.us.sentry.io/6680910" -config/debug=true config/configuration_script="res://example_configuration.gd" diff --git a/src/sentry_options.cpp b/src/sentry_options.cpp index 9f19983..6c7f1b5 100644 --- a/src/sentry_options.cpp +++ b/src/sentry_options.cpp @@ -3,6 +3,7 @@ #include "sentry/environment.h" #include "sentry/simple_bind.h" +#include #include namespace { @@ -54,7 +55,7 @@ void SentryOptions::_define_project_settings(const Ref &p_options _define_setting("sentry/config/dsn", p_options->dsn); _define_setting("sentry/config/release", p_options->release); _define_setting("sentry/config/dist", p_options->dist); - _define_setting("sentry/config/debug", p_options->debug); + _define_setting(PropertyInfo(Variant::INT, "sentry/config/debug_printing", PROPERTY_HINT_ENUM, "Off,On,Auto"), (int)SentryOptions::DEBUG_DEFAULT); _define_setting(PropertyInfo(Variant::FLOAT, "sentry/config/sample_rate", PROPERTY_HINT_RANGE, "0.0,1.0"), p_options->sample_rate); _define_setting("sentry/config/attach_log", p_options->attach_log); _define_setting(PropertyInfo(Variant::INT, "sentry/config/max_breadcrumbs", PROPERTY_HINT_RANGE, "0, 500"), p_options->max_breadcrumbs); @@ -90,7 +91,12 @@ void SentryOptions::_load_project_settings(const Ref &p_options) p_options->disabled_in_editor = ProjectSettings::get_singleton()->get_setting("sentry/config/disabled_in_editor", p_options->disabled_in_editor); p_options->dsn = ProjectSettings::get_singleton()->get_setting("sentry/config/dsn", p_options->dsn); p_options->dist = ProjectSettings::get_singleton()->get_setting("sentry/config/dist", p_options->dist); - p_options->debug = ProjectSettings::get_singleton()->get_setting("sentry/config/debug", p_options->debug); + + // DebugMode is only used to represent the debug option in the project settings. + // The user may also set the `debug` option explicitly in a configuration script. + DebugMode mode = (DebugMode)(int)ProjectSettings::get_singleton()->get_setting("sentry/config/debug_printing", (int)SentryOptions::DEBUG_DEFAULT); + p_options->_init_debug_option(mode); + p_options->sample_rate = ProjectSettings::get_singleton()->get_setting("sentry/config/sample_rate", p_options->sample_rate); p_options->attach_log = ProjectSettings::get_singleton()->get_setting("sentry/config/attach_log", p_options->attach_log); p_options->max_breadcrumbs = ProjectSettings::get_singleton()->get_setting("sentry/config/max_breadcrumbs", p_options->max_breadcrumbs); @@ -110,6 +116,11 @@ void SentryOptions::_load_project_settings(const Ref &p_options) p_options->configuration_script = ProjectSettings::get_singleton()->get_setting("sentry/config/configuration_script", p_options->configuration_script); } +void SentryOptions::_init_debug_option(DebugMode p_mode) { + ERR_FAIL_NULL(OS::get_singleton()); + debug = (p_mode == DebugMode::DEBUG_ON) || (p_mode == DebugMode::DEBUG_AUTO && OS::get_singleton()->is_debug_build()); +} + void SentryOptions::create_singleton() { singleton = Ref(memnew(SentryOptions)); @@ -140,8 +151,8 @@ void SentryOptions::_bind_methods() { BIND_PROPERTY(SentryOptions, PropertyInfo(Variant::STRING, "dsn"), set_dsn, get_dsn); BIND_PROPERTY(SentryOptions, PropertyInfo(Variant::STRING, "release"), set_release, get_release); BIND_PROPERTY(SentryOptions, PropertyInfo(Variant::STRING, "dist"), set_dist, get_dist); - BIND_PROPERTY(SentryOptions, PropertyInfo(Variant::STRING, "environment"), set_environment, get_environment); BIND_PROPERTY(SentryOptions, PropertyInfo(Variant::BOOL, "debug"), set_debug_enabled, is_debug_enabled); + BIND_PROPERTY(SentryOptions, PropertyInfo(Variant::STRING, "environment"), set_environment, get_environment); BIND_PROPERTY(SentryOptions, PropertyInfo(Variant::FLOAT, "sample_rate"), set_sample_rate, get_sample_rate); BIND_PROPERTY(SentryOptions, PropertyInfo(Variant::BOOL, "attach_log"), set_attach_log, is_attach_log_enabled); BIND_PROPERTY(SentryOptions, PropertyInfo(Variant::INT, "max_breadcrumbs"), set_max_breadcrumbs, get_max_breadcrumbs); @@ -170,6 +181,7 @@ void SentryOptions::_bind_methods() { SentryOptions::SentryOptions() { error_logger_limits.instantiate(); // Ensure limits are initialized. environment = sentry::environment::detect_godot_environment(); + _init_debug_option(DEBUG_DEFAULT); } SentryOptions::~SentryOptions() { diff --git a/src/sentry_options.h b/src/sentry_options.h index d93c2ae..b5ba32e 100644 --- a/src/sentry_options.h +++ b/src/sentry_options.h @@ -40,13 +40,20 @@ class SentryOptions : public RefCounted { private: static Ref singleton; + enum class DebugMode { + DEBUG_OFF = 0, + DEBUG_ON = 1, + DEBUG_AUTO = 2, + }; + static constexpr DebugMode DEBUG_DEFAULT = DebugMode::DEBUG_AUTO; + bool enabled = true; bool disabled_in_editor = true; String dsn = ""; String release = "{app_name}@{app_version}"; String dist = ""; - String environment; bool debug = false; + String environment; double sample_rate = 1.0; bool attach_log = true; int max_breadcrumbs = 100; @@ -65,6 +72,8 @@ class SentryOptions : public RefCounted { static void _define_project_settings(const Ref &p_options); static void _load_project_settings(const Ref &p_options); + void _init_debug_option(DebugMode p_debug_mode); + protected: static void _bind_methods(); @@ -92,7 +101,7 @@ class SentryOptions : public RefCounted { _FORCE_INLINE_ void set_environment(const String &p_environment) { environment = p_environment; } _FORCE_INLINE_ bool is_debug_enabled() const { return debug; } - _FORCE_INLINE_ void set_debug_enabled(bool p_debug) { debug = p_debug; } + _FORCE_INLINE_ void set_debug_enabled(bool p_enabled) { debug = p_enabled; } _FORCE_INLINE_ double get_sample_rate() const { return sample_rate; } _FORCE_INLINE_ void set_sample_rate(double p_sample_rate) { sample_rate = p_sample_rate; }