public void asChildOf(TraceContext parent) { traceId.copyFrom(parent.traceId); parentId.copyFrom(parent.id); transactionId.copyFrom(parent.transactionId); flags = parent.flags; id.setToRandomValue(); clock.init(parent.clock); onMutation(); }
/** * Creates a new {@code traceparent}-compliant {@link TraceContext} with a 64 bit {@link #id}. * <p> * Note: the {@link #traceId} will still be 128 bit * </p> * @param tracer */ public static TraceContext with64BitId(ElasticApmTracer tracer) { return new TraceContext(tracer, Id.new64BitId()); }
/** * Creates a new {@link TraceContext} with a 128 bit {@link #id}, * suitable for errors, * as those might not have a trace reference and therefore require a larger id in order to be globally unique. * @param tracer */ public static TraceContext with128BitId(ElasticApmTracer tracer) { return new TraceContext(tracer, Id.new128BitId()); }
public <T> Transaction start(TraceContext.ChildContextCreator<T> childContextCreator, @Nullable T parent, long epochMicros, Sampler sampler) { onStart(); if (parent == null || !childContextCreator.asChildOf(traceContext, parent)) { traceContext.asRootSpan(sampler); } if (epochMicros >= 0) { this.timestamp = epochMicros; } else { this.timestamp = traceContext.getClock().getEpochMicros(); } return this; }
@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; }
@Override public Span createSpan() { return createSpan(traceContext.getClock().getEpochMicros()); }
public void end() { end(traceContext.getClock().getEpochMicros()); }
@Override public boolean isChildOf(TraceContextHolder other) { return getTraceContext().isChildOf(other); }
public boolean isSampled() { return getTraceContext().isSampled(); }
@Override public void resetState() { context.resetState(); delegate = null; } }
@Override public Transaction createInstance() { return new Transaction(ElasticApmTracer.this); } });
@Override public Span createInstance() { return new Span(ElasticApmTracer.this); } });
/** * Creates a reference to a {@link TraceContext} * * @return {@code this}, for chaining * @param traceContext parent trace context */ public ErrorCapture asChildOf(TraceContext traceContext) { this.traceContext.asChildOf(traceContext); return this; }
/** * An alias for {@link #isRecorded()} * * @return {@code true} when this span should be sampled, {@code false} otherwise */ public boolean isSampled() { return isRecorded(); }
@Override public void resetState() { for (int i = 0; i < data.length; i++) { data[i] = 0; } onMutation(true); }
@Override public void close() { deactivate(); } };
public void asRootSpan(Sampler sampler) { traceId.setToRandomValue(); id.setToRandomValue(); transactionId.copyFrom(id); if (sampler.isSampled(traceId)) { this.flags = FLAG_RECORDED; } clock.init(); onMutation(); }
@Override public void resetState() { context.resetState(); delegate = null; } }