CloudTraceSdkTraceService extends TraceService { @Override public Span open(String name) { checkNotNull(name); return new SpanImpl(tracers.getCurrent(), name); } CloudTraceSdkTraceService(); @VisibleForTesting  CloudTraceSdkTraceService(Tracers tracers); @Override Span open(String name);  }
@Test public void exampleSpan() { when(mockTracers.getCurrent()).thenReturn(mockTracer); TraceService traceService = new CloudTraceSdkTraceService(mockTracers); try (TraceService.Span span = traceService.open("JDBC.Driver#connect")) { span.annotate(Label.DATABASE_URL, Optional.of("jdbc:mockdriver")); span.annotate(Label.SQL_TEXT, Optional.absent()); } ArgumentCaptor<Labels> labels = ArgumentCaptor.forClass(Labels.class); InOrder inOrder = inOrder(mockTracer); inOrder.verify(mockTracer).startSpan("JDBC.Driver#connect"); inOrder.verify(mockTracer).annotateSpan(eq(null), labels.capture()); inOrder.verify(mockTracer).endSpan(null); verifyNoMoreInteractions(mockTracer); assertThat(labels.getValue().getLabels()) .containsExactly(new com.google.cloud.trace.core.Label( "g.co/jdbc/url", "jdbc:mockdriver")); }