if (Trace.isTracing()) { traceScope = Trace.startSpan("LockManager.getRowLock"); traceScope.getSpan().addTimelineAnnotation("Getting a lock"); traceScope.getSpan().addTimelineAnnotation("Failed to get row lock"); iie.initCause(ie); if (traceScope != null) { traceScope.getSpan().addTimelineAnnotation("Interrupted exception getting row lock"); traceScope.close();
TraceScope ts0 = Trace.startSpan("Connection Trace", Sampler.ALWAYS); try { connection = ConnectionFactory.createConnection(conf); } finally { ts0.close(); TraceScope ts1 = Trace.startSpan("Get Trace", Sampler.ALWAYS); // co HTraceExample-2-Start Start a span, giving it a name and sample rate. try { Get get = new Get(Bytes.toBytes("row-1")); // co HTraceExample-3-Default Perform common operations that should be traced. Result res = table.get(get); } finally { ts1.close(); // co HTraceExample-4-Close Close the span to group performance details together. System.out.println("Is trace detached? " + ts1.isDetached()); // co HTraceExample-5-Span Talk to the trace and span instances from within the code. Span span = ts1.getSpan(); System.out.println("Span Time: " + span.getAccumulatedMillis()); System.out.println("Span: " + span); System.out.println("Sampler: " + sampler.getClass().getName()); TraceScope ts2 = Trace.startSpan("Scan Trace", sampler); // co HTraceExample-6-Scan Start another span with a different sampler. try { Scan scan = new Scan(); scanner.close(); } finally { ts2.close();
@Override public void postBatchMutateIndispensably(ObserverContext<RegionCoprocessorEnvironment> c, MiniBatchOperationInProgress<Mutation> miniBatchOp, final boolean success) throws IOException { BatchMutateContext context = getBatchMutateContext(c); if (context == null || context.indexUpdates == null) { return; } // get the current span, or just use a null-span to avoid a bunch of if statements try (TraceScope scope = Trace.startSpan("Starting to write index updates")) { Span current = scope.getSpan(); if (current == null) { current = NullSpan.INSTANCE; } if (success) { // if miniBatchOp was successfully written, write index updates if (!context.indexUpdates.isEmpty()) { this.writer.write(context.indexUpdates, false, context.clientVersion); } current.addTimelineAnnotation("Wrote index updates"); } } catch (Throwable t) { String msg = "Failed to write index updates:" + context.indexUpdates; LOG.error(msg, t); ServerUtil.throwIOException(msg, t); } finally { removeBatchMutateContext(c); } }
public void writeWithTracing() throws Exception { long startTime = System.currentTimeMillis(); TraceScope ts = Trace.startSpan("testWriteTraceHooks", Sampler.ALWAYS); writeTestFile("testWriteTraceHooks.dat"); long endTime = System.currentTimeMillis(); ts.close(); Span s = map.get("testWriteTraceHooks").get(0); Assert.assertNotNull(s); long spanStart = s.getStartTimeMillis(); long spanEnd = s.getStopTimeMillis(); for (String desc : spansInTopTrace) { for (Span span : map.get(desc)) { Assert.assertEquals(ts.getSpan().getTraceId(), span.getTraceId());
final Span savedSpan = Trace.currentSpan(); final Span child = Trace.startSpan(SCANNER_OPENED_TRACE_INFO, savedSpan).getSpan(); try { RegionScanner scanner = doPostScannerOpen(c, scan, delegate); try { if (!success && child != null) { child.stop(); Trace.continueSpan(savedSpan);
TraceScope getPathTraceScope(String description, String path) { TraceScope scope = Trace.startSpan(description, traceSampler); Span span = scope.getSpan(); if (span != null) { if (path != null) { span.addKVAnnotation(PATH, path.getBytes(Charset.forName("UTF-8"))); } } return scope; }
@Override public void sync() throws IOException { TraceScope scope = Trace.startSpan("FSHLog.sync"); try { scope = Trace.continueSpan(publishSyncThenBlockOnCompletion(scope.detach())); } finally { assert scope == NullScope.INSTANCE || !scope.isDetached(); scope.close(); } }
@Override public void after() { scope.close(); } }
rowRangeIterator.next(); TraceScope scope = org.apache.htrace.Trace.startSpan("RWI seek"); if (Trace.isTracing()) scope.getSpan().addKVAnnotation(SEEK_RANGE, range.toString().getBytes(StandardCharsets.UTF_8)); try { writeWrapper(true/*, initialSeek*/); } finally { scope.close();
if (traceScope.getSpan() != null) { conn.setTraceScope(traceScope); } else { conn.setSampler(Sampler.NEVER); if (traceScope == null || traceScope.getSpan() == null) return null; first = false; ImmutableBytesWritable ptr = new ImmutableBytesWritable(); ParseNodeFactory factory = new ParseNodeFactory(); LiteralParseNode literal = factory.literal(traceScope.getSpan().getTraceId()); LiteralExpression expression = LiteralExpression.newConstant(literal.getValue(), PLong.INSTANCE,
/** * 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; }
/** * 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(); } }
@Override public Tuple next() throws SQLException { if (!started) { scope.getSpan().addTimelineAnnotation("First request completed"); started = true; } return super.next(); }
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value="NP_NULL_ON_SOME_PATH_EXCEPTION", justification="Will never be null") @Override public long append(final HTableDescriptor htd, final HRegionInfo hri, final WALKey key, final WALEdit edits, final boolean inMemstore) throws IOException { if (this.closed) throw new IOException("Cannot append; log is closed"); // Make a trace scope for the append. It is closed on other side of the ring buffer by the // single consuming thread. Don't have to worry about it. TraceScope scope = Trace.startSpan("FSHLog.append"); // This is crazy how much it takes to make an edit. Do we need all this stuff!!!!???? We need // all this to make a key and then below to append the edit, we need to carry htd, info, // etc. all over the ring buffer. FSWALEntry entry = null; long sequence = this.disruptor.getRingBuffer().next(); try { RingBufferTruck truck = this.disruptor.getRingBuffer().get(sequence); // TODO: reuse FSWALEntry as we do SyncFuture rather create per append. entry = new FSWALEntry(sequence, key, edits, htd, hri, inMemstore); truck.loadPayload(entry, scope.detach()); } finally { this.disruptor.getRingBuffer().publish(sequence); } return sequence; }
Span span = trace.getSpan(); ImmutableBytesWritable indexMetaDataPtr = new ImmutableBytesWritable(); while (tableRefIterator.hasNext()) { child.addTimelineAnnotation("Attempt " + retryCount); List<List<Mutation>> mutationBatchList = getMutationBatchList(batchSize, batchSizeBytes, mutationList); + Bytes.toString(htableName)); child.stop(); child.stop(); shouldRetry = false; mutationCommitTime = System.currentTimeMillis() - startTime;
public Span(TraceScope scope) { this.scope = scope; this.span = scope.getSpan(); }
protected void tracedWriteRequest(Call call, int priority, Span span) throws IOException { TraceScope ts = Trace.continueSpan(span); try { writeRequest(call, priority, span); } finally { ts.close(); } }