public void activate(TraceContextHolder<?> holder) { if (logger.isDebugEnabled()) { logger.debug("Activating {} on thread {}", holder.getTraceContext(), Thread.currentThread().getId()); } activeStack.get().push(holder); }
/** * Wraps the provided {@link Callable} and makes this {@link TraceContext} active in the {@link Callable#call()} method. * * <p> * Note: does not activate the {@link AbstractSpan} but only the {@link TraceContext}. * This is useful if this span is closed in a different thread than the provided {@link java.util.concurrent.Callable} is executed in. * </p> */ public <V> Callable<V> withActiveContext(Callable<V> runnable) { return tracer.wrapCallable(runnable, getTraceContext()); }
public void deactivate(TraceContextHolder<?> holder) { if (logger.isDebugEnabled()) { logger.debug("Deactivating {} on thread {}", holder.getTraceContext(), Thread.currentThread().getId()); } final Deque<TraceContextHolder<?>> stack = activeStack.get(); assertIsActive(holder, stack.poll()); if (holder == stack.peekLast()) { // if this is the bottom of the stack // clear to avoid potential leaks in case of wrong api usage // makes all leaked spans eligible for GC stack.clear(); } }
/** * Wraps the provided {@link Runnable} and makes this {@link TraceContext} active in the {@link Runnable#run()} method. * * <p> * Note: does not activate the {@link AbstractSpan} but only the {@link TraceContext}. * This is useful if this span is closed in a different thread than the provided {@link Runnable} is executed in. * </p> */ public Runnable withActiveContext(Runnable runnable) { return tracer.wrapRunnable(runnable, getTraceContext()); }
public boolean isSampled() { return getTraceContext().isSampled(); }
@Override public boolean isChildOf(TraceContextHolder parent) { return parent.getTraceContext().getTraceId().equals(traceId) && parent.getTraceContext().getId().equals(parentId); }
public T captureException(@Nullable Throwable t) { if (t != null) { captureException(getTraceContext().getClock().getEpochMicros(), t); } return (T) this; }
public void captureException(long epochMicros, @Nullable Throwable e, @Nullable TraceContextHolder<?> active) { if (e != null) { ErrorCapture error = errorPool.createInstance(); error.withTimestamp(epochMicros); error.setException(e); Transaction currentTransaction = currentTransaction(); if (currentTransaction != null) { error.setTransactionType(currentTransaction.getType()); error.setTransactionSampled(currentTransaction.isSampled()); } if (active != null) { if (active instanceof Transaction) { Transaction transaction = (Transaction) active; // The error might have occurred in a different thread than the one the transaction was recorded // That's why we have to ensure the visibility of the transaction properties error.getContext().copyFrom(transaction.getContextEnsureVisibility()); } else if (active instanceof Span) { Span span = (Span) active; error.getContext().getTags().putAll(span.getContext().getTags()); } error.asChildOf(active.getTraceContext()); } else { error.getTraceContext().getId().setToRandomValue(); } reporter.report(error); } }