Set Up Logs

Structured logs allow you to send, view and query logs sent from your applications within Sentry.

With Sentry Structured Logs, you can send text-based log information from your Godot Engine applications to Sentry. Once in Sentry, these logs can be viewed alongside relevant errors, searched by text-string, or searched using their individual attributes.

Logs for Godot Engine are supported in Sentry Godot SDK version 1.1.0 and above.

To enable logging in your Godot project, you need to configure the Sentry SDK with Logs enabled.

  1. Open Project Settings in Godot, and navigate to Sentry > Experimental.
  2. Turn on the Enable Logs option.

Alternatively, you can enable logs programmatically when initializing the SDK:

Copied
SentrySDK.init(func(options: SentryOptions) -> void:
	options.experimental.enable_logs = true
)

Once the feature is enabled on the SDK and the SDK is initialized, you can send logs using the SentrySDK.logger APIs.

The SentrySDK.logger exposes six methods that you can use to log messages at different log levels: trace, debug, info, warn, error, and fatal.

Copied
SentrySDK.logger.trace("Initialized inventory database")
SentrySDK.logger.debug("Player inventory updated")
SentrySDK.logger.info("Level loaded successfully")
SentrySDK.logger.warn("Item configuration not found")
SentrySDK.logger.error("Failed to save game state")
SentrySDK.logger.fatal("Inventory data corrupted")

When the feature is enabled, the SDK automatically captures Godot messages, warnings, and errors as logs. You can use print(), push_warning(), and push_error() as usual. These show up as info, warning, and error logs. The SDK also turns runtime errors and warnings into events based on your configuration.

To filter logs, or update them before they are sent to Sentry, you can use the before_send_log option.

Copied
SentrySDK.init(func(options: SentryOptions) -> void:
	options.experimental.enable_logs = true
	options.experimental.before_send_log = _before_send_log
)

func _before_send_log(log_entry: SentryLog) -> SentryLog:
	# Filter junk.
	if log_entry.body == "Junk message":
		return null
	# Remove sensitive information from log messages.
	log_entry.body = log_entry.body.replace("Bruno", "REDACTED")
	# Add custom attributes.
	log_entry.set_attribute("current_scene", current_scene.name)
	return log_entry

The before_send_log function receives a SentryLog object, and should return either the same log object, with or without modifications, or null if you want to discard it.

The Godot SDK automatically sets several default attributes on all log entries to provide context and improve debugging:

  • environment: The environment set in the SDK if defined. This is sent from the SDK as sentry.environment.
  • release: The release set in the SDK if defined. This is sent from the SDK as sentry.release.
  • sdk.name: The name of the SDK that sent the log. This is sent from the SDK as sentry.sdk.name.
  • sdk.version: The version of the SDK that sent the log. This is sent from the SDK as sentry.sdk.version.

  • user.id: The user ID. Maps to id in the User payload, which is set by default by the SDKs.

If user information is available in the current scope, the following attributes are added to the log:

  • user.name: The username. Maps to username in the User payload.
  • user.email: The email address. Maps to email in the User payload.

If a log is generated by an SDK integration, the SDK will set additional attributes to help you identify the source of the log.

  • origin: The origin of the log. This is sent from the SDK as sentry.origin.

  • Logs are sent asynchronously to avoid impacting game performance.
  • Consider disabling debug level logs in production to avoid excessive log volume.
  • before_send_log callback is executed synchronously, so keep processing lightweight.
Was this helpful?
Help improve this content
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").