Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add auto debug mode #73

Merged
merged 12 commits into from
Feb 5, 2025
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- Add auto debug mode ([#73](https://github.com/getsentry/sentry-godot/pull/73))

## 0.1.1

### Fixes
Expand Down
1 change: 0 additions & 1 deletion project/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,4 @@ ui/toolbar/run_overall=true
[sentry]

config/dsn="https://[email protected]/6680910"
config/debug=true
config/configuration_script="res://example_configuration.gd"
18 changes: 15 additions & 3 deletions src/sentry_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "sentry/environment.h"
#include "sentry/simple_bind.h"

#include <godot_cpp/classes/os.hpp>
#include <godot_cpp/classes/project_settings.hpp>

namespace {
Expand Down Expand Up @@ -54,7 +55,7 @@ void SentryOptions::_define_project_settings(const Ref<SentryOptions> &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);
Expand Down Expand Up @@ -90,7 +91,12 @@ void SentryOptions::_load_project_settings(const Ref<SentryOptions> &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);
Expand All @@ -110,6 +116,11 @@ void SentryOptions::_load_project_settings(const Ref<SentryOptions> &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));

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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() {
Expand Down
13 changes: 11 additions & 2 deletions src/sentry_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,20 @@ class SentryOptions : public RefCounted {
private:
static Ref<SentryOptions> 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;
Expand All @@ -65,6 +72,8 @@ class SentryOptions : public RefCounted {
static void _define_project_settings(const Ref<SentryOptions> &p_options);
static void _load_project_settings(const Ref<SentryOptions> &p_options);

void _init_debug_option(DebugMode p_debug_mode);

protected:
static void _bind_methods();

Expand Down Expand Up @@ -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; }
Expand Down