diff --git a/src/Plugins/AppleSentryPlugin/AppleSentryApplicationDelegate.mm b/src/Plugins/AppleSentryPlugin/AppleSentryApplicationDelegate.mm index 9bd1f616cc..58becdec33 100644 --- a/src/Plugins/AppleSentryPlugin/AppleSentryApplicationDelegate.mm +++ b/src/Plugins/AppleSentryPlugin/AppleSentryApplicationDelegate.mm @@ -10,7 +10,7 @@ @implementation AppleSentryApplicationDelegate #pragma mark - UIKitProxyApplicationDelegateInterface -- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSString * AppleSentryPlugin_DSN = Mengine::Helper::AppleGetBundlePluginConfigString( @("MengineAppleSentryPlugin"), @("DSN"), nil ); if( AppleSentryPlugin_DSN == nil ) @@ -18,16 +18,13 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( return NO; } - BOOL AppleSentryPlugin_Debug = Mengine::Helper::AppleGetBundlePluginConfigBoolean( @("MengineAppleSentryPlugin"), @("Debug"), NO ); - const Mengine::Char * BUILD_VERSION = Mengine::Helper::getBuildVersion(); [SentrySDK startWithConfigureOptions:^(SentryOptions *options) { options.dsn = AppleSentryPlugin_DSN; - options.debug = AppleSentryPlugin_Debug; // Enabled debug when first installing is always helpful + options.debug = MENGINE_DEBUG_VALUE(YES, NO); // Enabled debug when first installing is always helpful + options.environment = MENGINE_BUILD_PUBLISH_VALUE(@"production", @"debug"); options.releaseName = @(BUILD_VERSION); - options.attachStacktrace = true; - options.tracesSampleRate = @(1.0); }]; return YES; diff --git a/src/Plugins/AppleSentryPlugin/AppleSentryHelper.h b/src/Plugins/AppleSentryPlugin/AppleSentryHelper.h deleted file mode 100644 index 949be27355..0000000000 --- a/src/Plugins/AppleSentryPlugin/AppleSentryHelper.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "Config/Char.h" -#include "Config/StdInt.h" - -#import - -namespace Mengine -{ - namespace Helper - { - void appleSentryErrorCapture( const Char * _msg, int32_t _code ); - void appleSentryMessageCapture( const Char * _error ); - - void appleSentrySetExtraBoolean( const Char * _key, int32_t _value ); - void appleSentrySetExtraInteger( const Char * _key, int32_t _value ); - void appleSentrySetExtraString( const Char * _key, const Char * _value ); - void appleSentrySetExtraNSString( const Char * _key, NSString * _value ); - } -} diff --git a/src/Plugins/AppleSentryPlugin/AppleSentryHelper.mm b/src/Plugins/AppleSentryPlugin/AppleSentryHelper.mm deleted file mode 100644 index b0fcd6e394..0000000000 --- a/src/Plugins/AppleSentryPlugin/AppleSentryHelper.mm +++ /dev/null @@ -1,50 +0,0 @@ -#import "AppleSentryHelper.h" - -#import - -namespace Mengine -{ - namespace Helper - { - ////////////////////////////////////////////////////////////////////////// - void appleSentryErrorCapture( const Char * _msg, int32_t _code ) - { - NSError *error = [NSError errorWithDomain:@(_msg) code:_code userInfo: nil]; - [SentrySDK captureError:error]; - } - ////////////////////////////////////////////////////////////////////////// - void appleSentryMessageCapture( const Char * _msg ) - { - [SentrySDK captureMessage:@(_msg)]; - } - ////////////////////////////////////////////////////////////////////////// - void appleSentrySetExtraBoolean( const Char * _key, int32_t _value ) - { - [SentrySDK configureScope:^(SentryScope *_Nonnull scope) { - [scope setExtraValue:(_value == 0 ? @FALSE : @TRUE) forKey:@(_key)]; - }]; - } - ////////////////////////////////////////////////////////////////////////// - void appleSentrySetExtraInteger( const Char * _key, int32_t _value ) - { - [SentrySDK configureScope:^(SentryScope *_Nonnull scope) { - [scope setExtraValue:@(_value) forKey:@(_key)]; - }]; - } - ////////////////////////////////////////////////////////////////////////// - void appleSentrySetExtraString( const Char * _key, const Char * _value ) - { - [SentrySDK configureScope:^(SentryScope *_Nonnull scope) { - [scope setExtraValue:@(_value) forKey:@(_key)]; - }]; - } - ////////////////////////////////////////////////////////////////////////// - void appleSentrySetExtraNSString( const Char * _key, NSString * _value ) - { - [SentrySDK configureScope:^(SentryScope *_Nonnull scope) { - [scope setExtraValue:_value forKey:@(_key)]; - }]; - } - ////////////////////////////////////////////////////////////////////////// - } -} diff --git a/src/Plugins/AppleSentryPlugin/AppleSentryLoggerCapture.mm b/src/Plugins/AppleSentryPlugin/AppleSentryLoggerCapture.mm index 6c8f1d86d0..5ca9116dcb 100644 --- a/src/Plugins/AppleSentryPlugin/AppleSentryLoggerCapture.mm +++ b/src/Plugins/AppleSentryPlugin/AppleSentryLoggerCapture.mm @@ -1,11 +1,12 @@ #include "AppleSentryLoggerCapture.h" -#include "AppleSentryHelper.h" #include "Kernel/ConfigHelper.h" #include "Kernel/LoggerHelper.h" #include "Config/StdString.h" +#import + namespace Mengine { ////////////////////////////////////////////////////////////////////////// @@ -43,7 +44,7 @@ MENGINE_STRNCAT( buffer, data_str, data_size ); - Helper::appleSentryMessageCapture( buffer ); + [SentrySDK captureMessage:@(buffer)]; } ////////////////////////////////////////////////////////////////////////// } diff --git a/src/Plugins/AppleSentryPlugin/AppleSentryPlugin.mm b/src/Plugins/AppleSentryPlugin/AppleSentryPlugin.mm index 7d0061968e..8bc2f932b0 100644 --- a/src/Plugins/AppleSentryPlugin/AppleSentryPlugin.mm +++ b/src/Plugins/AppleSentryPlugin/AppleSentryPlugin.mm @@ -58,7 +58,7 @@ } ////////////////////////////////////////////////////////////////////////// void AppleSentryPlugin::_finalizePlugin() - { + { SERVICE_FINALIZE( AppleSentryService ); } ////////////////////////////////////////////////////////////////////////// diff --git a/src/Plugins/AppleSentryPlugin/AppleSentryService.h b/src/Plugins/AppleSentryPlugin/AppleSentryService.h index 946b3da003..9113130892 100644 --- a/src/Plugins/AppleSentryPlugin/AppleSentryService.h +++ b/src/Plugins/AppleSentryPlugin/AppleSentryService.h @@ -19,7 +19,7 @@ namespace Mengine public: bool _initializeService() override; - void _finalizeService() override; + void _finalizeService() override; protected: void notifyCreateApplication_(); diff --git a/src/Plugins/AppleSentryPlugin/AppleSentryService.mm b/src/Plugins/AppleSentryPlugin/AppleSentryService.mm index 2236c33f22..9ecd9fa0cf 100644 --- a/src/Plugins/AppleSentryPlugin/AppleSentryService.mm +++ b/src/Plugins/AppleSentryPlugin/AppleSentryService.mm @@ -1,7 +1,5 @@ #include "AppleSentryService.h" -#include "AppleSentryHelper.h" - #include "Interface/PlatformServiceInterface.h" #include "Interface/ApplicationInterface.h" #include "Interface/LoggerServiceInterface.h" @@ -82,160 +80,135 @@ m_loggerCapture = nullptr; [SentrySDK close]; - } + } ////////////////////////////////////////////////////////////////////////// void AppleSentryService::notifyCreateApplication_() { - NSString * bundleIdentifier = Helper::AppleGetBundleIdentifier(); - - LOGGER_INFO_PROTECTED( "sentry", "sentry set extra [Application: %s]" - , [bundleIdentifier UTF8String] - ); - - Helper::appleSentrySetExtraNSString( "Application", bundleIdentifier ); - - Char companyName[MENGINE_APPLICATION_COMPANY_MAXNAME] = {'\0'}; - APPLICATION_SERVICE() - ->getCompanyName( companyName ); - - LOGGER_INFO_PROTECTED( "sentry", "sentry set extra [Company: %s]" - , companyName - ); - - Helper::appleSentrySetExtraString( "Company", companyName ); - - Char projectName[MENGINE_PLATFORM_PROJECT_TITLE_MAXNAME] = {'\0'}; - APPLICATION_SERVICE() - ->getProjectName( projectName ); - - LOGGER_INFO_PROTECTED( "sentry", "sentry set extra [Project: %s]" - , projectName - ); + [SentrySDK configureScope:^(SentryScope *_Nonnull scope) { + NSString * bundleIdentifier = Helper::AppleGetBundleIdentifier(); + + LOGGER_INFO_PROTECTED( "sentry", "sentry set extra [Application: %s]" + , [bundleIdentifier UTF8String] + ); + + [scope setExtraValue:bundleIdentifier forKey:@"Application"]; + + Char companyName[MENGINE_APPLICATION_COMPANY_MAXNAME] = {'\0'}; + APPLICATION_SERVICE() + ->getCompanyName( companyName ); - Helper::appleSentrySetExtraString( "Project", projectName ); + LOGGER_INFO_PROTECTED( "sentry", "sentry set extra [Company: %s]" + , companyName + ); + + [scope setExtraValue:@(companyName) forKey:@"Company"]; + + Char projectName[MENGINE_PLATFORM_PROJECT_TITLE_MAXNAME] = {'\0'}; + APPLICATION_SERVICE() + ->getProjectName( projectName ); + LOGGER_INFO_PROTECTED( "sentry", "sentry set extra [Project: %s]" + , projectName + ); + + [scope setExtraValue:@(projectName) forKey:@"Project"]; + #ifdef MENGINE_DEBUG - Char userName[MENGINE_PLATFORM_USER_MAXNAME] = {'\0'}; - PLATFORM_SERVICE() - ->getUserName( userName ); + Char userName[MENGINE_PLATFORM_USER_MAXNAME] = {'\0'}; + PLATFORM_SERVICE() + ->getUserName( userName ); - LOGGER_INFO_PROTECTED( "sentry", "sentry set extra [User: %s]" - , userName - ); + LOGGER_INFO_PROTECTED( "sentry", "sentry set extra [User: %s]" + , userName + ); - Helper::appleSentrySetExtraString( "User", userName ); + [scope setExtraValue:@(userName) forKey:@"User"]; #endif + + uint32_t projectVersion = APPLICATION_SERVICE() + ->getProjectVersion(); - uint32_t projectVersion = APPLICATION_SERVICE() - ->getProjectVersion(); - - Char projectVersionString[32] = {'\0'}; - if( Helper::stringalized( projectVersion, projectVersionString, 31 ) == false ) - { - LOGGER_INFO_PROTECTED( "sentry", "sentry set extra [Version: %s]" - , "Error" - ); - - Helper::appleSentrySetExtraString( "Version", "Error" ); - } - else - { - LOGGER_INFO_PROTECTED( "sentry", "sentry set extra [Version: %s]" - , projectVersionString + LOGGER_INFO_PROTECTED( "sentry", "sentry set extra [Version: %u]" + , projectVersion ); - Helper::appleSentrySetExtraString( "Version", projectVersionString ); - } - - bool debugMode = Helper::isDebugMode(); - - LOGGER_INFO_PROTECTED( "sentry", "sentry set extra [Debug: %u]" - , debugMode - ); - - Helper::appleSentrySetExtraBoolean( "Debug", debugMode ); - - bool developmentMode = Helper::isDevelopmentMode(); - - LOGGER_INFO_PROTECTED( "sentry", "sentry set extra [Development: %u]" - , developmentMode - ); - - Helper::appleSentrySetExtraBoolean( "Development", developmentMode ); - - bool masterMode = Helper::isMasterRelease(); - - LOGGER_INFO_PROTECTED( "sentry", "sentry set extra [Master: %u]" - , masterMode - ); - - Helper::appleSentrySetExtraBoolean( "Master", masterMode ); - - bool publishMode = Helper::isBuildPublish(); - - LOGGER_INFO_PROTECTED( "sentry", "sentry set extra [Publish: %u]" - , publishMode - ); + [scope setExtraValue:@(projectVersion) forKey:@"Version"]; + + bool debugMode = Helper::isDebugMode(); - Helper::appleSentrySetExtraBoolean( "Publish", publishMode ); + LOGGER_INFO_PROTECTED( "sentry", "sentry set extra [Debug: %u]" + , debugMode + ); - const Char * ENGINE_GIT_SHA1 = Helper::getEngineGITSHA1(); + [scope setExtraValue:@(debugMode) forKey:@"Debug"]; + + bool developmentMode = Helper::isDevelopmentMode(); - LOGGER_INFO_PROTECTED( "sentry", "sentry set extra [Engine Commit: %s]" - , ENGINE_GIT_SHA1 - ); + LOGGER_INFO_PROTECTED( "sentry", "sentry set extra [Development: %u]" + , developmentMode + ); - Helper::appleSentrySetExtraString( "Engine Commit", ENGINE_GIT_SHA1 ); + [scope setExtraValue:@(developmentMode) forKey:@"Development"]; + + bool masterMode = Helper::isMasterRelease(); - const Char * BUILD_DATE = Helper::getBuildDate(); + LOGGER_INFO_PROTECTED( "sentry", "sentry set extra [Master: %u]" + , masterMode + ); - LOGGER_INFO_PROTECTED( "sentry", "sentry set extra [Build Date: %s]" - , BUILD_DATE - ); + [scope setExtraValue:@(masterMode) forKey:@"Master"]; + + bool publishMode = Helper::isBuildPublish(); - Helper::appleSentrySetExtraString( "Build Date", BUILD_DATE ); + LOGGER_INFO_PROTECTED( "sentry", "sentry set extra [Publish: %u]" + , publishMode + ); - const Char * BUILD_USERNAME = Helper::getBuildUsername(); + [scope setExtraValue:@(publishMode) forKey:@"Publish"]; + + const Char * ENGINE_GIT_SHA1 = Helper::getEngineGITSHA1(); - LOGGER_INFO_PROTECTED( "sentry", "sentry set extra [Build Username: %s]" - , BUILD_USERNAME - ); + LOGGER_INFO_PROTECTED( "sentry", "sentry set extra [Engine Commit: %s]" + , ENGINE_GIT_SHA1 + ); - Helper::appleSentrySetExtraString( "Build Username", BUILD_USERNAME ); + [scope setExtraValue:@(ENGINE_GIT_SHA1) forKey:@"Engine Commit"]; + + const Char * BUILD_DATE = Helper::getBuildDate(); - const Char * contentCommit = Helper::getContentCommit(); + LOGGER_INFO_PROTECTED( "sentry", "sentry set extra [Build Date: %s]" + , BUILD_DATE + ); - LOGGER_INFO_PROTECTED( "sentry", "sentry set extra [Content Commit: %s]" - , contentCommit - ); + [scope setExtraValue:@(BUILD_DATE) forKey:@"Build Date"]; + + const Char * BUILD_USERNAME = Helper::getBuildUsername(); - Helper::appleSentrySetExtraString( "Content Commit", contentCommit ); - - PlatformDateTime dateTime; - DATETIME_SYSTEM() - ->getLocalDateTime( &dateTime ); + LOGGER_INFO_PROTECTED( "sentry", "sentry set extra [Build Username: %s]" + , BUILD_USERNAME + ); - Char LOG_TIMESTAMP[256] = {'\0'}; - Helper::makeLoggerShortDate( dateTime, "[%02u:%02u:%02u:%04u]", LOG_TIMESTAMP, 0, 256 ); + [scope setExtraValue:@(BUILD_USERNAME) forKey:@"Build Username"]; + + const Char * contentCommit = Helper::getContentCommit(); - Helper::appleSentrySetExtraString( "Log Timestamp", LOG_TIMESTAMP ); - Helper::appleSentrySetExtraBoolean( "Engine Stop", false ); + LOGGER_INFO_PROTECTED( "sentry", "sentry set extra [Content Commit: %s]" + , contentCommit + ); - if( HAS_OPTION( "sentrycrash" ) == true ) - { - LOGGER_MESSAGE_RELEASE( "!!!test sentry crash!!!" ); + [scope setExtraValue:@(contentCommit) forKey:@"Content Commit"]; + + PlatformDateTime dateTime; + DATETIME_SYSTEM() + ->getLocalDateTime( &dateTime ); - Char message_uid[21] = {'\0'}; - Helper::makeUID( 20, message_uid ); - message_uid[20] = '\0'; + Char LOG_TIMESTAMP[256] = {'\0'}; + Helper::makeLoggerShortDate( dateTime, "%02u:%02u:%02u:%04u", LOG_TIMESTAMP, 0, 256 ); - LOGGER_MESSAGE_RELEASE( "uid: %s", message_uid ); - LOGGER_MESSAGE_RELEASE( "!!!test sentry crash!!!" ); + [scope setExtraValue:@(LOG_TIMESTAMP) forKey:@"Log Timestamp"]; - Helper::appleSentrySetExtraString( "Crash UID", message_uid ); - - Helper::crash( "sentrycrash" ); - } + [scope setExtraValue:@NO forKey:@"Engine Stop"]; + }]; } ////////////////////////////////////////////////////////////////////////// void AppleSentryService::notifyAssertion_( const Char * _category, EAssertionLevel _level, const Char * _test, const Char * _file, int32_t _line, const Char * _message ) @@ -247,27 +220,35 @@ return; } - Helper::appleSentrySetExtraString( "Assetion Test", _test ); - Helper::appleSentrySetExtraString( "Assetion Function", _file ); - Helper::appleSentrySetExtraInteger( "Assetion Line", _line ); + [SentrySDK configureScope:^(SentryScope *_Nonnull scope) { + [scope setExtraValue:@(_test) forKey:@"Assetion Test"]; + [scope setExtraValue:@(_file) forKey:@"Assetion Function"]; + [scope setExtraValue:@(_line) forKey:@"Assetion Line"]; + }]; - Helper::appleSentryErrorCapture( _message, 0 ); + NSError *error = [NSError errorWithDomain:@(_message) code:0 userInfo: nil]; + [SentrySDK captureError:error]; } ////////////////////////////////////////////////////////////////////////// void AppleSentryService::notifyError_( const Char * _category, EErrorLevel _level, const Char * _file, int32_t _line, const Char * _message ) { MENGINE_UNUSED( _category ); - Helper::appleSentrySetExtraInteger( "Error Level", _level ); - Helper::appleSentrySetExtraString( "Error Function", _file ); - Helper::appleSentrySetExtraInteger( "Error Line", _line ); - - Helper::appleSentryErrorCapture( _message, 0 ); + [SentrySDK configureScope:^(SentryScope *_Nonnull scope) { + [scope setExtraValue:@(_level) forKey:@"Error Level"]; + [scope setExtraValue:@(_file) forKey:@"Error Function"]; + [scope setExtraValue:@(_line) forKey:@"Error Line"]; + }]; + + NSError *error = [NSError errorWithDomain:@(_message) code:0 userInfo: nil]; + [SentrySDK captureError:error]; } ////////////////////////////////////////////////////////////////////////// void AppleSentryService::notifyEngineStop_() { - Helper::appleSentrySetExtraBoolean( "Engine Stop", true ); + [SentrySDK configureScope:^(SentryScope *_Nonnull scope) { + [scope setExtraValue:@YES forKey:@"Engine Stop"]; + }]; } ////////////////////////////////////////////////////////////////////////// } diff --git a/src/Plugins/AppleSentryPlugin/CMakeLists.txt b/src/Plugins/AppleSentryPlugin/CMakeLists.txt index 0cff66ea80..257cf4100d 100644 --- a/src/Plugins/AppleSentryPlugin/CMakeLists.txt +++ b/src/Plugins/AppleSentryPlugin/CMakeLists.txt @@ -12,9 +12,6 @@ src AppleSentryService.h AppleSentryService.mm - - AppleSentryHelper.h - AppleSentryHelper.mm ) if(MENGINE_TARGET_IOS) @@ -31,6 +28,7 @@ elseif(MENGINE_TARGET_MACOS) ) endif() + ADD_MENGINE_PLUGIN(MENGINE_PLUGIN_APPLE_SENTRY) if(MENGINE_TARGET_IOS) @@ -44,4 +42,4 @@ TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${THIRDPARTY_LIB_DIR}/${MENGINE_LIB_PREFIX TARGET_LINK_LIBRARIES(${PROJECT_NAME} Kernel) -ADD_MENGINE_COCOAPOD(Sentry "https://github.com/getsentry/sentry-cocoa.git" "8.9.1") +ADD_MENGINE_COCOAPOD(Sentry "https://github.com/getsentry/sentry-cocoa.git" "8.10.0") diff --git a/src/Plugins/CMakeLists.txt b/src/Plugins/CMakeLists.txt index e3742bbbd4..066cb1cb6f 100644 --- a/src/Plugins/CMakeLists.txt +++ b/src/Plugins/CMakeLists.txt @@ -250,6 +250,10 @@ if(MENGINE_PLUGIN_GAMEANALYTICS) ADD_SUBDIRECTORY(GameAnalyticsPlugin) endif() +if(MENGINE_PLUGIN_APPLE_SENTRY) + ADD_SUBDIRECTORY(AppleSentryPlugin) +endif() + if(MENGINE_PLUGIN_APPLE_GAMECENTER) ADD_SUBDIRECTORY(AppleGameCenterPlugin) endif() @@ -322,8 +326,4 @@ if(MENGINE_PLUGIN_APPLE_ONESIGNAL) ADD_SUBDIRECTORY(AppleOneSignalPlugin) endif() -if(MENGINE_PLUGIN_APPLE_SENTRY) - ADD_SUBDIRECTORY(AppleSentryPlugin) -endif() - MENGINE_SUBFOLDER() \ No newline at end of file