@Override public List<List<Span>> getTracesByIds(List<Long> traceIds) { tracer.startNewSpan(component, "get-traces-by-ids"); try { return delegate.getTracesByIds(traceIds); } finally { tracer.finishSpan(); } }
@Override public List<String> getSpanNames(String serviceName) { tracer.startNewSpan(component, "get-span-names"); try { return delegate.getSpanNames(serviceName); } finally { tracer.finishSpan(); } }
@Override public List<String> getServiceNames() { tracer.startNewSpan(component, "get-service-names"); try { return delegate.getServiceNames(); } finally { tracer.finishSpan(); } }
public void record(ApplicationEvent event) { annotations.put(event.getClass().getSimpleName().replace("Event", ""), timestamp + microsSinceInit()); // record duration and flush the trace if we're done if (event instanceof ApplicationReadyEvent) { long duration = microsSinceInit(); // get duration now, as below logic might skew things. ApplicationReadyEvent ready = (ApplicationReadyEvent) event; LocalTracer tracer = ready.getApplicationContext().getBeanFactory() .getBean(Brave.class).localTracer(); tracer.startNewSpan("spring-boot", "bootstrap", timestamp); annotations.forEach(tracer::submitAnnotation); tracer.finishSpan(duration); } }
/** * Request a new local span, which starts now. * * @param component {@link zipkinCoreConstants#LOCAL_COMPONENT component} responsible for the operation * @param operation name of the operation that's begun * @return metadata about the new span or null if one wasn't started due to sampling policy. * @see zipkinCoreConstants#LOCAL_COMPONENT */ public SpanId startNewSpan(String component, String operation) { SpanId spanId = startNewSpan(component, operation, currentTimeMicroseconds()); if (spanId == null) return null; spanAndEndpoint().span().startTick = System.nanoTime(); // embezzle start tick into an internal field. return spanId; }
@Override public List<DependencyLink> getDependencies(long endTs, @Nullable Long lookback) { tracer.startNewSpan(component, "get-dependencies"); try { return delegate.getDependencies(endTs, lookback); } finally { tracer.finishSpan(); } } }
@Override public List<List<Span>> getTraces(QueryRequest request) { if (tracer.startNewSpan(component, "get-traces") != null) { tracer.submitBinaryAnnotation("request", request.toString()); } try { return delegate.getTraces(request); } finally { tracer.finishSpan(); } }
@Test public void usesExistingTraceId_local() throws Exception { server.enqueue(new MockResponse()); SpanId parent = brave.localTracer().startNewSpan(getClass().getSimpleName(), "test"); try { get(client, "/foo"); } finally { brave.localTracer().finishSpan(); } RecordedRequest request = server.takeRequest(); assertThat(request.getHeader("x-b3-traceId")) .isEqualTo(parent.traceIdString()); assertThat(request.getHeader("x-b3-parentspanid")) .endsWith(IdConversion.convertToString(parent.spanId)); }
/** * This tests that the parent is determined at the time the request was made, not when the request * was executed. */ @Test public void usesParentFromInvocationTime_local() throws Exception { server.enqueue(new MockResponse().setBodyDelay(1, TimeUnit.SECONDS)); server.enqueue(new MockResponse()); SpanId parent = brave.localTracer().startNewSpan(getClass().getSimpleName(), "test"); try { getAsync(client, "/foo"); getAsync(client, "/foo"); } finally { brave.localTracer().finishSpan(); } // changing the local span after the fact! brave.localTracer().startNewSpan(getClass().getSimpleName(), "test"); try { for (int i = 0; i < 2; i++) { RecordedRequest request = server.takeRequest(); assertThat(request.getHeader("x-b3-traceId")) .isEqualTo(parent.traceIdString()); assertThat(request.getHeader("x-b3-parentspanid")) .endsWith(IdConversion.convertToString(parent.spanId)); } } finally { brave.localTracer().finishSpan(); } }