Skip to content

Conversation

@limbonaut
Copy link
Collaborator

@limbonaut limbonaut commented Aug 20, 2025

This PR adds new lifecycle methods to the SentrySDK class: init(), close(), and is_enabled(). These methods are similar to what you’ll find in other SDKs. By default, the SDK tries to initialize itself automatically if "Auto Init" is enabled in the project settings. If disabled, devs can still manually initialize the SDK by calling init(). close() allows shutting down the previously initialized SDK.

This makes configuration script approach obsolete, giving us two clear options:

  1. Auto-initialization (performed early).
  2. Manual initialization with an optional configuration callback (like the lambda in the example below).

Additionally, options.enabled is renamed to auto_init for better clarity, as suggested by @bruno-garcia here.

Check #257 (comment) for more details.

Breaking changes

  • Configuration script option and class are removed and no longer supported. Instead, please use manual initialization with configuration callback (see below).
  • enabled option is renamed to auto_init for clarity, and removed from SentryOptions properties (setting it from code has no sense - we auto-initialize very early).
  • disabled_in_editor_play option is renamed to skip_auto_init_on_editor_play for clarity, and removed from SentryOptions properties.

How to initialize and configure the SDK from code

The earliest you can initialize the SDK is in the MainLoop._initialize(). Here's how you can do it:

  1. Disable "Auto Init" in the project settings under Sentry category.
  2. Create a main loop script with a class_name attribute, and init Sentry inside _initialize() method.
class_name MyMainLoop
extends SceneTree

func _initialize() -> void:
	# Sentry initialization
	SentrySDK.init(func(options: SentryOptions) -> void:
		options.release = "[email protected]"
	)
	
	# Post-init configuration
	SentrySDK.add_attachment(...)
	# ...
  1. Assign your main loop type in the project settings under application/run/main_loop_type ("MyMainLoop" in the example code).

@github-actions
Copy link
Contributor

github-actions bot commented Aug 20, 2025

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 7c34f6e

@limbonaut limbonaut force-pushed the ref/improve-initialization branch from 5b03693 to 0b5f933 Compare August 20, 2025 15:20
@limbonaut limbonaut marked this pull request as ready for review September 10, 2025 14:53
cursor[bot]

This comment was marked as outdated.

@limbonaut
Copy link
Collaborator Author

@sentry review

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

Copy link
Collaborator

@jpnurmi jpnurmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like how the tests are somehow easier to understand at a glance because the SentrySDK.init() call is visible. LGTM 👍

@limbonaut limbonaut merged commit cca682c into main Sep 12, 2025
46 checks passed
@limbonaut limbonaut deleted the ref/improve-initialization branch September 12, 2025 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add manual initialization and shutdown

4 participants