-
-
Notifications
You must be signed in to change notification settings - Fork 6
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: Event hooks & configuration via GDScript #60
Changes from all commits
549a602
af51cbc
61efe59
a6272a5
84d21bc
e9f6355
df663f0
9812184
a6e587d
3685467
54f6c44
2aaabd8
64637c2
f091945
ff81efb
287ff3b
d9ee288
50cca83
cef3266
a5267cc
46c122e
9a49f11
8b41d9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
extends SentryConfiguration | ||
## Example Sentry configuration script. | ||
## | ||
## Tip: You can assign configuration script in the project settings. | ||
|
||
|
||
## Configure Sentry SDK options | ||
func _configure(options: SentryOptions) -> void: | ||
print("[example_configuration.gd] Configuring SDK options via GDScript") | ||
|
||
options.debug = true | ||
options.release = "sentry-godot-demo@" + ProjectSettings.get_setting("application/config/version") | ||
|
||
# Set up event callbacks | ||
options.before_send = _before_send | ||
options.on_crash = _on_crash | ||
|
||
|
||
## before_send callback example | ||
func _before_send(ev: SentryEvent) -> SentryEvent: | ||
print("[example_configuration.gd] Processing event: ", ev.id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One of the more important uses of this callback is to allow users filtering of events. I.e. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can, although, this would apply to everything in the demo project, including our unit tests, so it should be something harmless. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated the example with filtering in 9a49f11 |
||
if ev.message == "junk": | ||
print("[example_configuration.gd] Discarding event with message 'junk'") | ||
return null | ||
return ev | ||
|
||
|
||
## on_crash callback example | ||
func _on_crash(ev: SentryEvent) -> SentryEvent: | ||
print("[example_configuration.gd] Crashing with event: ", ev.id) | ||
return ev |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,4 @@ ui/toolbar/run_overall=true | |
|
||
config/dsn="https://[email protected]/6680910" | ||
config/debug=true | ||
config/configuration_script="res://example_configuration.gd" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
class_name TestEventIntegrity | ||
extends GdUnitTestSuite | ||
|
||
signal callback_processed | ||
|
||
var created_id: String | ||
|
||
|
||
func before_test() -> void: | ||
SentrySDK._set_before_send(_before_send) | ||
|
||
|
||
func after_test() -> void: | ||
SentrySDK._unset_before_send() | ||
|
||
|
||
@warning_ignore("unused_parameter") | ||
func test_event_integrity(timeout := 10000) -> void: | ||
var event := SentrySDK.create_event() | ||
event.message = "integrity-check" | ||
event.level = SentrySDK.LEVEL_DEBUG | ||
event.logger = "custom-logger" | ||
event.release = "custom-release" | ||
event.dist = "custom-dist" | ||
event.environment = "custom-environment" | ||
created_id = event.id | ||
|
||
var captured_id := SentrySDK.capture_event(event) | ||
assert_signal(self).is_emitted("callback_processed") | ||
|
||
assert_str(captured_id).is_not_empty() | ||
assert_str(captured_id).is_not_equal(created_id) # event was discarded | ||
assert_str(SentrySDK.get_last_event_id()).is_not_empty() | ||
assert_str(captured_id).is_equal(SentrySDK.get_last_event_id()) | ||
assert_str(created_id).is_not_equal(SentrySDK.get_last_event_id()) | ||
|
||
|
||
func _before_send(event: SentryEvent) -> SentryEvent: | ||
assert_str(event.message).is_equal("integrity-check") | ||
assert_int(event.level).is_equal(SentrySDK.LEVEL_DEBUG) | ||
assert_str(event.logger).is_equal("custom-logger") | ||
assert_str(event.release).is_equal("custom-release") | ||
assert_str(event.dist).is_equal("custom-dist") | ||
assert_str(event.environment).is_equal("custom-environment") | ||
assert_str(event.id).is_equal(created_id) | ||
callback_processed.emit() | ||
return null # discard event |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,13 +111,20 @@ String NativeEvent::get_environment() const { | |
} | ||
|
||
NativeEvent::NativeEvent(sentry_value_t p_native_event) { | ||
native_event = p_native_event; | ||
if (sentry_value_refcount(p_native_event) > 0) { | ||
sentry_value_incref(p_native_event); // acquire ownership | ||
native_event = p_native_event; | ||
} else { | ||
// Shouldn't happen in healthy code. | ||
native_event = sentry_value_new_event(); | ||
ERR_PRINT("Sentry: Internal error: Event refcount is zero."); | ||
} | ||
Comment on lines
+114
to
+121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is this change coming from? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I adjusted how ownership is handled in the |
||
} | ||
|
||
NativeEvent::NativeEvent() : | ||
NativeEvent(sentry_value_new_event()) { | ||
NativeEvent::NativeEvent() { | ||
native_event = sentry_value_new_event(); | ||
} | ||
|
||
NativeEvent::~NativeEvent() { | ||
sentry_value_decref(native_event); | ||
sentry_value_decref(native_event); // release ownership | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include "sentry_configuration.h" | ||
|
||
#include "sentry_sdk.h" | ||
|
||
void SentryConfiguration::_call_configure(const Ref<SentryOptions> &p_options) { | ||
ERR_FAIL_COND(p_options.is_null()); | ||
GDVIRTUAL_CALL(_configure, p_options); | ||
ERR_FAIL_NULL(SentrySDK::get_singleton()); | ||
SentrySDK::get_singleton()->notify_options_configured(); | ||
} | ||
|
||
void SentryConfiguration::_notification(int p_what) { | ||
if (p_what == NOTIFICATION_READY) { | ||
_call_configure(SentryOptions::get_singleton()); | ||
} | ||
} | ||
|
||
void SentryConfiguration::_bind_methods() { | ||
GDVIRTUAL_BIND(_configure, "options"); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef SENTRY_CONFIGURATION_H | ||
#define SENTRY_CONFIGURATION_H | ||
|
||
#include "sentry_options.h" | ||
|
||
#include <godot_cpp/classes/node.hpp> | ||
#include <godot_cpp/core/gdvirtual.gen.inc> | ||
|
||
using namespace godot; | ||
|
||
class SentryConfiguration : public Node { | ||
GDCLASS(SentryConfiguration, Node); | ||
|
||
protected: | ||
static void _bind_methods(); | ||
void _notification(int p_what); | ||
|
||
GDVIRTUAL1(_configure, Ref<SentryOptions>); | ||
|
||
void _call_configure(const Ref<SentryOptions> &p_options); | ||
|
||
public: | ||
SentryConfiguration() {} | ||
}; | ||
|
||
#endif // SENTRY_CONFIGURATION_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could extend the sample here and provide some more options. I.e. setting the release and/or the environment. To give an idea what's there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea, although, we can't change environment until #66 is merged. Will keep it in mind.
I've updated the example configuration with setting release attribute in 46c122e