Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Add opt-in automatic network metrics for peer counts, ping, packet loss, and traffic rates, configurable through `SentryOptions.auto_metrics` and Project Settings ([#1033](https://github.com/getsentry/sentry-godot/pull/1033))
- Web: Add tunneling through your own server to help avoid ad blockers ([#1057](https://github.com/getsentry/sentry-godot/pull/1057))
- Add `auto_session_tracking` to control automatic session tracking and `session_tracking_interval_ms` to configure its background timeout ([#1069](https://github.com/getsentry/sentry-godot/pull/1069))
- Add `SentrySDK.start_session()` and `SentrySDK.end_session()` to control session boundaries manually ([#1070](https://github.com/getsentry/sentry-godot/pull/1070))

### Fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,16 @@ class SentryAndroidGodotPlugin(godot: Godot) : GodotPlugin(godot) {
}
}

@UsedByGodot
fun startSession() {
Sentry.startSession()
}

@UsedByGodot
fun endSession() {
Sentry.endSession()
}

@UsedByGodot
fun close() {
Sentry.close()
Expand Down
22 changes: 22 additions & 0 deletions doc_classes/SentrySDK.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@
Creates a new [SentryEvent] object. You can capture the event with [method SentrySDK.capture_event].
</description>
</method>
<method name="end_session">
<return type="void" />
<description>
Ends the current session for Release Health. Does nothing if there is no active session. See [method start_session].
</description>
</method>
<method name="get_active_span" qualifiers="const">
<return type="SentrySpan" />
<description>
Expand Down Expand Up @@ -217,6 +223,22 @@
To learn more, visit [url=https://docs.sentry.io/concepts/key-terms/tracing/]Tracing documentation[/url].
</description>
</method>
<method name="start_session">
<return type="void" />
<description>
Starts a session for Release Health, ending any existing session first.
Disable [member SentryOptions.auto_session_tracking] when your application controls session boundaries:
[codeblock]
SentrySDK.init(func(options: SentryOptions) -&gt; void:
options.auto_session_tracking = false
)
SentrySDK.start_session()
# End the session when the play session finishes.
SentrySDK.end_session()
[/codeblock]
To learn more, visit [url=https://docs.sentry.io/product/releases/health/]Release Health documentation[/url].
</description>
</method>
<method name="start_span">
<return type="SentrySpan" />
<param index="0" name="name" type="String" />
Expand Down
10 changes: 10 additions & 0 deletions src/sentry/android/android_sdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,16 @@ void AndroidSDK::init() {
}
}

void AndroidSDK::start_session() {
ENSURE_ANDROID_PLUGIN(plugin, _android_plugin);
plugin->call("startSession");
}

void AndroidSDK::end_session() {
ENSURE_ANDROID_PLUGIN(plugin, _android_plugin);
plugin->call("endSession");
}

void AndroidSDK::close() {
Object *plugin = _android_plugin.get();
if (plugin != nullptr) {
Expand Down
3 changes: 3 additions & 0 deletions src/sentry/android/android_sdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ class AndroidSDK : public InternalSDK {

virtual void set_trace(const String &p_trace_id, const String &p_parent_span_id) override;

virtual void start_session() override;
virtual void end_session() override;

virtual void init() override;
virtual void close() override;
virtual bool is_enabled() const override;
Expand Down
3 changes: 3 additions & 0 deletions src/sentry/cocoa/cocoa_sdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class CocoaSDK : public InternalSDK {

virtual void set_trace(const String &p_trace_id, const String &p_parent_span_id) override;

virtual void start_session() override;
virtual void end_session() override;

virtual void init() override;
virtual void close() override;
virtual bool is_enabled() const override;
Expand Down
8 changes: 8 additions & 0 deletions src/sentry/cocoa/cocoa_sdk.mm
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,14 @@ void _add_default_attachments(SentryObjCScope *p_scope) {
}
}

void CocoaSDK::start_session() {
[SentryObjCSDK startSession];
}

void CocoaSDK::end_session() {
[SentryObjCSDK endSession];
}

void CocoaSDK::close() {
[SentryObjCSDK close];
}
Expand Down
3 changes: 3 additions & 0 deletions src/sentry/disabled/disabled_sdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class DisabledSDK : public InternalSDK {

virtual void set_trace(const String &p_trace_id, const String &p_parent_span_id) override {}

virtual void start_session() override {}
virtual void end_session() override {}

virtual void init() override {}
virtual void close() override {}
virtual bool is_enabled() const override { return false; }
Expand Down
3 changes: 3 additions & 0 deletions src/sentry/internal_sdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ class InternalSDK {

virtual void set_trace(const String &p_trace_id, const String &p_parent_span_id) = 0;

virtual void start_session() = 0;
virtual void end_session() = 0;

virtual void init() = 0;
virtual void close() = 0;
virtual bool is_enabled() const = 0;
Expand Down
11 changes: 11 additions & 0 deletions src/sentry/javascript/bridge/src/sentry-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,17 @@ class SentryBridge {
}
}

public startSession(): void {
Sentry.startSession();
// Unlike the other SDKs, JS does not send the initial update when starting a session,
// so we do it manually here.
Sentry.captureSession();
}

public endSession(): void {
Sentry.endSession();
}

public close(timeout: number): void {
Sentry.close(timeout);
}
Expand Down
2 changes: 2 additions & 0 deletions src/sentry/javascript/bridge/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ try {
const expectedMethods = [
"init",
"close",
"startSession",
"endSession",
"isEnabled",
"setContext",
"removeContext",
Expand Down
10 changes: 10 additions & 0 deletions src/sentry/javascript/javascript_sdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,16 @@ void JavaScriptSDK::init() {
}
}

void JavaScriptSDK::start_session() {
ERR_FAIL_COND(!js_bridge());
js_bridge()->call("startSession");
}

void JavaScriptSDK::end_session() {
ERR_FAIL_COND(!js_bridge());
js_bridge()->call("endSession");
}

void JavaScriptSDK::close() {
ERR_FAIL_COND(!js_bridge());

Expand Down
3 changes: 3 additions & 0 deletions src/sentry/javascript/javascript_sdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class JavaScriptSDK : public InternalSDK {

virtual void set_trace(const String &p_trace_id, const String &p_parent_span_id) override;

virtual void start_session() override;
virtual void end_session() override;

virtual void init() override;
virtual void close() override;
virtual bool is_enabled() const override;
Expand Down
8 changes: 8 additions & 0 deletions src/sentry/native/native_sdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,14 @@ void NativeSDK::init() {
}
}

void NativeSDK::start_session() {
sentry_start_session();
}

void NativeSDK::end_session() {
sentry_end_session();
}

void NativeSDK::close() {
int err = sentry_close();
user_attachments.clear();
Expand Down
3 changes: 3 additions & 0 deletions src/sentry/native/native_sdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class NativeSDK : public InternalSDK {

virtual void set_trace(const String &p_trace_id, const String &p_parent_span_id) override;

virtual void start_session() override;
virtual void end_session() override;

virtual void init() override;
virtual void close() override;
virtual bool is_enabled() const override;
Expand Down
13 changes: 13 additions & 0 deletions src/sentry/sentry_sdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,16 @@ void SentrySDK::remove_user() {
}
}

void SentrySDK::start_session() {
ERR_FAIL_COND_MSG(!is_enabled(), "Sentry: Can't start a session - SDK is not initialized.");
internal_sdk->start_session();
}

void SentrySDK::end_session() {
ERR_FAIL_COND_MSG(!is_enabled(), "Sentry: Can't end a session - SDK is not initialized.");
internal_sdk->end_session();
}

void SentrySDK::start_new_trace() {
set_trace(sentry::uuid::make_uuid_no_dashes(), String());
}
Expand Down Expand Up @@ -712,6 +722,9 @@ void SentrySDK::_bind_methods() {
ClassDB::bind_method(D_METHOD("clear_attachments"), &SentrySDK::clear_attachments);
ClassDB::bind_method(D_METHOD("set_attribute", "name", "value"), &SentrySDK::set_attribute);
ClassDB::bind_method(D_METHOD("remove_attribute", "name"), &SentrySDK::remove_attribute);
ClassDB::bind_method(D_METHOD("start_session"), &SentrySDK::start_session);
ClassDB::bind_method(D_METHOD("end_session"), &SentrySDK::end_session);

ClassDB::bind_method(D_METHOD("start_new_trace"), &SentrySDK::start_new_trace);

ClassDB::bind_method(D_METHOD("get_current_scope"), &SentrySDK::get_current_scope);
Expand Down
3 changes: 3 additions & 0 deletions src/sentry/sentry_sdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ class SentrySDK : public Object {
void set_user(const Ref<SentryUser> &p_user);
void remove_user();

void start_session();
void end_session();

void start_new_trace();
void set_trace(const String &p_trace_id, const String &p_parent_span_id);

Expand Down
Loading