Skip to content

feat: User feedback API #204

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

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Features

- User feedback API ([#204](https://github.com/getsentry/sentry-godot/pull/204))

### Dependencies

- Bump gdUnit 4 from v5.0.0 to v5.0.4 ([#193](https://github.com/getsentry/sentry-godot/pull/193), [#197](https://github.com/getsentry/sentry-godot/pull/197))
Expand Down
28 changes: 28 additions & 0 deletions doc_classes/SentryFeedback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="SentryFeedback" inherits="RefCounted" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/godotengine/godot/master/doc/class.xsd">
<brief_description>
Represents user feedback in Sentry.
</brief_description>
<description>
</description>
<tutorials>
</tutorials>
<members>
<member name="associated_event_id" type="String" setter="set_associated_event_id" getter="get_associated_event_id" default="&quot;&quot;">
The identifier of an error event in the same project. [i]Optional[/i].
Use this to explicitly link a related error in the feedback UI.
</member>
<member name="contact_email" type="String" setter="set_contact_email" getter="get_contact_email" default="&quot;&quot;">
The email of the user who submitted the feedback. [i]Optional[/i].
If excluded, Sentry attempts to fill this in with user context. Anonymous feedbacks (no name or email) are still accepted.
</member>
<member name="message" type="String" setter="set_message" getter="get_message" default="&quot;&quot;">
Comments of the user, describing what happened and/or sharing feedback. [i]Required[/i].
The max length is 4096 characters.
</member>
<member name="name" type="String" setter="set_name" getter="get_name" default="&quot;&quot;">
The name of the user who submitted the feedback. [i]Optional[/i].
If excluded, Sentry attempts to fill this in with user context. Anonymous feedbacks (no name or email) are still accepted.
</member>
</members>
</class>
7 changes: 7 additions & 0 deletions doc_classes/SentrySDK.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
Captures [param event] and sends it to Sentry, returning the event ID. You can create an event with [method SentrySDK.create_event].
</description>
</method>
<method name="capture_feedback">
<return type="void" />
<param index="0" name="feedback" type="SentryFeedback" />
<description>
Captures user [param feedback] and sends it to Sentry. The feedback can optionally be associated with a specific error event if the [member SentryFeedback.associated_event_id] is set.
</description>
</method>
<method name="capture_message">
<return type="String" />
<param index="0" name="message" type="String" />
Expand Down
23 changes: 23 additions & 0 deletions project/test/suites/test_feedback.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
extends GdUnitTestSuite
## Test Feedback class.
@warning_ignore("unused_parameter")


func test_feedback_properties() -> void:
var feedback := SentryFeedback.new()

assert_str(feedback.associated_event_id).is_empty()
feedback.associated_event_id = "082ce03eface41dd94b8c6b005382d5e"
assert_str(feedback.associated_event_id).is_equal("082ce03eface41dd94b8c6b005382d5e")

assert_str(feedback.name).is_empty()
feedback.name = "Bob"
assert_str(feedback.name).is_equal(feedback.name)

assert_str(feedback.contact_email).is_empty()
feedback.contact_email = "bob@example.com"
assert_str(feedback.contact_email).is_equal("bob@example.com")

assert_str(feedback.message).is_empty()
feedback.message = "something happened"
assert_str(feedback.message).is_equal("something happened")
2 changes: 2 additions & 0 deletions src/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "sentry/util/print.h"
#include "sentry_configuration.h"
#include "sentry_event.h"
#include "sentry_feedback.h"
#include "sentry_logger.h"
#include "sentry_options.h"
#include "sentry_sdk.h"
Expand Down Expand Up @@ -51,6 +52,7 @@ void initialize_module(ModuleInitializationLevel p_level) {
GDREGISTER_INTERNAL_CLASS(RuntimeConfig);
GDREGISTER_CLASS(SentryConfiguration);
GDREGISTER_CLASS(SentryUser);
GDREGISTER_CLASS(SentryFeedback);
GDREGISTER_CLASS(SentrySDK);
GDREGISTER_ABSTRACT_CLASS(SentryEvent);
GDREGISTER_INTERNAL_CLASS(DisabledEvent);
Expand Down
2 changes: 2 additions & 0 deletions src/sentry/disabled_sdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class DisabledSDK : public InternalSDK {
virtual Ref<SentryEvent> create_event() override { return memnew(DisabledEvent); }
virtual String capture_event(const Ref<SentryEvent> &p_event) override { return ""; }

virtual void capture_feedback(const Ref<SentryFeedback> &p_feedback) override {}

virtual void initialize() override {}
};

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 @@ -3,6 +3,7 @@

#include "sentry/level.h"
#include "sentry_event.h"
#include "sentry_feedback.h"
#include "sentry_user.h"

#include <godot_cpp/variant/dictionary.hpp>
Expand Down Expand Up @@ -34,6 +35,8 @@ class InternalSDK {
virtual Ref<SentryEvent> create_event() = 0;
virtual String capture_event(const Ref<SentryEvent> &p_event) = 0;

virtual void capture_feedback(const Ref<SentryFeedback> &p_feedback) = 0;

virtual void initialize() = 0;

virtual ~InternalSDK() = default;
Expand Down
20 changes: 20 additions & 0 deletions src/sentry/native/native_sdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,26 @@ String NativeSDK::capture_event(const Ref<SentryEvent> &p_event) {
return _uuid_as_string(uuid);
}

void NativeSDK::capture_feedback(const Ref<SentryFeedback> &p_feedback) {
ERR_FAIL_COND(p_feedback.is_null());
ERR_FAIL_COND(p_feedback->get_message().is_empty());

sentry_uuid_t event_uuid;
if (p_feedback->get_associated_event_id().is_empty()) {
event_uuid = sentry_uuid_nil();
Copy link
Member

Choose a reason for hiding this comment

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

is this a random uuid? If the id doesn't correspond to an error event the feedback won't be created in sentry, if you're using the old capture_user_feedback

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for bringing this up, I didn't realize it's a different protocol.

} else {
event_uuid = sentry_uuid_from_string(p_feedback->get_associated_event_id().ascii());
}

sentry_value_t uf = sentry_value_new_user_feedback(
&event_uuid,
p_feedback->get_name().utf8(),
p_feedback->get_contact_email().utf8(),
p_feedback->get_message().utf8());

sentry_capture_user_feedback(uf);
Copy link
Member

Choose a reason for hiding this comment

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

why are we wrapping the old capture_user_feedback here? This will still send the old envelope format

Copy link
Member

Choose a reason for hiding this comment

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

The Godot SDK is built on top of sentry-native, which doesn't yet have the new capture_feedback.

See: getsentry/sentry-native#885 (comment)

}

void NativeSDK::initialize() {
ERR_FAIL_NULL(OS::get_singleton());
ERR_FAIL_NULL(ProjectSettings::get_singleton());
Expand Down
2 changes: 2 additions & 0 deletions src/sentry/native/native_sdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class NativeSDK : public InternalSDK {
virtual Ref<SentryEvent> create_event() override;
virtual String capture_event(const Ref<SentryEvent> &p_event) override;

virtual void capture_feedback(const Ref<SentryFeedback> &p_feedback) override;

virtual void initialize() override;

virtual ~NativeSDK() override;
Expand Down
10 changes: 10 additions & 0 deletions src/sentry_feedback.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "sentry_feedback.h"

#include "sentry/simple_bind.h"

void SentryFeedback::_bind_methods() {
BIND_PROPERTY(SentryFeedback, PropertyInfo(Variant::STRING, "name"), set_name, get_name);
BIND_PROPERTY(SentryFeedback, PropertyInfo(Variant::STRING, "contact_email"), set_contact_email, get_contact_email);
BIND_PROPERTY(SentryFeedback, PropertyInfo(Variant::STRING, "message"), set_message, get_message);
BIND_PROPERTY(SentryFeedback, PropertyInfo(Variant::STRING, "associated_event_id"), set_associated_event_id, get_associated_event_id);
}
34 changes: 34 additions & 0 deletions src/sentry_feedback.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef SENTRY_FEEDBACK_H
#define SENTRY_FEEDBACK_H

#include <godot_cpp/classes/ref_counted.hpp>

using namespace godot;

class SentryFeedback : public RefCounted {
GDCLASS(SentryFeedback, RefCounted);

private:
String name;
String contact_email;
String message;
String associated_event_id;

protected:
static void _bind_methods();

public:
String get_name() const { return name; }
void set_name(const String &p_name) { name = p_name; }

String get_contact_email() const { return contact_email; }
void set_contact_email(const String &p_contact_email) { contact_email = p_contact_email; }

String get_message() const { return message; }
void set_message(const String &p_message) { message = p_message; }

String get_associated_event_id() const { return associated_event_id; }
void set_associated_event_id(const String &p_associated_event_id) { associated_event_id = p_associated_event_id; }
};

#endif // SENTRY_FEEDBACK_H
10 changes: 10 additions & 0 deletions src/sentry_sdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ String SentrySDK::capture_event(const Ref<SentryEvent> &p_event) {
return internal_sdk->capture_event(p_event);
}

void SentrySDK::capture_feedback(const Ref<SentryFeedback> &p_feedback) {
ERR_FAIL_COND_MSG(p_feedback.is_null(), "Sentry: Can't capture feedback - feedback object is null.");
ERR_FAIL_COND_MSG(p_feedback->get_message().is_empty(), "Sentry: Can't capture feedback - feedback message is empty.");
if (p_feedback->get_message().length() > 4096) {
WARN_PRINT("Sentry: Feedback message is too long (max 4096 characters).");
}
return internal_sdk->capture_feedback(p_feedback);
}

void SentrySDK::set_tag(const String &p_key, const String &p_value) {
ERR_FAIL_COND_MSG(p_key.is_empty(), "Sentry: Can't set tag with an empty key.");
internal_sdk->set_tag(p_key, p_value);
Expand Down Expand Up @@ -194,6 +203,7 @@ void SentrySDK::_bind_methods() {
ClassDB::bind_method(D_METHOD("remove_user"), &SentrySDK::remove_user);
ClassDB::bind_method(D_METHOD("create_event"), &SentrySDK::create_event);
ClassDB::bind_method(D_METHOD("capture_event", "event"), &SentrySDK::capture_event);
ClassDB::bind_method(D_METHOD("capture_feedback", "feedback"), &SentrySDK::capture_feedback);

// Hidden API methods -- used in testing.
ClassDB::bind_method(D_METHOD("_set_before_send", "callable"), &SentrySDK::set_before_send);
Expand Down
2 changes: 2 additions & 0 deletions src/sentry_sdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class SentrySDK : public Object {
Ref<SentryEvent> create_event() const;
String capture_event(const Ref<SentryEvent> &p_event);

void capture_feedback(const Ref<SentryFeedback> &p_feedback);

// * Hidden API methods -- used in testing

void set_before_send(const Callable &p_callable) { SentryOptions::get_singleton()->set_before_send(p_callable); }
Expand Down
Loading