-
-
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
Conversation
|
#ifdef NATIVE_SDK | ||
internal_sdk = std::make_shared<NativeSDK>(); | ||
#else | ||
// Unsupported platform | ||
sentry::util::print_debug("This is an unsupported platform. Disabling Sentry SDK..."); | ||
enabled = false; | ||
#endif | ||
} | ||
|
||
if (!enabled) { | ||
sentry::util::print_debug("Sentry SDK is DISABLED! Operations with Sentry SDK will result in no-ops."); | ||
internal_sdk = std::make_shared<DisabledSDK>(); | ||
return; |
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.
FYI this code moved to _intialize()
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.
This is amazing stuff. The changelog reads as if the SDK initializes at different points depending on whether the configure callback has been implemented. I don't quite follow the chain of notifications to get from init
to configure
back to actual init
with the actual options. Would unifying the initialization to just the one right after the script server runs simplify this?
func _configure(options: SentryOptions) -> void: | ||
print("[example_configuration.gd] Configuring SDK options via GDScript") | ||
options.debug = true | ||
|
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.
|
||
## 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 comment
The 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. return null
for dropping events entirely. Based on the native implementation it looks like this should be supported. Can we update the sample with some filtering?
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 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the example with filtering in 9a49f11
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."); | ||
} |
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.
Where is this change coming from?
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 adjusted how ownership is handled in the NativeEvent
class, just so we don't have to preclude constructor call with incref every time.
} | ||
|
||
if (!enabled) { | ||
sentry::util::print_debug("Sentry SDK is DISABLED! Operations with Sentry SDK will result in no-ops."); |
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'm not quite following the whole initialization. Is logging set up prior to initialization? Does this show up 100% of the time with the SDK disabled? The way to get rid of this would be to increase the logging verbosity I guess?
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.
If you are commenting on this specific if-branch, then this message would appear in stdout if options.debug
is ON and SDK is disabled either manually via options or because it is unsupported platform.
I'm not sure what you mean by logging here. Godot doesn't employ the logger concept, with verbosity levels and such. There is print, push_error, and push_warning in GDScript. But we're not adding this message to such channels, and similar to sentry_native, it is simply printed to stdout (for consistency’s sake). Our error logger will eventually process errors and warnings, but will not deal with prints.
Thanks for reviewing @bitsandfoxes. It's a best-effort solution among very few options. Let me explain.
Correct, more on that below.
We don't have an initialization opportunity at that point. Here are our options:
These are the options I could find to tap into initialization, and I don't see any other way aside from introducing upstream changes.
UPDATE: |
9b8e805
to
8b41d9a
Compare
This PR introduces configuration via GDScript and adds the user-facing event hooks
before_send
andon_crash
, as outlined in https://develop.sentry.dev/sdk/expected-features/#before-send-hook and https://docs.sentry.io/platforms/native/configuration/filtering/.It introduces a new public API class called
SentryConfiguration
which users can extend in a script, and assign the script file in options to configure the SDK during initialization. However, due to the way scripting is initialized in the Godot Engine, this comes with a trade-off: a slightly later initialization. If a configuration script is assigned, initialization must be delayed untilScriptServer
is ready to load and run the user script.Resolves #47
Resolves #48