/** * Clears current span. */ public void clearCurrentSpan() { currentSpan().setCurrentSpan(ServerSpan.EMPTY); }
/** * Sets the current Trace/Span state. Using this method indicates that a parent request has decided that we should not * trace the current request. * * @see ServerTracer#setStateCurrentTrace(SpanId, String) * @see ServerTracer#setStateUnknown(String) */ public void setStateNoTracing() { currentSpan().setCurrentSpan(ServerSpan.NOT_SAMPLED); }
@Override public void afterConcurrentHandlingStarted(final HttpServletRequest request, final HttpServletResponse response, final Object handler) { request.setAttribute(HTTP_SERVER_SPAN_ATTRIBUTE, serverThreadBinder.getCurrentServerSpan()); serverThreadBinder.setCurrentSpan(null); }
@Override public void afterConcurrentHandlingStarted(final HttpServletRequest request, final HttpServletResponse response, final Object handler) { request.setAttribute(HTTP_SERVER_SPAN_ATTRIBUTE, serverThreadBinder.getCurrentServerSpan()); serverThreadBinder.setCurrentSpan(ServerSpan.EMPTY); }
/** * {@inheritDoc} */ @Override public void run() { serverSpanThreadBinder.setCurrentSpan(currentServerSpan); final long start = System.currentTimeMillis(); try { wrappedRunnable.run(); } finally { final long duration = System.currentTimeMillis() - start; currentServerSpan.incThreadDuration(duration); } }
/** * {@inheritDoc} */ @Override public T call() throws Exception { serverTracer.setCurrentSpan(currentServerSpan); final long start = System.currentTimeMillis(); try { return wrappedCallable.call(); } finally { final long duration = System.currentTimeMillis() - start; currentServerSpan.incThreadDuration(duration); } }
@Override public void afterCompletion(final HttpServletRequest request, final HttpServletResponse response, final Object handler, final Exception ex) { final ServerSpan span = (ServerSpan) request.getAttribute(HTTP_SERVER_SPAN_ATTRIBUTE); if (span != null) { serverThreadBinder.setCurrentSpan(span); } try { serverTracer.setServerSend(); } finally { serverTracer.clearCurrentSpan(); } }
/** Sets a span associated with the context as the current server span. */ public static void setServerSpan(TraceContext context, ServerSpanThreadBinder threadBinder) { if (threadBinder == null) throw new NullPointerException("threadBinder == null"); ServerSpan serverSpan = ServerSpan.create(toSpan(context)); threadBinder.setCurrentSpan(serverSpan); }
@Override public void afterCompletion(final HttpServletRequest request, final HttpServletResponse response, final Object handler, final Exception ex) { final ServerSpan span = (ServerSpan) request.getAttribute(HTTP_SERVER_SPAN_ATTRIBUTE); if (span != null) { serverThreadBinder.setCurrentSpan(span); } responseInterceptor.handle(new HttpServerResponseAdapter(new HttpResponse() { @Override public int getHttpStatusCode() { return response.getStatus(); } })); }
/** * Sets the server sent event for current thread. */ public void setServerSend() { if (submitEndAnnotation("ss")) { currentSpan().setCurrentSpan(ServerSpan.EMPTY); } }
@Override public void afterCompletion(final HttpServletRequest request, final HttpServletResponse response, final Object handler, final Exception ex) { final ServerSpan span = (ServerSpan) request.getAttribute(HTTP_SERVER_SPAN_ATTRIBUTE); if (span != null) { serverThreadBinder.setCurrentSpan(span); } if (serverTracer != null && ex != null) { // TODO: revisit https://github.com/openzipkin/openzipkin.github.io/issues/52 String message = ex.getMessage(); if (message == null) message = ex.getClass().getSimpleName(); serverTracer.submitBinaryAnnotation("error", message); } responseInterceptor.handle(new HttpServerResponseAdapter(new HttpResponse() { // retrolambda fails to backport response::getStatus @Override public int getHttpStatusCode() { return response.getStatus(); // This won't work in Servlet 2.5 } })); } }
/** * {@inheritDoc} */ @Override public void run() { serverSpanThreadBinder().setCurrentSpan(currentServerSpan()); wrappedRunnable().run(); } }
/** * {@inheritDoc} */ @Override public T call() throws Exception { serverSpanThreadBinder().setCurrentSpan(currentServerSpan()); return wrappedCallable().call(); }
void setStateCurrentTrace(Span span, String spanName) { checkNotBlank(spanName, "Null or blank span name"); recorder().name(span, spanName); currentSpan().setCurrentSpan(ServerSpan.create(span)); } /**
/** * {@inheritDoc} */ @Override public T call() throws Exception { if (localSpanThreadBinder() == null) { // old behavior serverSpanThreadBinder().setCurrentSpan(currentServerSpan()); return wrappedCallable().call(); } ServerSpan previousServerSpan = serverSpanThreadBinder().getCurrentServerSpan(); Span previousLocalSpan = localSpanThreadBinder().getCurrentLocalSpan(); try { serverSpanThreadBinder().setCurrentSpan(currentServerSpan()); localSpanThreadBinder().setCurrentSpan(currentLocalSpan()); return wrappedCallable().call(); } finally { serverSpanThreadBinder().setCurrentSpan(previousServerSpan); localSpanThreadBinder().setCurrentSpan(previousLocalSpan); } }
/** * {@inheritDoc} */ @Override public void run() { if (localSpanThreadBinder() == null) { // old behavior serverSpanThreadBinder().setCurrentSpan(currentServerSpan()); wrappedRunnable().run(); return; } ServerSpan previousServerSpan = serverSpanThreadBinder().getCurrentServerSpan(); Span previousLocalSpan = localSpanThreadBinder().getCurrentLocalSpan(); try { serverSpanThreadBinder().setCurrentSpan(currentServerSpan()); localSpanThreadBinder().setCurrentSpan(currentLocalSpan()); wrappedRunnable().run(); } finally { serverSpanThreadBinder().setCurrentSpan(previousServerSpan); localSpanThreadBinder().setCurrentSpan(previousLocalSpan); } } }
this.eventBuilder.withRequestExecutionStartTime(System.currentTimeMillis()); if (this.taskRequestWrapper.getRequestContext().isPresent() && this.taskRequestWrapper.getRequestContext().get().getCurrentServerSpan() != null) { Brave.getServerSpanThreadBinder().setCurrentSpan(this.taskRequestWrapper.getRequestContext().get().getCurrentServerSpan());