AppEngineTraceService extends TraceService { @Override public Span open(String name) { checkNotNull(name); return new SpanImpl(traceService.startSpan(name)); } AppEngineTraceService(); @VisibleForTesting  AppEngineTraceService(com.google.appengine.api.labs.trace.TraceService traceService); @Override Span open(String name);  }
@Test public void exampleSpan() { when(mockTraceService.startSpan(any(String.class))).thenReturn(mockSpan); TraceService traceService = new AppEngineTraceService(mockTraceService); try (TraceService.Span span = traceService.open("JDBC.Driver#connect")) { span.annotate(Label.DATABASE_URL, Optional.of("jdbc:mockdriver")); span.annotate(Label.SQL_TEXT, Optional.<String>absent()); } InOrder inOrder = inOrder(mockTraceService, mockSpan); inOrder.verify(mockTraceService).startSpan("JDBC.Driver#connect"); inOrder.verify(mockSpan).setLabel("g.co/jdbc/url", "jdbc:mockdriver"); inOrder.verify(mockSpan).close(); verifyNoMoreInteractions(mockTraceService, mockSpan); }