Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixes

- Fixed SentryLog.set_attribute() not working on Android ([#438](https://github.com/getsentry/sentry-godot/pull/438))
- Fixed occasional crash on exit on Android ([#439](https://github.com/getsentry/sentry-godot/pull/439))

## 1.1.0

Expand Down
26 changes: 21 additions & 5 deletions src/sentry/android/android_sdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,31 @@ void SentryAndroidBeforeSendLogHandler::_bind_methods() {
// *** AndroidSDK

void AndroidSDK::set_context(const String &p_key, const Dictionary &p_value) {
Object *android_plugin = _get_android_plugin();
ERR_FAIL_NULL(android_plugin);
android_plugin->call(ANDROID_SN(setContext), p_key, sanitize_variant(p_value));
}

void AndroidSDK::remove_context(const String &p_key) {
Object *android_plugin = _get_android_plugin();
ERR_FAIL_NULL(android_plugin);
android_plugin->call(ANDROID_SN(removeContext), p_key);
}

void AndroidSDK::set_tag(const String &p_key, const String &p_value) {
Object *android_plugin = _get_android_plugin();
ERR_FAIL_NULL(android_plugin);
android_plugin->call(ANDROID_SN(setTag), p_key, p_value);
}

void AndroidSDK::remove_tag(const String &p_key) {
Object *android_plugin = _get_android_plugin();
ERR_FAIL_NULL(android_plugin);
android_plugin->call(ANDROID_SN(removeTag), p_key);
}

void AndroidSDK::set_user(const Ref<SentryUser> &p_user) {
Object *android_plugin = _get_android_plugin();
ERR_FAIL_NULL(android_plugin);

if (p_user.is_valid()) {
Expand All @@ -111,25 +116,29 @@ void AndroidSDK::set_user(const Ref<SentryUser> &p_user) {
}

void AndroidSDK::remove_user() {
Object *android_plugin = _get_android_plugin();
ERR_FAIL_NULL(android_plugin);
android_plugin->call(ANDROID_SN(removeUser));
}

Ref<SentryBreadcrumb> AndroidSDK::create_breadcrumb() {
Object *android_plugin = _get_android_plugin();
ERR_FAIL_NULL_V(android_plugin, nullptr);
int32_t handle = android_plugin->call(ANDROID_SN(createBreadcrumb));
Ref<AndroidBreadcrumb> crumb = memnew(AndroidBreadcrumb(android_plugin, handle));
return crumb;
}

void AndroidSDK::add_breadcrumb(const Ref<SentryBreadcrumb> &p_breadcrumb) {
Object *android_plugin = _get_android_plugin();
ERR_FAIL_NULL(android_plugin);
Ref<AndroidBreadcrumb> crumb = p_breadcrumb;
ERR_FAIL_COND(crumb.is_null());
android_plugin->call(ANDROID_SN(addBreadcrumb), crumb->get_handle());
}

void AndroidSDK::log(LogLevel p_level, const String &p_body, const Dictionary &p_attributes) {
Object *android_plugin = _get_android_plugin();
ERR_FAIL_NULL(android_plugin);

if (p_body.is_empty()) {
Expand All @@ -152,23 +161,27 @@ void AndroidSDK::log(LogLevel p_level, const String &p_body, const Dictionary &p
}

String AndroidSDK::capture_message(const String &p_message, Level p_level) {
Object *android_plugin = _get_android_plugin();
ERR_FAIL_NULL_V(android_plugin, String());
return android_plugin->call(ANDROID_SN(captureMessage), p_message, p_level);
}

String AndroidSDK::get_last_event_id() {
Object *android_plugin = _get_android_plugin();
ERR_FAIL_NULL_V(android_plugin, String());
return android_plugin->call(ANDROID_SN(getLastEventId));
}

Ref<SentryEvent> AndroidSDK::create_event() {
Object *android_plugin = _get_android_plugin();
ERR_FAIL_NULL_V(android_plugin, nullptr);
int32_t event_handle = android_plugin->call(ANDROID_SN(createEvent));
Ref<AndroidEvent> event = memnew(AndroidEvent(android_plugin, event_handle));
return event;
}

String AndroidSDK::capture_event(const Ref<SentryEvent> &p_event) {
Object *android_plugin = _get_android_plugin();
ERR_FAIL_NULL_V(android_plugin, String());
ERR_FAIL_COND_V(p_event.is_null(), String());
Ref<AndroidEvent> android_event = p_event;
Expand All @@ -179,6 +192,7 @@ String AndroidSDK::capture_event(const Ref<SentryEvent> &p_event) {
}

void AndroidSDK::capture_feedback(const Ref<SentryFeedback> &p_feedback) {
Object *android_plugin = _get_android_plugin();
ERR_FAIL_NULL(android_plugin);
ERR_FAIL_COND_MSG(p_feedback.is_null(), "Sentry: Can't capture feedback - feedback object is null.");
ERR_FAIL_COND_MSG(p_feedback->get_message().is_empty(), "Sentry: Can't capture feedback - feedback message is empty.");
Expand All @@ -190,6 +204,8 @@ void AndroidSDK::capture_feedback(const Ref<SentryFeedback> &p_feedback) {
}

void AndroidSDK::add_attachment(const Ref<SentryAttachment> &p_attachment) {
Object *android_plugin = _get_android_plugin();
ERR_FAIL_NULL(android_plugin);
ERR_FAIL_COND(p_attachment.is_null());

if (p_attachment->get_path().is_empty()) {
Expand All @@ -211,6 +227,7 @@ void AndroidSDK::add_attachment(const Ref<SentryAttachment> &p_attachment) {
}

void AndroidSDK::init(const PackedStringArray &p_global_attachments, const Callable &p_configuration_callback) {
Object *android_plugin = _get_android_plugin();
ERR_FAIL_NULL(android_plugin);

if (p_configuration_callback.is_valid()) {
Expand Down Expand Up @@ -251,20 +268,23 @@ void AndroidSDK::init(const PackedStringArray &p_global_attachments, const Calla
}

void AndroidSDK::close() {
Object *android_plugin = _get_android_plugin();
if (android_plugin != nullptr) {
android_plugin->call(ANDROID_SN(close));
}
}

bool AndroidSDK::is_enabled() const {
Object *android_plugin = _get_android_plugin();
return android_plugin && android_plugin->call(ANDROID_SN(isEnabled));
}

AndroidSDK::AndroidSDK() {
AndroidStringNames::create_singleton();

android_plugin = Engine::get_singleton()->get_singleton("SentryAndroidGodotPlugin");
Object *android_plugin = Engine::get_singleton()->get_singleton("SentryAndroidGodotPlugin");
ERR_FAIL_NULL_MSG(android_plugin, "Sentry: Unable to locate SentryAndroidGodotPlugin singleton.");
android_plugin_instance_id = android_plugin->get_instance_id();

before_send_handler = memnew(SentryAndroidBeforeSendHandler);
before_send_handler->_initialize(android_plugin);
Expand All @@ -274,10 +294,6 @@ AndroidSDK::AndroidSDK() {
}

AndroidSDK::~AndroidSDK() {
if (is_enabled()) {
close();
}

AndroidStringNames::destroy_singleton();
if (before_send_handler) {
memdelete(before_send_handler);
Expand Down
6 changes: 4 additions & 2 deletions src/sentry/android/android_sdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ class SentryAndroidBeforeSendLogHandler : public Object {
// Internal SDK utilizing Sentry Android (sentry-java repo).
class AndroidSDK : public InternalSDK {
private:
Object *android_plugin = nullptr;
uint64_t android_plugin_instance_id = 0;
SentryAndroidBeforeSendHandler *before_send_handler = nullptr;
SentryAndroidBeforeSendLogHandler *before_send_log_handler = nullptr;

_FORCE_INLINE_ Object *_get_android_plugin() const { return ObjectDB::get_instance(android_plugin_instance_id); }

public:
virtual void set_context(const String &p_key, const Dictionary &p_value) override;
virtual void remove_context(const String &p_key) override;
Expand Down Expand Up @@ -73,7 +75,7 @@ class AndroidSDK : public InternalSDK {
virtual void close() override;
virtual bool is_enabled() const override;

bool has_android_plugin() const { return android_plugin != nullptr; }
bool has_android_plugin() const { return _get_android_plugin() != nullptr; }

AndroidSDK();
virtual ~AndroidSDK() override;
Expand Down
8 changes: 8 additions & 0 deletions src/sentry/logging/sentry_godot_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ void SentryGodotLogger::_apply_normal_limits() {
void SentryGodotLogger::_log_error(const String &p_function, const String &p_file, int32_t p_line,
const String &p_code, const String &p_rationale, bool p_editor_notify, int32_t p_error_type,
const TypedArray<Ref<ScriptBacktrace>> &p_script_backtraces) {
if (!SentrySDK::get_singleton()) {
return;
}

static thread_local uint32_t num_entries = 0;
constexpr uint32_t MAX_ENTRIES = 5;
RecursionGuard feedback_loop_guard{ &num_entries, MAX_ENTRIES };
Expand Down Expand Up @@ -445,6 +449,10 @@ void SentryGodotLogger::_log_error(const String &p_function, const String &p_fil
void SentryGodotLogger::_log_message(const String &p_message, bool p_error) {
sentry::logging::MessageScope message_scope;

if (!SentrySDK::get_singleton()) {
return;
}

bool as_log = SentryOptions::get_singleton()->get_experimental()->get_enable_logs();
bool as_breadcrumb = SentryOptions::get_singleton()->is_logger_messages_as_breadcrumbs_enabled();

Expand Down
Loading