11// Runner uploads the apk by default (on current directory or under the apps' bin).
22// To skip, pass 'skipUpload:true' as the first argument
3+ #pragma warning disable SENTRY0001
34var skipUpload = args . Any ( a => a . Equals ( "skipUpload:true" , StringComparison . OrdinalIgnoreCase ) ) ;
45
5- Console . WriteLine ( $ "Starting runner (skipUpload:{ skipUpload } )...") ;
6+ IntrLog . Info ( $ "Starting runner (skipUpload:{ skipUpload } )...") ;
67
78const string appName = "SymbolCollector.apk" ;
89const string appPackage = "io.sentry.symbolcollector.android" ;
1314var cronJobName = Environment . GetEnvironmentVariable ( "CRON_JOB_NAME" ) ;
1415if ( cronJobName is not null )
1516{
16- Console . WriteLine ( "Running cron job: {0}" , cronJobName ) ;
17+ IntrLog . Info ( "Running cron job: {0}" , cronJobName ) ;
1718}
1819
1920string ? filePath = null ;
3637 options . AutoSessionTracking = true ;
3738 options . TracesSampleRate = 1.0 ;
3839
39- #pragma warning disable SENTRY0001
4040 options . Experimental . EnableLogs = true ;
41- #pragma warning restore SENTRY0001
4241} ) ;
4342
4443var transaction = SentrySdk . StartTransaction ( "appium.runner" , "runner appium to upload apk to saucelabs and collect symbols real devices" ) ;
5554 var getDevicesSpan = transaction . StartChild ( "appium.get-devices" , "getting android devices" ) ;
5655 var devices = await client . GetDevices ( ) ;
5756 getDevicesSpan . Finish ( ) ;
58-
57+
5958 // Simply pick a random device
6059 var deviceToRun = devices [ Random . Shared . Next ( devices . Count ) ] ;
61- Console . WriteLine ( "Randomly selected device: {0}" , deviceToRun ) ;
60+ IntrLog . Info ( "Randomly selected device: {0}" , deviceToRun ) ;
6261
6362 var app = $ "storage:filename={ appName } ";
6463
6564 if ( ! skipUpload )
6665 {
6766 if ( filePath is null )
6867 {
69- Console . WriteLine ( "'filePath' is null, skipping apk upload." ) ;
68+ IntrLog . Info ( "'filePath' is null, skipping apk upload." ) ;
7069 }
7170 else
7271 {
73- Console . WriteLine ( "Uploading apk: {0}" , filePath ) ;
72+ IntrLog . Info ( "Uploading apk: {0}" , filePath ) ;
7473
7574 var span = transaction . StartChild ( "appium.upload-apk" , "uploading apk to saucelabs" ) ;
7675 var buildId = await client . UploadApkAsync ( filePath , appName ) ;
8079 }
8180 else
8281 {
83- Console . WriteLine ( "'skipUpload' is true, skipping apk upload." ) ;
82+ IntrLog . Info ( "'skipUpload' is true, skipping apk upload." ) ;
8483 }
8584
8685 await UploadSymbolsOnSauceLabs ( app , deviceToRun , transaction , client ) ;
@@ -145,7 +144,7 @@ async Task UploadSymbolsOnSauceLabs(string app, SauceLabsDevice deviceToRun, ISp
145144
146145 try
147146 {
148- Console . WriteLine ( "Starting symbol upload..." ) ;
147+ IntrLog . Info ( "Starting symbol upload..." ) ;
149148
150149 var totalWaitTimeSeconds = 40 * 60 ;
151150 var retryCounter = 200 ;
@@ -169,7 +168,7 @@ async Task UploadSymbolsOnSauceLabs(string app, SauceLabsDevice deviceToRun, ISp
169168 {
170169 _ = wait . Until ( d => d . FindElement (
171170 By . Id ( $ "{ appPackage } :id/done_text") ) ) ;
172- Console . WriteLine ( "💯!" ) ;
171+ IntrLog . Info ( "💯!" ) ;
173172 return ;
174173 }
175174 catch ( WebDriverTimeoutException )
@@ -189,7 +188,7 @@ async Task UploadSymbolsOnSauceLabs(string app, SauceLabsDevice deviceToRun, ISp
189188 By . Id ( $ "{ appPackage } :id/dialog_error") ) ;
190189 if ( dialogView is not null )
191190 {
192- Console . WriteLine ( "Failed collecting symbols:" ) ;
191+ IntrLog . Error ( "Failed collecting symbols:" ) ;
193192 var dialogBody = driver . FindElement (
194193 By . Id ( $ "{ appPackage } :id/dialog_body") ) ;
195194 throw new Exception ( dialogBody . Text ) ;
@@ -199,15 +198,15 @@ async Task UploadSymbolsOnSauceLabs(string app, SauceLabsDevice deviceToRun, ISp
199198 {
200199 }
201200
202- Console . WriteLine ( $ "Not done nor errored. Waiting { iterationTimeout } ...") ;
201+ IntrLog . Info ( $ "Not done nor errored. Waiting { iterationTimeout } ...") ;
203202 }
204203 } while ( -- retryCounter != 0 ) ;
205204
206205 throw new TimeoutException ( $ "Waited { totalWaitTimeSeconds } seconds but didn't complete.") ;
207206 }
208207 catch ( WebDriverException e )
209208 {
210- Console . WriteLine ( "WebDriver error, terminating the app: {0}" , e ) ;
209+ IntrLog . Error ( "WebDriver error, terminating the app: {0}" , e ) ;
211210 try
212211 {
213212 driver . TerminateApp ( appPackage ) ;
@@ -222,13 +221,13 @@ async Task UploadSymbolsOnSauceLabs(string app, SauceLabsDevice deviceToRun, ISp
222221 }
223222 catch ( Exception e ) when ( appTerminatedMessage . Equals ( e . Message ) )
224223 {
225- Console . WriteLine ( "App was not running: {0}" , e ) ;
224+ IntrLog . Warning ( "App was not running: {0}" , e ) ;
226225 RestartAppAndCrashRunner ( e ) ;
227226 }
228227
229228 void RestartAppAndCrashRunner ( Exception e )
230229 {
231- Console . WriteLine ( "Restarting the app" ) ;
230+ IntrLog . Info ( "Restarting the app" ) ;
232231
233232 // Relaunch so we can capture any crashes stored on disk on the previous run
234233 driver . ActivateApp ( appPackage ) ;
@@ -253,3 +252,33 @@ void RestartAppAndCrashRunner(Exception e)
253252 driver . Quit ( ) ;
254253 }
255254}
255+
256+ static class IntrLog
257+ {
258+ public static void Info ( string message , params object [ ] args )
259+ {
260+ Console . WriteLine ( message , args ) ;
261+ SentrySdk . Experimental . Logger . LogInfo ( message , args ) ;
262+ }
263+
264+ public static void Warning ( string message , params object [ ] args )
265+ {
266+ Console . WriteLine ( message , args ) ;
267+ SentrySdk . Experimental . Logger . LogWarning ( message , args ) ;
268+ }
269+
270+ public static void Error ( string message , Exception ? exception = null , params object [ ] args )
271+ {
272+ var formattedMessage = args . Length > 0 ? string . Format ( message , args ) : message ;
273+ Console . WriteLine ( formattedMessage ) ;
274+ if ( exception != null )
275+ {
276+ Console . WriteLine ( exception ) ;
277+ SentrySdk . Experimental . Logger . LogError ( $ "{ message } - { exception . Message } ", args ) ;
278+ }
279+ else
280+ {
281+ SentrySdk . Experimental . Logger . LogError ( message , args ) ;
282+ }
283+ }
284+ }
0 commit comments