From 3e790b4b9e13870cd8e8ae4cec743b60bf5db53e Mon Sep 17 00:00:00 2001 From: alves Date: Tue, 6 Jan 2026 20:38:04 +0800 Subject: [PATCH 1/5] feature sentry report to server use log module. --- deps/Sentry/Sentry.cmake | 2 +- src/common_func/common_func.cpp | 73 +++++++++++++++++- src/common_func/common_func.hpp | 4 + src/sentry_wrapper/SentryWrapper.cpp | 106 +++++++++++++++++---------- 4 files changed, 142 insertions(+), 43 deletions(-) diff --git a/deps/Sentry/Sentry.cmake b/deps/Sentry/Sentry.cmake index 138580b24f..07fb569c56 100644 --- a/deps/Sentry/Sentry.cmake +++ b/deps/Sentry/Sentry.cmake @@ -81,7 +81,7 @@ endif() Snapmaker_Orca_add_cmake_project(Sentry GIT_REPOSITORY https://github.com/getsentry/sentry-native.git - GIT_TAG 0.12.1 + GIT_TAG 0.12.2 GIT_SHALLOW ON PATCH_COMMAND ${SENTRY_PATCH_COMMAND} CMAKE_ARGS diff --git a/src/common_func/common_func.cpp b/src/common_func/common_func.cpp index cdde23d3c6..4b31cfd860 100644 --- a/src/common_func/common_func.cpp +++ b/src/common_func/common_func.cpp @@ -100,8 +100,8 @@ namespace common } nlohmann::json json_data; json_file >> json_data; - std::string str_version = json_data["version"]; - std::string str_build_number = json_data["build_number"]; + std::string str_version = json_data.value("version", ""); + std::string str_build_number = json_data.value("build_number", ""); std::string flutter_version = std::string("flutter_version: ") + str_version + std::string(" ") + std::string("build_number: ") + str_build_number; @@ -109,4 +109,73 @@ namespace common return flutter_version; } + + std::string getLocalArea() + { + std::string localArea = ""; + std::string cfgfile = ""; +#ifdef _WIN32 + wchar_t appDataPath[MAX_PATH] = {0}; + auto hr = SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appDataPath); + char* path = new char[MAX_PATH]; + size_t pathLength; + wcstombs_s(&pathLength, path, MAX_PATH, appDataPath, MAX_PATH); + std::string filePath = path; + cfgfile = filePath + "\\" + std::string("Snapmaker_Orca\\Snapmaker_Orca.conf"); +#elif __APPLE__ + const char* home_env = getenv("HOME"); + cfgfile = home_env; + cfgfile = versionFilePath + "/Library/Application Support/Snapmaker_Orca/Snapmaker_Orca.conf"; +#else + +#endif + std::ifstream json_file(cfgfile); + if (!json_file.is_open()) { + std::ifstream json_file(cfgfile); + return ""; + } + + nlohmann::json json_data; + json_file >> json_data; + + auto dataObj = json_data.value("app", nlohmann::json::object()); + localArea = dataObj.value("region", ""); + + return localArea; + } + + std::string getLanguage() + { + std::string localLanguage = ""; + + std::string cfgfile = ""; +#ifdef _WIN32 + wchar_t appDataPath[MAX_PATH] = {0}; + auto hr = SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appDataPath); + char* path = new char[MAX_PATH]; + size_t pathLength; + wcstombs_s(&pathLength, path, MAX_PATH, appDataPath, MAX_PATH); + std::string filePath = path; + cfgfile = filePath + "\\" + std::string("Snapmaker_Orca\\Snapmaker_Orca.conf"); +#elif __APPLE__ + const char* home_env = getenv("HOME"); + cfgfile = home_env; + cfgfile = versionFilePath + "/Library/Application Support/Snapmaker_Orca/Snapmaker_Orca.conf"; +#else + +#endif + std::ifstream json_file(cfgfile); + if (!json_file.is_open()) { + std::ifstream json_file(cfgfile); + return ""; + } + + nlohmann::json json_data; + json_file >> json_data; + + auto dataObj = json_data.value("app", nlohmann::json::object()); + localLanguage = dataObj.value("language", ""); + + return localLanguage; + } } \ No newline at end of file diff --git a/src/common_func/common_func.hpp b/src/common_func/common_func.hpp index 9303b4196f..8ad5eec3f7 100644 --- a/src/common_func/common_func.hpp +++ b/src/common_func/common_func.hpp @@ -25,6 +25,10 @@ namespace common std::string getMachineId(); + std::string getLocalArea(); + + std::string getLanguage(); + } // namespace common #endif \ No newline at end of file diff --git a/src/sentry_wrapper/SentryWrapper.cpp b/src/sentry_wrapper/SentryWrapper.cpp index de4dd86c6a..4657754836 100644 --- a/src/sentry_wrapper/SentryWrapper.cpp +++ b/src/sentry_wrapper/SentryWrapper.cpp @@ -55,10 +55,13 @@ static sentry_value_t on_crash_callback(const sentry_ucontext_t* uctx, sentry_va return event; } + static sentry_value_t before_send_log(sentry_value_t log, void* user_dataa) +{ + return log; + } + static sentry_value_t before_send(sentry_value_t event, void* hint, void* data) { - - sentry_value_t level_val = sentry_value_get_by_key(event, SENTRY_KEY_LEVEL); std::string levelName = sentry_value_as_string(level_val); @@ -198,8 +201,8 @@ void initSentryEx() sentry_options_set_debug(options, 0); #endif - // sentry_options_set_environment(options, "develop"); - sentry_options_set_environment(options, "Release"); + sentry_options_set_environment(options, "develop"); + //sentry_options_set_environment(options, "Release"); sentry_options_set_auto_session_tracking(options, 0); sentry_options_set_symbolize_stacktraces(options, 1); @@ -209,6 +212,10 @@ void initSentryEx() sentry_options_set_sample_rate(options, 1.0); sentry_options_set_traces_sample_rate(options, 1.0); + sentry_options_set_enable_logs(options, 1); + sentry_options_set_before_send_log(options, before_send_log, NULL); + sentry_options_set_logs_with_attributes(options, true); + sentry_init(options); sentry_start_session(); @@ -240,48 +247,67 @@ void sentryReportLogEx(SENTRY_LOG_LEVEL logLevel, const std::string& logTraceId) { sentry_level_t sentry_msg_level; - switch (logLevel) - { - case SENTRY_LOG_TRACE: - sentry_msg_level = SENTRY_LEVEL_TRACE; - break; - case SENTRY_LOG_DEBUG: - sentry_msg_level = SENTRY_LEVEL_DEBUG; - break; - case SENTRY_LOG_INFO: - sentry_msg_level = SENTRY_LEVEL_INFO; - break; - case SENTRY_LOG_WARNING: - sentry_msg_level = SENTRY_LEVEL_WARNING; - break; - case SENTRY_LOG_ERROR: - sentry_msg_level = SENTRY_LEVEL_ERROR; - break; - case SENTRY_LOG_FATAL: - sentry_msg_level = SENTRY_LEVEL_FATAL; - break; - default: - return; - } + sentry_value_t tags = sentry_value_new_object(); - sentry_value_t event = sentry_value_new_message_event(sentry_msg_level, - funcModule.c_str(), - logContent.c_str() - ); + if (!funcModule.empty()) + sentry_value_set_by_key(tags, "function_module", sentry_value_new_string(funcModule.c_str())); - sentry_value_t tags = sentry_value_new_object(); + if (!logTraceId.empty()) + sentry_value_set_by_key(tags, "snapmaker_trace_id", sentry_value_new_string(logTraceId.c_str())); - if (!logTraceId.empty()) - sentry_value_set_by_key(tags, "snapmaker_trace_id", sentry_value_new_string(logTraceId.c_str())); - - if (SENTRY_LEVEL_TRACE == sentry_msg_level) - sentry_value_set_by_key(tags, BURY_POINT, sentry_value_new_string("snapmaker_bury_point")); - if (!logTagKey.empty()) sentry_value_set_by_key(tags, logTagKey.c_str(), sentry_value_new_string(logTagValue.c_str())); - sentry_value_set_by_key(event, "snapmaker_tags", tags); - sentry_capture_event(event); + sentry_value_set_by_key(tags, "snapmaker_version", sentry_value_new_string(Snapmaker_VERSION)); + + std::string flutterVersion = common::get_flutter_version(); + if (!flutterVersion.empty()) + sentry_value_set_by_key(tags, "flutter_version", sentry_value_new_string(flutterVersion.c_str())); + + std::string pcName = common::get_pc_name(); + if (!pcName.empty()) + sentry_value_set_by_key(tags, "pc_name", sentry_value_new_string(pcName.c_str())); + + std::string machineID = common::getMachineId(); + if (!machineID.empty()) + sentry_value_set_by_key(tags, "machine_id", sentry_value_new_string(machineID.c_str())); + + std::string currentLanguage = common::getLanguage(); + if (!currentLanguage.empty()) + sentry_value_set_by_key(tags, "current_language", sentry_value_new_string(currentLanguage.c_str())); + + std::string localArea = common::getLocalArea(); + if (!localArea.empty()) + sentry_value_set_by_key(tags, "local_area", sentry_value_new_string(localArea.c_str())); + + switch (logLevel) { + case SENTRY_LOG_TRACE: + sentry_msg_level = SENTRY_LEVEL_TRACE; + sentry_value_set_by_key(tags, BURY_POINT, sentry_value_new_string("snapmaker_bury_point")); + sentry_log_trace(logContent.c_str(), tags, 3); + break; + case SENTRY_LOG_DEBUG: + sentry_msg_level = SENTRY_LEVEL_DEBUG; + sentry_log_debug(logContent.c_str(), tags, 3); + break; + case SENTRY_LOG_INFO: + sentry_msg_level = SENTRY_LEVEL_INFO; + sentry_log_info(logContent.c_str(), tags, 3); + break; + case SENTRY_LOG_WARNING: + sentry_msg_level = SENTRY_LEVEL_WARNING; + sentry_log_warn(logContent.c_str(), tags, 3); + break; + case SENTRY_LOG_ERROR: + sentry_msg_level = SENTRY_LEVEL_ERROR; + sentry_log_error(logContent.c_str(), tags, 3); + break; + case SENTRY_LOG_FATAL: + sentry_msg_level = SENTRY_LEVEL_FATAL; + sentry_log_fatal(logContent.c_str(), tags, 3); + break; + default: return; + } } From 49546332c3b6977e56b41e4d3b2caad66d918fc7 Mon Sep 17 00:00:00 2001 From: alves Date: Tue, 6 Jan 2026 20:45:05 +0800 Subject: [PATCH 2/5] feature add log for privacy policy changed. --- src/slic3r/GUI/GUI_App.cpp | 4 ++-- src/slic3r/GUI/Preferences.cpp | 3 ++- src/slic3r/GUI/WebGuideDialog.cpp | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index b92533e3f5..d7cdcef833 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -7072,7 +7072,7 @@ bool GUI_App::run_wizard(ConfigWizard::RunReason reason, ConfigWizard::StartPage auto isAgree = wxGetApp().app_config->get("app", "privacy_policy_isagree"); set_privacy_policy(isAgree == "true"); - + BOOST_LOG_TRIVIAL(warning) << "run_wizard changed the privacy policy with: " << (isAgree); return res; } @@ -7292,7 +7292,7 @@ bool GUI_App::config_wizard_startup() { auto isAgree = wxGetApp().app_config->get("app", "privacy_policy_isagree"); set_privacy_policy(isAgree == "true"); - + BOOST_LOG_TRIVIAL(warning) << "config_wizard_startup changed the privacy policy with: " << (isAgree); if (!m_app_conf_exists || preset_bundle->printers.only_default_printers()) { BOOST_LOG_TRIVIAL(info) << "run wizard..."; run_wizard(ConfigWizard::RR_DATA_EMPTY); diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index 41265bc2e0..5909829264 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -750,7 +750,8 @@ wxBoxSizer *PreferencesDialog::create_item_checkbox(wxString title, wxWindow *pa if (param == "privacy_policy_isagree") { - app_config->set("app", "privacy_policy_isagree", checkbox->GetValue()); + app_config->set("app", "privacy_policy_isagree", checkbox->GetValue()); + BOOST_LOG_TRIVIAL(warning) <<"create_item_checkbox changed the privacy policy with: "<<(checkbox->GetValue()?"true" : "false"); set_privacy_policy(checkbox->GetValue()); } // if (param == "staff_pick_switch") { diff --git a/src/slic3r/GUI/WebGuideDialog.cpp b/src/slic3r/GUI/WebGuideDialog.cpp index 7784c408d4..045a099a8e 100644 --- a/src/slic3r/GUI/WebGuideDialog.cpp +++ b/src/slic3r/GUI/WebGuideDialog.cpp @@ -650,6 +650,7 @@ int GuideFrame::SaveProfile() // } else // m_MainPtr->app_config->set(std::string(m_SectionName.mb_str()), "privacyuse", "0"); m_MainPtr->app_config->set("app", "privacy_policy_isagree", PrivacyUse); + BOOST_LOG_TRIVIAL(warning) << "SaveProfile changed the privacy policy with: " << (PrivacyUse ? "true" : "false"); set_privacy_policy(PrivacyUse); m_MainPtr->app_config->set("region", m_Region); m_MainPtr->app_config->set_bool("stealth_mode", StealthMode); From 7ad145dd30d0d68e688058f5fe90b6b8943c4635 Mon Sep 17 00:00:00 2001 From: alves Date: Tue, 6 Jan 2026 20:49:07 +0800 Subject: [PATCH 3/5] feature upload sentry log by the flags control. --- src/sentry_wrapper/SentryWrapper.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/sentry_wrapper/SentryWrapper.cpp b/src/sentry_wrapper/SentryWrapper.cpp index 4657754836..0a2136018c 100644 --- a/src/sentry_wrapper/SentryWrapper.cpp +++ b/src/sentry_wrapper/SentryWrapper.cpp @@ -246,6 +246,10 @@ void sentryReportLogEx(SENTRY_LOG_LEVEL logLevel, const std::string& logTagValue, const std::string& logTraceId) { + if (!get_privacy_policy()) { + return; + } + sentry_level_t sentry_msg_level; sentry_value_t tags = sentry_value_new_object(); From eb49ab79688e042c4491b88e84a06da7034b5756 Mon Sep 17 00:00:00 2001 From: alves Date: Wed, 7 Jan 2026 09:39:44 +0800 Subject: [PATCH 4/5] feature remove not work code. --- src/sentry_wrapper/SentryWrapper.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/sentry_wrapper/SentryWrapper.cpp b/src/sentry_wrapper/SentryWrapper.cpp index 0a2136018c..e3d5bad670 100644 --- a/src/sentry_wrapper/SentryWrapper.cpp +++ b/src/sentry_wrapper/SentryWrapper.cpp @@ -126,11 +126,6 @@ void initSentryEx() sentry_options_t* options = sentry_options_new(); std::string dsn = std::string("https://c74b617c2aedc291444d3a238d23e780@o4508125599563776.ingest.us.sentry.io/4510425163956224"); { -#ifdef __APPLE__ - -#elif _WIN32 - -#endif sentry_options_set_dsn(options, dsn.c_str()); std::string handlerDir = ""; std::string dataBaseDir = ""; From 4a7746cc5a7c5ec215b26d1d189504b8e8c3aae7 Mon Sep 17 00:00:00 2001 From: alves Date: Wed, 7 Jan 2026 10:10:31 +0800 Subject: [PATCH 5/5] feature add tags for sentry report log. --- src/sentry_wrapper/SentryWrapper.cpp | 86 ++++++++++++++++------------ 1 file changed, 50 insertions(+), 36 deletions(-) diff --git a/src/sentry_wrapper/SentryWrapper.cpp b/src/sentry_wrapper/SentryWrapper.cpp index e3d5bad670..33d4163a50 100644 --- a/src/sentry_wrapper/SentryWrapper.cpp +++ b/src/sentry_wrapper/SentryWrapper.cpp @@ -196,8 +196,8 @@ void initSentryEx() sentry_options_set_debug(options, 0); #endif - sentry_options_set_environment(options, "develop"); - //sentry_options_set_environment(options, "Release"); + //sentry_options_set_environment(options, "develop"); + sentry_options_set_environment(options, "Release"); sentry_options_set_auto_session_tracking(options, 0); sentry_options_set_symbolize_stacktraces(options, 1); @@ -235,11 +235,11 @@ void exitSentryEx() sentry_close(); } void sentryReportLogEx(SENTRY_LOG_LEVEL logLevel, - const std::string& logContent, - const std::string& funcModule, - const std::string& logTagKey, - const std::string& logTagValue, - const std::string& logTraceId) + const std::string& logContent, + const std::string& funcModule, + const std::string& logTagKey, + const std::string& logTagValue, + const std::string& logTraceId) { if (!get_privacy_policy()) { return; @@ -248,62 +248,76 @@ void sentryReportLogEx(SENTRY_LOG_LEVEL logLevel, sentry_level_t sentry_msg_level; sentry_value_t tags = sentry_value_new_object(); - if (!funcModule.empty()) - sentry_value_set_by_key(tags, "function_module", sentry_value_new_string(funcModule.c_str())); + if (!funcModule.empty()) { + sentry_value_t attr = sentry_value_new_attribute(sentry_value_new_string(funcModule.c_str()), NULL); + sentry_value_set_by_key(tags, "function_module", attr); + } - if (!logTraceId.empty()) - sentry_value_set_by_key(tags, "snapmaker_trace_id", sentry_value_new_string(logTraceId.c_str())); + if (!logTraceId.empty()) { + sentry_value_t attr = sentry_value_new_attribute(sentry_value_new_string(logTraceId.c_str()), NULL); + sentry_value_set_by_key(tags, "snapmaker_trace_id", attr); + } - if (!logTagKey.empty()) - sentry_value_set_by_key(tags, logTagKey.c_str(), sentry_value_new_string(logTagValue.c_str())); + if (!logTagKey.empty()) { + sentry_value_t attr = sentry_value_new_attribute(sentry_value_new_string(logTagValue.c_str()), NULL); + sentry_value_set_by_key(tags, logTagKey.c_str(), attr); + } - sentry_value_set_by_key(tags, "snapmaker_version", sentry_value_new_string(Snapmaker_VERSION)); + sentry_value_t attr = sentry_value_new_attribute(sentry_value_new_string(Snapmaker_VERSION), NULL); + sentry_value_set_by_key(tags, "snapmaker_version", attr); std::string flutterVersion = common::get_flutter_version(); - if (!flutterVersion.empty()) - sentry_value_set_by_key(tags, "flutter_version", sentry_value_new_string(flutterVersion.c_str())); - + if (!flutterVersion.empty()) { + sentry_value_t attr = sentry_value_new_attribute(sentry_value_new_string(flutterVersion.c_str()), NULL); + sentry_value_set_by_key(tags, "flutter_version", attr); + } std::string pcName = common::get_pc_name(); - if (!pcName.empty()) - sentry_value_set_by_key(tags, "pc_name", sentry_value_new_string(pcName.c_str())); - + if (!pcName.empty()) { + sentry_value_t attr = sentry_value_new_attribute(sentry_value_new_string(pcName.c_str()), NULL); + sentry_value_set_by_key(tags, "pc_name", attr); + } std::string machineID = common::getMachineId(); - if (!machineID.empty()) - sentry_value_set_by_key(tags, "machine_id", sentry_value_new_string(machineID.c_str())); - + if (!machineID.empty()) { + sentry_value_t attr = sentry_value_new_attribute(sentry_value_new_string(machineID.c_str()), NULL); + sentry_value_set_by_key(tags, "machine_id", attr); + } std::string currentLanguage = common::getLanguage(); - if (!currentLanguage.empty()) - sentry_value_set_by_key(tags, "current_language", sentry_value_new_string(currentLanguage.c_str())); - + if (!currentLanguage.empty()) { + sentry_value_t attr = sentry_value_new_attribute(sentry_value_new_string(currentLanguage.c_str()), NULL); + sentry_value_set_by_key(tags, "current_language", attr); + } std::string localArea = common::getLocalArea(); - if (!localArea.empty()) - sentry_value_set_by_key(tags, "local_area", sentry_value_new_string(localArea.c_str())); - + if (!localArea.empty()) + { + sentry_value_t attr = sentry_value_new_attribute(sentry_value_new_string(localArea.c_str()), NULL); + sentry_value_set_by_key(tags, "local_area", attr); + } switch (logLevel) { case SENTRY_LOG_TRACE: sentry_msg_level = SENTRY_LEVEL_TRACE; - sentry_value_set_by_key(tags, BURY_POINT, sentry_value_new_string("snapmaker_bury_point")); - sentry_log_trace(logContent.c_str(), tags, 3); + sentry_value_t attr = sentry_value_new_attribute(sentry_value_new_string("snapmaker_bury_point"), NULL); + sentry_value_set_by_key(tags, BURY_POINT, attr); + sentry_log_trace(logContent.c_str(), tags); break; case SENTRY_LOG_DEBUG: sentry_msg_level = SENTRY_LEVEL_DEBUG; - sentry_log_debug(logContent.c_str(), tags, 3); + sentry_log_debug(logContent.c_str(), tags); break; case SENTRY_LOG_INFO: sentry_msg_level = SENTRY_LEVEL_INFO; - sentry_log_info(logContent.c_str(), tags, 3); + sentry_log_info(logContent.c_str(), tags); break; case SENTRY_LOG_WARNING: sentry_msg_level = SENTRY_LEVEL_WARNING; - sentry_log_warn(logContent.c_str(), tags, 3); + sentry_log_warn(logContent.c_str(), tags); break; case SENTRY_LOG_ERROR: sentry_msg_level = SENTRY_LEVEL_ERROR; - sentry_log_error(logContent.c_str(), tags, 3); + sentry_log_error(logContent.c_str(), tags); break; case SENTRY_LOG_FATAL: sentry_msg_level = SENTRY_LEVEL_FATAL; - sentry_log_fatal(logContent.c_str(), tags, 3); + sentry_log_fatal(logContent.c_str(), tags); break; default: return; }