Skip to content

Commit

Permalink
Introduce send-default-pii option to handle sensitive data (#21)
Browse files Browse the repository at this point in the history
* Introduce `send-default-pii` option to handle sensitive data

* Avoid sending data if it won't be useful

Co-authored-by: Bruno Garcia <[email protected]>

---------

Co-authored-by: Bruno Garcia <[email protected]>
  • Loading branch information
limbonaut and bruno-garcia authored Nov 27, 2024
1 parent df5b624 commit 4c5b36d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
12 changes: 7 additions & 5 deletions src/sentry/contexts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "sentry/environment.h"
#include "sentry/uuid.h"
#include "sentry_options.h"

#include <godot_cpp/classes/dir_access.hpp>
#include <godot_cpp/classes/display_server.hpp>
Expand Down Expand Up @@ -61,12 +62,13 @@ Dictionary make_device_context(const Ref<RuntimeConfig> &p_runtime_config) {
device_context["orientation"] = orientation;
}

// TODO: Need platform-specific solutions - this doesn't work well.
String host = OS::get_singleton()->get_environment("HOST");
if (host.is_empty()) {
host = "localhost";
if (SentryOptions::get_singleton()->is_send_default_pii_enabled()) {
// TODO: Need platform-specific solutions - this doesn't work well.
String host = OS::get_singleton()->get_environment("HOST");
if (!host.is_empty()) {
device_context["name"] = host;
}
}
device_context["name"] = host;

String model = OS::get_singleton()->get_model_name();
if (!model.is_empty() && model != "GenericDevice") {
Expand Down
2 changes: 2 additions & 0 deletions src/sentry_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void SentryOptions::_load_project_settings() {
sample_rate = ProjectSettings::get_singleton()->get_setting("sentry/config/sample_rate", sample_rate);
attach_log = ProjectSettings::get_singleton()->get_setting("sentry/config/attach_log", attach_log);
max_breadcrumbs = ProjectSettings::get_singleton()->get_setting("sentry/config/max_breadcrumbs", max_breadcrumbs);
send_default_pii = ProjectSettings::get_singleton()->get_setting("sentry/config/send_default_pii", send_default_pii);

error_logger_enabled = ProjectSettings::get_singleton()->get_setting("sentry/config/error_logger/enabled", error_logger_enabled);
error_logger_max_lines = ProjectSettings::get_singleton()->get_setting("sentry/config/error_logger/max_lines", error_logger_max_lines);
Expand Down Expand Up @@ -64,6 +65,7 @@ void SentryOptions::_define_project_settings() {
_define_setting(PropertyInfo(Variant::FLOAT, "sentry/config/sample_rate", PROPERTY_HINT_RANGE, "0.0,1.0"), sample_rate);
_define_setting("sentry/config/attach_log", attach_log);
_define_setting(PropertyInfo(Variant::INT, "sentry/config/max_breadcrumbs", PROPERTY_HINT_RANGE, "0, 500"), max_breadcrumbs);
_define_setting("sentry/config/send_default_pii", send_default_pii);

_define_setting("sentry/config/error_logger/enabled", error_logger_enabled);
_define_setting("sentry/config/error_logger/max_lines", error_logger_max_lines);
Expand Down
2 changes: 2 additions & 0 deletions src/sentry_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class SentryOptions {
bool attach_log = true;
int32_t config_value_order = 0;
int max_breadcrumbs = 100;
bool send_default_pii = false;

bool error_logger_enabled = true;
int error_logger_max_lines = 30;
Expand All @@ -47,6 +48,7 @@ class SentryOptions {
double get_sample_rate() const { return sample_rate; }
bool is_attach_log_enabled() const { return attach_log; }
int get_max_breadcrumbs() const { return max_breadcrumbs; }
bool is_send_default_pii_enabled() const { return send_default_pii; }

bool is_error_logger_enabled() const { return error_logger_enabled; }
int get_error_logger_max_lines() const { return error_logger_max_lines; }
Expand Down
7 changes: 2 additions & 5 deletions src/sentry_sdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,9 @@ void SentrySDK::set_user(const Ref<SentryUser> &p_user) {

// Initialize user ID if not supplied.
if (p_user->get_id().is_empty()) {
// Take user ID from the runtime config or generate a new one if it's empty.
String user_id = get_user()->get_id();
if (user_id.is_empty()) {
user_id = sentry::uuid::make_uuid();
if (get_user()->get_id().is_empty() && SentryOptions::get_singleton()->is_send_default_pii_enabled()) {
p_user->generate_new_id();
}
p_user->set_id(user_id);
}

// Save user in a runtime conf-file.
Expand Down

0 comments on commit 4c5b36d

Please sign in to comment.