@@ -493,15 +493,19 @@ static sentry_value_t
493493breadcrumb_ts (const char * message , uint64_t ts )
494494{
495495 sentry_value_t breadcrumb = sentry_value_new_breadcrumb (NULL , message );
496- sentry_value_set_by_key (breadcrumb , "timestamp" ,
497- sentry__value_new_string_owned (sentry__usec_time_to_iso8601 (ts )));
496+ if (ts > 0 ) {
497+ sentry_value_set_by_key (breadcrumb , "timestamp" ,
498+ sentry__value_new_string_owned (sentry__usec_time_to_iso8601 (ts )));
499+ } else {
500+ sentry_value_remove_by_key (breadcrumb , "timestamp" );
501+ }
498502 return breadcrumb ;
499503}
500504
501505SENTRY_TEST (scope_breadcrumbs )
502506{
503507 SENTRY_TEST_OPTIONS_NEW (options );
504- sentry_options_set_max_breadcrumbs (options , 5 );
508+ sentry_options_set_max_breadcrumbs (options , 6 );
505509 sentry_init (options );
506510
507511 // global: ["global1", "global4"]
@@ -524,7 +528,7 @@ SENTRY_TEST(scope_breadcrumbs)
524528
525529 sentry_value_t result = sentry_value_get_by_key (event , "breadcrumbs" );
526530 TEST_CHECK (sentry_value_get_type (result ) == SENTRY_VALUE_TYPE_LIST );
527- TEST_CHECK (sentry_value_get_length (result ) == 2 );
531+ TEST_CHECK_INT_EQUAL (sentry_value_get_length (result ), 2 );
528532 TEST_CHECK_MESSAGE_EQUAL (result , 0 , "global1" );
529533 TEST_CHECK_MESSAGE_EQUAL (result , 1 , "global4" );
530534
@@ -547,7 +551,7 @@ SENTRY_TEST(scope_breadcrumbs)
547551
548552 sentry_value_t result = sentry_value_get_by_key (event , "breadcrumbs" );
549553 TEST_CHECK (sentry_value_get_type (result ) == SENTRY_VALUE_TYPE_LIST );
550- TEST_CHECK (sentry_value_get_length (result ) == 4 );
554+ TEST_CHECK_INT_EQUAL (sentry_value_get_length (result ), 4 );
551555 TEST_CHECK_MESSAGE_EQUAL (result , 0 , "global1" );
552556 TEST_CHECK_MESSAGE_EQUAL (result , 1 , "event3" );
553557 TEST_CHECK_MESSAGE_EQUAL (result , 2 , "global4" );
@@ -577,24 +581,80 @@ SENTRY_TEST(scope_breadcrumbs)
577581
578582 sentry_value_t result = sentry_value_get_by_key (event , "breadcrumbs" );
579583 TEST_CHECK (sentry_value_get_type (result ) == SENTRY_VALUE_TYPE_LIST );
580- TEST_CHECK (sentry_value_get_length (result ) == 4 );
584+ TEST_CHECK_INT_EQUAL (sentry_value_get_length (result ), 4 );
581585 TEST_CHECK_MESSAGE_EQUAL (result , 0 , "local2" );
582586 TEST_CHECK_MESSAGE_EQUAL (result , 1 , "event3" );
583587 TEST_CHECK_MESSAGE_EQUAL (result , 2 , "event5" );
584588 TEST_CHECK_MESSAGE_EQUAL (result , 3 , "local6" );
585589
586- // event <- global: ["local2", "event3", "global4", "event5", "local6"]
590+ // event <- global: ["global1", "local2", "event3", "global4", "event5",
591+ // "local6"]
587592 sentry__scope_apply_to_event (
588593 global_scope , options , event , SENTRY_SCOPE_BREADCRUMBS );
589594
590595 result = sentry_value_get_by_key (event , "breadcrumbs" );
591596 TEST_CHECK (sentry_value_get_type (result ) == SENTRY_VALUE_TYPE_LIST );
592- TEST_CHECK (sentry_value_get_length (result ) == 5 );
597+ TEST_CHECK_INT_EQUAL (sentry_value_get_length (result ), 6 );
598+ TEST_CHECK_MESSAGE_EQUAL (result , 0 , "global1" );
599+ TEST_CHECK_MESSAGE_EQUAL (result , 1 , "local2" );
600+ TEST_CHECK_MESSAGE_EQUAL (result , 2 , "event3" );
601+ TEST_CHECK_MESSAGE_EQUAL (result , 3 , "global4" );
602+ TEST_CHECK_MESSAGE_EQUAL (result , 4 , "event5" );
603+ TEST_CHECK_MESSAGE_EQUAL (result , 5 , "local6" );
604+
605+ sentry_scope_free (local_scope );
606+ sentry_value_decref (event );
607+ }
608+
609+ // global: ["global1", "global4", "globalx"]
610+ sentry_add_breadcrumb (breadcrumb_ts ("globalx" , 0 ));
611+
612+ SENTRY_WITH_SCOPE (global_scope ) {
613+ // local: ["local2", "localx", "local6"]
614+ sentry_scope_t * local_scope = sentry_local_scope_new ();
615+ sentry_scope_add_breadcrumb (local_scope , breadcrumb_ts ("local2" , 2 ));
616+ sentry_scope_add_breadcrumb (local_scope , breadcrumb_ts ("localx" , 0 ));
617+ sentry_scope_add_breadcrumb (local_scope , breadcrumb_ts ("local6" , 6 ));
618+
619+ // event: ["event3", "event5", "eventx"]
620+ sentry_value_t event = sentry_value_new_object ();
621+ {
622+ sentry_value_t breadcrumbs = sentry_value_new_list ();
623+ sentry_value_append (breadcrumbs , breadcrumb_ts ("event3" , 3 ));
624+ sentry_value_append (breadcrumbs , breadcrumb_ts ("event5" , 5 ));
625+ sentry_value_append (breadcrumbs , breadcrumb_ts ("eventx" , 0 ));
626+ sentry_value_set_by_key (event , "breadcrumbs" , breadcrumbs );
627+ }
628+
629+ // event <- local: ["local2", "localx", "event3", "event5", "eventx",
630+ // "local6"]
631+ sentry__scope_apply_to_event (
632+ local_scope , options , event , SENTRY_SCOPE_BREADCRUMBS );
633+
634+ sentry_value_t result = sentry_value_get_by_key (event , "breadcrumbs" );
635+ TEST_CHECK (sentry_value_get_type (result ) == SENTRY_VALUE_TYPE_LIST );
636+ TEST_CHECK_INT_EQUAL (sentry_value_get_length (result ), 6 );
593637 TEST_CHECK_MESSAGE_EQUAL (result , 0 , "local2" );
594- TEST_CHECK_MESSAGE_EQUAL (result , 1 , "event3" );
595- TEST_CHECK_MESSAGE_EQUAL (result , 2 , "global4" );
638+ TEST_CHECK_MESSAGE_EQUAL (result , 1 , "localx" );
639+ TEST_CHECK_MESSAGE_EQUAL (result , 2 , "event3" );
640+ TEST_CHECK_MESSAGE_EQUAL (result , 3 , "event5" );
641+ TEST_CHECK_MESSAGE_EQUAL (result , 4 , "eventx" );
642+ TEST_CHECK_MESSAGE_EQUAL (result , 5 , "local6" );
643+
644+ // event <- global: ["event3", "global4", "globalx", "event5", "eventx",
645+ // "local6"]
646+ sentry__scope_apply_to_event (
647+ global_scope , options , event , SENTRY_SCOPE_BREADCRUMBS );
648+
649+ result = sentry_value_get_by_key (event , "breadcrumbs" );
650+ TEST_CHECK (sentry_value_get_type (result ) == SENTRY_VALUE_TYPE_LIST );
651+ TEST_CHECK (sentry_value_get_length (result ) == 6 );
652+ TEST_CHECK_MESSAGE_EQUAL (result , 0 , "event3" );
653+ TEST_CHECK_MESSAGE_EQUAL (result , 1 , "global4" );
654+ TEST_CHECK_MESSAGE_EQUAL (result , 2 , "globalx" );
596655 TEST_CHECK_MESSAGE_EQUAL (result , 3 , "event5" );
597- TEST_CHECK_MESSAGE_EQUAL (result , 4 , "local6" );
656+ TEST_CHECK_MESSAGE_EQUAL (result , 4 , "eventx" );
657+ TEST_CHECK_MESSAGE_EQUAL (result , 5 , "local6" );
598658
599659 sentry_scope_free (local_scope );
600660 sentry_value_decref (event );
0 commit comments