/** * Finish the current trace. */ public static void off() { org.apache.htrace.Span span = org.apache.htrace.Trace.currentSpan(); if (span != null) { span.stop(); // close() will no-op, but ensure safety if the implementation changes org.apache.htrace.Tracer.getInstance().continueSpan(null).close(); } }
/** * Get the trace id of the current span. */ public static long currentTraceId() { return org.apache.htrace.Trace.currentSpan().getTraceId(); }
/** * Obtain {@link org.apache.accumulo.core.trace.thrift.TInfo} for the current span. */ public static TInfo traceInfo() { Span span = org.apache.htrace.Trace.currentSpan(); if (span != null) { return new TInfo(span.getTraceId(), span.getSpanId()); } return DONT_TRACE; } }
public static String getSpanName(Span span) { return Tracing.TRACE_METRIC_PREFIX + span.getTraceId() + SEPARATOR + span.getParentId() + SEPARATOR + span.getSpanId(); }
/** * Start a span with the currently configured sampling frequency. Creates a new 'current' span * on this thread - the previous 'current' span will be replaced with this newly created span. * <p> * Hands back the direct span as you shouldn't be detaching the span - use {@link TraceRunnable} * instead to detach a span from this operation. * @param connection from which to read parameters * @param string description of the span to start * @return the underlying span. */ public static TraceScope startNewSpan(PhoenixConnection connection, String string) { Sampler<?> sampler = connection.getSampler(); TraceScope scope = Trace.startSpan(string, sampler); addCustomAnnotationsToSpan(scope.getSpan(), connection); return scope; }
@Override public Tuple next() throws SQLException { if (!started) { scope.getSpan().addTimelineAnnotation("First request completed"); started = true; } return super.next(); }
/** * Continue a trace by starting a new span with a given parent and description. */ public static Span trace(TInfo info, String description) { if (info.traceId == 0) { return Span.NULL_SPAN; } TraceInfo ti = new TraceInfo(info.traceId, info.parentId); return new Span(org.apache.htrace.Trace.startSpan(description, ti)); }
@Override public void after() { scope.close(); } }
/** * Add data to the current span. */ public static void data(String k, String v) { org.apache.htrace.Span span = org.apache.htrace.Trace.currentSpan(); if (span != null) span.addKVAnnotation(k.getBytes(UTF_8), v.getBytes(UTF_8)); }
/** * Start a trace span with a given description with the given sampler. */ public static <T> Span on(String description, Sampler<T> sampler) { return new Span(org.apache.htrace.Trace.startSpan(description, sampler)); }
public Span(TraceScope scope) { this.scope = scope; this.span = scope.getSpan(); }
public long traceId() { return span.getTraceId(); }
/** * Check whether tracing is generally enabled. * @return true If tracing is enabled, false otherwise */ public static boolean isTracing() { return Trace.isTracing(); } }
public static Span child(Span s, String d) { if (s == null) { return NullSpan.INSTANCE; } return s.child(d); }
@Override public void close() throws IOException { try { delegate.close(); } finally { if (child != null) { child.stop(); } } } };
@Override public void close() throws SQLException { scope.close(); super.close(); }
/** * Start a new span with a given name, if already tracing. */ public static Span start(String description) { return new Span(org.apache.htrace.Trace.startSpan(description)); }
/** * Returns whether tracing is currently on. */ public static boolean isTracing() { return org.apache.htrace.Trace.isTracing(); }
private void closeTraceScope(final PhoenixConnection conn) { if(conn.getTraceScope()!=null) { conn.getTraceScope().close(); conn.setTraceScope(null); } }