1919import com .facebook .react .bridge .WritableNativeMap ;
2020
2121import java .util .ArrayDeque ;
22+ import java .util .ArrayList ;
2223import java .util .Deque ;
2324import java .util .HashMap ;
2425import java .util .Iterator ;
26+ import java .util .List ;
2527import java .util .Map ;
2628import java .util .logging .Level ;
2729import java .util .logging .Logger ;
@@ -159,14 +161,23 @@ public void crash() {
159161 @ ReactMethod
160162 public void captureBreadcrumb (ReadableMap breadcrumb ) {
161163 logger .info (String .format ("captureEvent '%s'" , breadcrumb ));
164+
165+ BreadcrumbBuilder breadcrumbBuilder = new BreadcrumbBuilder ();
166+ if (breadcrumb .hasKey ("category" )) {
167+ breadcrumbBuilder .setCategory (breadcrumb .getString ("category" ));
168+ }
169+ if (breadcrumb .hasKey ("data" )) {
170+ Map <String , String > newData = new HashMap <>();
171+ for (Map .Entry <String , Object > data : breadcrumb .getMap ("data" ).toHashMap ().entrySet ()) {
172+ newData .put (data .getKey (), data .getValue ().toString ());
173+ }
174+ breadcrumbBuilder .setData (newData );
175+ }
176+ breadcrumbBuilder .setLevel (breadcrumbLevel ((ReadableNativeMap )breadcrumb ));
177+
162178 if (breadcrumb .hasKey ("message" )) {
163- Sentry .record (
164- new BreadcrumbBuilder ()
165- .setMessage (breadcrumb .getString ("message" ))
166- .setCategory (breadcrumb .getString ("category" ))
167- .setLevel (breadcrumbLevel ((ReadableNativeMap )breadcrumb ))
168- .build ()
169- );
179+ breadcrumbBuilder .setMessage (breadcrumb .getString ("message" ));
180+ Sentry .record (breadcrumbBuilder .build ());
170181 }
171182 }
172183
@@ -261,6 +272,7 @@ public static Event buildEvent(EventBuilder eventBuilder) {
261272
262273 setRelease (eventBuilder );
263274 stripInternalSentry (eventBuilder );
275+ eventBuilder .withBreadcrumbs (copyIterator (Sentry .getStoredClient ().getContext ().getBreadcrumbs ()));
264276
265277 if (extra != null ) {
266278 for (Map .Entry <String , Object > entry : extra .toHashMap ().entrySet ()) {
@@ -280,6 +292,13 @@ public static Event buildEvent(EventBuilder eventBuilder) {
280292 return eventBuilder .build ();
281293 }
282294
295+ public static <T > List <T > copyIterator (Iterator <T > iter ) {
296+ List <T > copy = new ArrayList <T >();
297+ while (iter .hasNext ())
298+ copy .add (iter .next ());
299+ return copy ;
300+ }
301+
283302 private static void addExceptionInterface (EventBuilder eventBuilder , String type , String value , ReadableNativeArray stack ) {
284303 StackTraceInterface stackTraceInterface = new StackTraceInterface (convertToNativeStacktrace (stack ));
285304 Deque <SentryException > exceptions = new ArrayDeque <>();
0 commit comments