diff --git a/modules/sentry-native b/modules/sentry-native index 22ac4ceb..1ea83a8f 160000 --- a/modules/sentry-native +++ b/modules/sentry-native @@ -1 +1 @@ -Subproject commit 22ac4cebcf749e7e3c47fa40bd1cf237d960258e +Subproject commit 1ea83a8f119b110e7cf209976422efe925cd88ca diff --git a/project/main.gd b/project/main.gd index 3d9dc144..3493bbb3 100644 --- a/project/main.gd +++ b/project/main.gd @@ -1,6 +1,9 @@ extends Node func _ready() -> void: + SentrySDK.logger.info("Starting UI on {platform}", { + platform=OS.get_name() + }) if OS.get_name() in ["Android", "iOS"]: get_tree().change_scene_to_file.call_deferred("res://mobile.tscn") else: diff --git a/src/sentry/native/native_sdk.cpp b/src/sentry/native/native_sdk.cpp index dc46a6af..23c7a7e7 100644 --- a/src/sentry/native/native_sdk.cpp +++ b/src/sentry/native/native_sdk.cpp @@ -209,27 +209,36 @@ void NativeSDK::log(LogLevel p_level, const String &p_body, const Dictionary &p_ String body = p_body; - // TODO: Native doesn't support passing attributes yet. - // See: https://github.com/getsentry/sentry-native/issues/1405 + sentry_value_t attributes; + + if (p_attributes.is_empty()) { + attributes = sentry_value_new_null(); + } else { + attributes = sentry_value_new_object(); + for (const Variant &key : p_attributes.keys()) { + sentry_value_set_by_key(attributes, key.stringify().utf8(), + variant_to_attribute(p_attributes[key])); + } + } switch (p_level) { case LOG_LEVEL_TRACE: { - sentry_log_trace(body.utf8()); + sentry_log_trace(body.utf8(), attributes); } break; case LOG_LEVEL_DEBUG: { - sentry_log_debug(body.utf8()); + sentry_log_debug(body.utf8(), attributes); } break; case LOG_LEVEL_INFO: { - sentry_log_info(body.utf8()); + sentry_log_info(body.utf8(), attributes); } break; case LOG_LEVEL_WARN: { - sentry_log_warn(body.utf8()); + sentry_log_warn(body.utf8(), attributes); } break; case LOG_LEVEL_ERROR: { - sentry_log_error(body.utf8()); + sentry_log_error(body.utf8(), attributes); } break; case LOG_LEVEL_FATAL: { - sentry_log_fatal(body.utf8()); + sentry_log_fatal(body.utf8(), attributes); } break; } } @@ -404,6 +413,8 @@ void NativeSDK::init(const PackedStringArray &p_global_attachments, const Callab } } + sentry_options_set_logs_with_attributes(options, true); + // Hooks. sentry_options_set_before_send(options, _handle_before_send, NULL); sentry_options_set_on_crash(options, _handle_on_crash, NULL); diff --git a/src/sentry/native/native_util.cpp b/src/sentry/native/native_util.cpp index 96b14995..68911a41 100644 --- a/src/sentry/native/native_util.cpp +++ b/src/sentry/native/native_util.cpp @@ -146,26 +146,20 @@ Level cstring_to_level(const CharString &p_cstring) { } sentry_value_t variant_to_attribute(const Variant &p_value) { - sentry_value_t obj = sentry_value_new_object(); switch (p_value.get_type()) { case Variant::BOOL: { - sentry_value_set_by_key(obj, "type", sentry_value_new_string("boolean")); - sentry_value_set_by_key(obj, "value", sentry_value_new_bool((bool)p_value)); + return sentry_value_new_attribute(sentry_value_new_bool((bool)p_value), NULL); } break; case Variant::INT: { - sentry_value_set_by_key(obj, "type", sentry_value_new_string("integer")); - sentry_value_set_by_key(obj, "value", sentry_value_new_int64((int64_t)p_value)); + return sentry_value_new_attribute(sentry_value_new_int64((int64_t)p_value), NULL); } break; case Variant::FLOAT: { - sentry_value_set_by_key(obj, "type", sentry_value_new_string("double")); - sentry_value_set_by_key(obj, "value", sentry_value_new_double((double)p_value)); + return sentry_value_new_attribute(sentry_value_new_double((double)p_value), NULL); } break; default: { - sentry_value_set_by_key(obj, "type", sentry_value_new_string("string")); - sentry_value_set_by_key(obj, "value", sentry_value_new_string(p_value.stringify().utf8())); + return sentry_value_new_attribute(sentry_value_new_string(p_value.stringify().utf8()), NULL); } break; } - return obj; } } // namespace sentry::native diff --git a/src/sentry/sentry_logger.cpp b/src/sentry/sentry_logger.cpp index e6bc5a81..a4f3245e 100644 --- a/src/sentry/sentry_logger.cpp +++ b/src/sentry/sentry_logger.cpp @@ -5,42 +5,52 @@ namespace sentry { -void SentryLogger::log(LogLevel p_level, const String &p_body) { - INTERNAL_SDK()->log(p_level, p_body); +void SentryLogger::log(LogLevel p_level, const String &p_body, const Dictionary &p_params) { + String body = p_body; + Dictionary attributes; + if (!p_params.is_empty()) { + attributes["sentry.message.template"] = p_body; + for (const Variant &key : p_params.keys()) { + String attr_key = "sentry.message.parameter." + key.stringify(); + attributes[attr_key] = p_params[key]; + } + body = p_body.format(p_params); + } + INTERNAL_SDK()->log(p_level, body, attributes); } -void SentryLogger::trace(const String &p_body) { - INTERNAL_SDK()->log(LOG_LEVEL_TRACE, p_body); +void SentryLogger::trace(const String &p_body, const Dictionary &p_params) { + log(LOG_LEVEL_TRACE, p_body, p_params); } -void SentryLogger::debug(const String &p_body) { - INTERNAL_SDK()->log(LOG_LEVEL_DEBUG, p_body); +void SentryLogger::debug(const String &p_body, const Dictionary &p_params) { + log(LOG_LEVEL_DEBUG, p_body, p_params); } -void SentryLogger::info(const String &p_body) { - INTERNAL_SDK()->log(LOG_LEVEL_INFO, p_body); +void SentryLogger::info(const String &p_body, const Dictionary &p_params) { + log(LOG_LEVEL_INFO, p_body, p_params); } -void SentryLogger::warn(const String &p_body) { - INTERNAL_SDK()->log(LOG_LEVEL_WARN, p_body); +void SentryLogger::warn(const String &p_body, const Dictionary &p_params) { + log(LOG_LEVEL_WARN, p_body, p_params); } -void SentryLogger::error(const String &p_body) { - INTERNAL_SDK()->log(LOG_LEVEL_ERROR, p_body); +void SentryLogger::error(const String &p_body, const Dictionary &p_params) { + log(LOG_LEVEL_ERROR, p_body, p_params); } -void SentryLogger::fatal(const String &p_body) { - INTERNAL_SDK()->log(LOG_LEVEL_FATAL, p_body); +void SentryLogger::fatal(const String &p_body, const Dictionary &p_params) { + log(LOG_LEVEL_FATAL, p_body, p_params); } void SentryLogger::_bind_methods() { - ClassDB::bind_method(D_METHOD("log", "level", "body"), &SentryLogger::log); - ClassDB::bind_method(D_METHOD("trace", "body"), &SentryLogger::trace); - ClassDB::bind_method(D_METHOD("debug", "body"), &SentryLogger::debug); - ClassDB::bind_method(D_METHOD("info", "body"), &SentryLogger::info); - ClassDB::bind_method(D_METHOD("warn", "body"), &SentryLogger::warn); - ClassDB::bind_method(D_METHOD("error", "body"), &SentryLogger::error); - ClassDB::bind_method(D_METHOD("fatal", "body"), &SentryLogger::fatal); + ClassDB::bind_method(D_METHOD("log", "level", "body", "parameters"), &SentryLogger::log, DEFVAL(Dictionary())); + ClassDB::bind_method(D_METHOD("trace", "body", "parameters"), &SentryLogger::trace, DEFVAL(Dictionary())); + ClassDB::bind_method(D_METHOD("debug", "body", "parameters"), &SentryLogger::debug, DEFVAL(Dictionary())); + ClassDB::bind_method(D_METHOD("info", "body", "parameters"), &SentryLogger::info, DEFVAL(Dictionary())); + ClassDB::bind_method(D_METHOD("warn", "body", "parameters"), &SentryLogger::warn, DEFVAL(Dictionary())); + ClassDB::bind_method(D_METHOD("error", "body", "parameters"), &SentryLogger::error, DEFVAL(Dictionary())); + ClassDB::bind_method(D_METHOD("fatal", "body", "parameters"), &SentryLogger::fatal, DEFVAL(Dictionary())); } SentryLogger::SentryLogger() {} diff --git a/src/sentry/sentry_logger.h b/src/sentry/sentry_logger.h index a4265e5f..1b27e574 100644 --- a/src/sentry/sentry_logger.h +++ b/src/sentry/sentry_logger.h @@ -16,13 +16,13 @@ class SentryLogger : public Object { static void _bind_methods(); public: - void log(LogLevel p_level, const String &p_body); - void trace(const String &p_body); - void debug(const String &p_body); - void info(const String &p_body); - void warn(const String &p_body); - void error(const String &p_body); - void fatal(const String &p_body); + void log(LogLevel p_level, const String &p_body, const Dictionary &p_params); + void trace(const String &p_body, const Dictionary &p_params); + void debug(const String &p_body, const Dictionary &p_params); + void info(const String &p_body, const Dictionary &p_params); + void warn(const String &p_body, const Dictionary &p_params); + void error(const String &p_body, const Dictionary &p_params); + void fatal(const String &p_body, const Dictionary &p_params); SentryLogger(); };