private void onBatchExport(List<SpanData> spanDataList) { // From the java documentation of the ConcurrentHashMap#entrySet(): // The view's iterator is a "weakly consistent" iterator that will never throw // ConcurrentModificationException, and guarantees to traverse elements as they existed // upon construction of the iterator, and may (but is not guaranteed to) reflect any // modifications subsequent to construction. for (Map.Entry<String, Handler> it : serviceHandlers.entrySet()) { // In case of any exception thrown by the service handlers continue to run. try { it.getValue().export(spanDataList); } catch (Throwable e) { logger.log(Level.WARNING, "Exception thrown by the service export " + it.getKey(), e); } } }
@Test public void serviceHandlerThrowsException() { doThrow(new IllegalArgumentException("No export for you.")) .when(mockServiceHandler) .export(anyListOf(SpanData.class)); SpanExporterImpl spanExporter = SpanExporterImpl.create(4, Duration.create(1, 0)); StartEndHandler startEndHandler = new StartEndHandlerImpl(spanExporter, runningSpanStore, null, new SimpleEventQueue()); spanExporter.registerHandler("test.service", serviceHandler); spanExporter.registerHandler("mock.service", mockServiceHandler); RecordEventsSpanImpl span1 = createSampledEndedSpan(startEndHandler, SPAN_NAME_1); List<SpanData> exported = serviceHandler.waitForExport(1); assertThat(exported).containsExactly(span1.toSpanData()); // Continue to export after the exception was received. RecordEventsSpanImpl span2 = createSampledEndedSpan(startEndHandler, SPAN_NAME_1); exported = serviceHandler.waitForExport(1); assertThat(exported).containsExactly(span2.toSpanData()); }
private void onBatchExport(List<SpanData> spanDataList) { // From the java documentation of the ConcurrentHashMap#entrySet(): // The view's iterator is a "weakly consistent" iterator that will never throw // ConcurrentModificationException, and guarantees to traverse elements as they existed // upon construction of the iterator, and may (but is not guaranteed to) reflect any // modifications subsequent to construction. for (Map.Entry<String, Handler> it : serviceHandlers.entrySet()) { // In case of any exception thrown by the service handlers continue to run. try { it.getValue().export(spanDataList); } catch (Throwable e) { logger.log(Level.WARNING, "Exception thrown by the service export " + it.getKey(), e); } } }