@@ -7,49 +7,96 @@ namespace Sentry.Maui.Device.IntegrationTestApp;
77
88public partial class App : Application
99{
10- private static readonly ConcurrentDictionary < string , Breadcrumb > _breadcrumbs = new ( ) ;
10+ private static readonly ConcurrentDictionary < string , Dictionary < string , string > > systemBreadcrumbs = new ( ) ;
11+ private static string ? testArg ;
1112
1213 public App ( )
1314 {
1415 InitializeComponent ( ) ;
1516 }
1617
17- public static string ? TestArg => System . Environment . GetEnvironmentVariable ( "SENTRY_TEST_ARG" ) ;
18-
1918 public static bool HasTestArg ( string arg )
2019 {
21- return string . Equals ( TestArg , arg , StringComparison . OrdinalIgnoreCase ) ;
20+ return string . Equals ( testArg , arg , StringComparison . OrdinalIgnoreCase ) ;
2221 }
2322
24- public static void RecordBreadcrumb ( Breadcrumb breadcrumb )
23+ public static void ReceiveSystemBreadcrumb ( Breadcrumb breadcrumb )
2524 {
26- if ( breadcrumb . Data ? . TryGetValue ( "action" , out var action ) != true )
25+ if ( breadcrumb . Type != "system" ||
26+ breadcrumb . Data ? . TryGetValue ( "action" , out var action ) != true ||
27+ string . IsNullOrEmpty ( action ) )
2728 {
2829 return ;
2930 }
3031
31- _breadcrumbs [ action ] = new Breadcrumb (
32- breadcrumb . Message ,
33- breadcrumb . Type ,
34- new Dictionary < string , string >
35- {
36- [ "action" ] = action ,
37- [ "thread_id" ] = Thread . CurrentThread . ManagedThreadId . ToString ( )
38- } ,
39- breadcrumb . Category ,
40- breadcrumb . Level ) ;
32+ systemBreadcrumbs [ action ] = new Dictionary < string , string > ( )
33+ {
34+ [ "action" ] = action ,
35+ [ "category" ] = breadcrumb . Category ?? string . Empty ,
36+ [ "thread_id" ] = Thread . CurrentThread . ManagedThreadId . ToString ( ) ,
37+ [ "type" ] = breadcrumb . Type ?? string . Empty ,
38+ } ;
39+
40+ if ( HasTestArg ( action ) )
41+ {
42+ // received after OnAppearing
43+ CaptureSystemBreadcrumb ( action , systemBreadcrumbs [ action ] ! ) ;
44+ Kill ( ) ;
45+ }
4146 }
4247
43- public static bool TryGetBreadcrumb ( string action , out Breadcrumb ? breadcrumb )
48+ public static void CaptureSystemBreadcrumb ( string action , Dictionary < string , string > data )
4449 {
45- return _breadcrumbs . TryGetValue ( action , out breadcrumb ) ;
50+ SentrySdk . CaptureMessage ( action , scope =>
51+ {
52+ foreach ( var kvp in data )
53+ {
54+ scope . SetExtra ( kvp . Key , kvp . Value ) ;
55+ }
56+ } ) ;
4657 }
4758
4859 protected override Window CreateWindow ( IActivationState ? activationState )
4960 {
5061 return new Window ( new AppShell ( ) ) ;
5162 }
5263
64+ public static void OnAppearing ( )
65+ {
66+ testArg = System . Environment . GetEnvironmentVariable ( "SENTRY_TEST_ARG" ) ;
67+
68+ #pragma warning disable CS0618
69+ if ( Enum . TryParse < CrashType > ( testArg , ignoreCase : true , out var crashType ) )
70+ {
71+ SentrySdk . CauseCrash ( crashType ) ;
72+ }
73+ #pragma warning restore CS0618
74+
75+ if ( HasTestArg ( "NullReferenceException" ) )
76+ {
77+ try
78+ {
79+ object ? obj = null ;
80+ _ = obj ! . ToString ( ) ;
81+ }
82+ catch ( NullReferenceException ex )
83+ {
84+ SentrySdk . CaptureException ( ex ) ;
85+ }
86+ Kill ( ) ;
87+ }
88+ else if ( ! string . IsNullOrEmpty ( testArg ) && systemBreadcrumbs . TryGetValue ( testArg , out var breadcrumb ) )
89+ {
90+ // received before OnAppearing
91+ CaptureSystemBreadcrumb ( testArg , breadcrumb ) ;
92+ Kill ( ) ;
93+ }
94+ else if ( HasTestArg ( "None" ) )
95+ {
96+ Kill ( ) ;
97+ }
98+ }
99+
53100 public static void Kill ( )
54101 {
55102 SentrySdk . Close ( ) ;
0 commit comments