Filtering for Godot Engine
Learn more about how to configure your Sentry Godot SDK to filter events reported to Sentry.
When you add Sentry to your app, you get a lot of valuable information about errors and performance. And lots of information is good -- as long as it's the right information, at a reasonable volume.
The Sentry SDKs have several configuration options to help you filter out events.
We also offer Inbound Filters to filter events in sentry.io. We recommend filtering at the client level though, because it removes the overhead of sending events you don't actually want. Learn more about the fields available in an event.
Configure your SDK to filter error events by using the before_send callback method and configuring, enabling, or disabling integrations.
All Sentry SDKs support the before_send callback method. Because it's called immediately before the event is sent to the server, this is your last chance to decide not to send data or to edit it. before_send receives the event object as a parameter, which you can use to either modify the event’s data or drop it completely by returning null, based on custom logic and the data available on the event.
class_name ProjectMainLoop
extends SceneTree
## Tip: Set "ProjectMainLoop" as your main loop type in the project settings
## under `application/run/main_loop_type`.
func _initialize() -> void:
SentrySDK.init(func(options: SentryOptions) -> void:
options.before_send = _before_send
)
func _before_send(event: SentryEvent) -> SentryEvent:
if event.environment.contains("editor"):
# Discard event if running from the editor.
return null
var error_message: String = event.get_exception_value(0)
if error_message.contains("Bruno"):
# Remove sensitive information from the event.
var redacted_message := error_message.replace("Bruno", "REDACTED")
event.set_exception_value(0, redacted_message)
return event
class_name ProjectMainLoop
extends SceneTree
## Tip: Set "ProjectMainLoop" as your main loop type in the project settings
## under `application/run/main_loop_type`.
func _initialize() -> void:
SentrySDK.init(func(options: SentryOptions) -> void:
options.before_send = _before_send
)
func _before_send(event: SentryEvent) -> SentryEvent:
if event.environment.contains("editor"):
# Discard event if running from the editor.
return null
var error_message: String = event.get_exception_value(0)
if error_message.contains("Bruno"):
# Remove sensitive information from the event.
var redacted_message := error_message.replace("Bruno", "REDACTED")
event.set_exception_value(0, redacted_message)
return event
// The .NET before-send hook filters events captured from your C# code.
SentrySdk.Init(options =>
{
options.SetBeforeSend((sentryEvent, hint) =>
{
if (sentryEvent.Environment?.Contains("editor") == true)
{
// Discard the event if running from the editor.
return null;
}
foreach (var exception in sentryEvent.SentryExceptions ?? [])
{
if (exception.Value?.Contains("Bruno") == true)
{
// Remove sensitive information from the event.
exception.Value = exception.Value.Replace("Bruno", "REDACTED");
}
}
return sentryEvent;
});
});
In C#, options.SetBeforeSend filters managed events, such as exceptions from your game's C# code and third-party .NET libraries. Native events are captured in the native layer; to filter them from C#, set options.Native.SetBeforeSend inside your SentrySdk.Init. This is most useful for engine, GDScript, and GDExtension errors. The callback receives a SentryNativeEvent that you can inspect, modify, or drop by returning null. Native crash events aren't passed to this callback.
SentrySdk.Init(options =>
{
options.Native.SetBeforeSend(nativeEvent =>
{
// Drop a noisy error that you can't fix.
if (nativeEvent.GetExceptionValue(0)?.Contains("Noisy error") == true)
{
return null;
}
return nativeEvent;
});
});
SentrySdk.Init(options =>
{
options.Native.SetBeforeSend(nativeEvent =>
{
// Drop a noisy error that you can't fix.
if (nativeEvent.GetExceptionValue(0)?.Contains("Noisy error") == true)
{
return null;
}
return nativeEvent;
});
});
Note also that breadcrumbs can be filtered, as discussed in our Breadcrumbs documentation.
Use before_send_transaction to drop unwanted transactions or modify transaction metadata before sending them to Sentry. Transactions don't pass through before_send.
A transaction groups a root SentrySpan and its child spans into the performance event sent when the root span ends. Returning null from the callback drops the entire transaction, including its child spans.
Enable Tracing
These examples assume you've enabled tracing. Registering a callback doesn't enable it.
The callback receives a SentryEvent representing the transaction. Return the same object, with or without modifications, to send it, or return null to drop it. Modify the object in place and don't retain it after the callback returns.
You can modify tags, contexts, release, and environment, or inspect the complete payload with to_json(). Error-specific fields such as message, level, threads, and exceptions aren't available for transaction events.
Disable Auto Init and register the callback during programmatic initialization.
The following example drops transactions from editor runs and adds a tag to the remaining transactions. In C#, use options.Native.SetBeforeSendTransaction for transactions created by the native layer, including GDScript and GDExtension code:
func _initialize() -> void:
SentrySDK.init(func(options: SentryOptions) -> void:
options.before_send_transaction = _before_send_transaction
)
func _before_send_transaction(transaction: SentryEvent) -> SentryEvent:
if transaction.environment == "editor_dev_run":
return null
transaction.set_tag("map_name", "frozen_keep")
return transaction
func _initialize() -> void:
SentrySDK.init(func(options: SentryOptions) -> void:
options.before_send_transaction = _before_send_transaction
)
func _before_send_transaction(transaction: SentryEvent) -> SentryEvent:
if transaction.environment == "editor_dev_run":
return null
transaction.set_tag("map_name", "frozen_keep")
return transaction
Sentry.Godot.SentrySdk.Init(options =>
{
options.Native.SetBeforeSendTransaction(transaction =>
{
if (transaction.Environment == "editor_dev_run")
{
return null;
}
transaction.SetTag("map_name", "frozen_keep");
return transaction;
});
});
The C# native callback receives a SentryNativeEvent, which supports Release, Distribution, Environment, and tags. Error-specific fields such as Message, Level, Logger, and exceptions aren't available. Modify the object in place and don't retain it after the callback returns.
Thread Safety
The callback isn't guaranteed to run on the main thread. Avoid accessing the scene tree from it.
Web Exports
On Web, before_send_transaction only runs when trace_lifecycle is SentryOptions.TRACE_LIFECYCLE_STATIC (the default). It doesn't run for streamed spans.
To filter transactions originating in managed (.NET) code, register options.SetBeforeSendTransaction in your initialization callback. It receives a SentryTransaction:
options.SetBeforeSendTransaction((transaction, hint) =>
{
if (transaction.Environment == "editor_dev_run")
{
return null;
}
transaction.SetTag("map_name", "frozen_keep");
return transaction;
});
options.SetBeforeSendTransaction((transaction, hint) =>
{
if (transaction.Environment == "editor_dev_run")
{
return null;
}
transaction.SetTag("map_name", "frozen_keep");
return transaction;
});
This callback doesn't process transactions from the native layer. If your game creates both native and managed transactions, configure both C# callbacks.
Available since: v2.2.0
User feedback doesn't pass through before_send, so that callback can't filter or modify feedback submissions. Use before_send_feedback instead.
The before_send_feedback callback receives a prepared SentryEvent after scope data and event enrichment have been applied. Return the same event object, with or without modifications, to send the feedback, or return null to drop it.
You can only set this callback programmatically. Disable Auto Init, then assign the callback when initializing the SDK:
SentrySDK.init(func(options: SentryOptions) -> void:
options.before_send_feedback = _before_send_feedback
)
func _before_send_feedback(event: SentryEvent) -> SentryEvent:
if event.environment == "editor_dev_run":
return null
event.set_tag("feedback_source", "in_game_form")
return event
SentrySDK.init(func(options: SentryOptions) -> void:
options.before_send_feedback = _before_send_feedback
)
func _before_send_feedback(event: SentryEvent) -> SentryEvent:
if event.environment == "editor_dev_run":
return null
event.set_tag("feedback_source", "in_game_form")
return event
SentrySdk.Init(options =>
{
options.SetBeforeSendFeedback(feedbackEvent =>
{
if (feedbackEvent.Environment == "editor_dev_run")
{
return null;
}
feedbackEvent.SetTag("feedback_source", "in_game_form");
return feedbackEvent;
});
});
In C#, SetBeforeSendFeedback applies to feedback captured through the managed SentrySdk.CaptureFeedback API. Feedback captured through GDScript or the native Godot API uses before_send_feedback instead.
iOS and macOS
In GDScript, the before_send_feedback callback isn't supported on iOS or macOS yet. Feedback is still sent on these platforms, but the callback doesn't run. This limitation doesn't apply to the C# callback.
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").