Refine search
@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); } }
private static synchronized void loadSpanReceivers(Configuration conf) { if (!receivers.isEmpty()) { log.info("Already loaded span receivers, enable tracing does not need to be called again"); return; } String[] receiverNames = conf.getTrimmedStrings(Property.TRACE_SPAN_RECEIVERS.toString()); if (receiverNames == null || receiverNames.length == 0) { return; } for (String className : receiverNames) { SpanReceiverBuilder builder = new SpanReceiverBuilder(wrapHadoopConf(conf)); SpanReceiver rcvr = builder.spanReceiverClass(className.trim()).build(); if (rcvr == null) { log.warn("Failed to load SpanReceiver {}", className); } else { receivers.add(rcvr); log.debug("SpanReceiver {} was loaded successfully.", className); } } for (SpanReceiver rcvr : receivers) { org.apache.htrace.Trace.addReceiver(rcvr); } }
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);
/** * Wrap the callable in a TraceCallable, if tracing. * @param callable to call * @param description description of the operation being run. If <tt>null</tt> uses the current * thread name * @return The callable provided, wrapped if tracing, 'callable' if not. */ public static <V> Callable<V> wrap(Callable<V> callable, String description) { if (Trace.isTracing()) { return new TraceCallable<V>(Trace.currentSpan(), callable, description); } return callable; }
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");
@Override public void requestShortCircuitShm(String clientName) throws IOException { ShortCircuitShmRequestProto.Builder builder = ShortCircuitShmRequestProto.newBuilder(). setClientName(clientName); if (Trace.isTracing()) { Span s = Trace.currentSpan(); builder.setTraceInfo(DataTransferTraceInfoProto.newBuilder() .setTraceId(s.getTraceId()).setParentId(s.getSpanId())); } ShortCircuitShmRequestProto proto = builder.build(); send(out, Op.REQUEST_SHORT_CIRCUIT_SHM, proto); }
traceScope = Trace.continueSpan(call.traceSpan); if (running) { // unexpected -- log it LOG.info(Thread.currentThread().getName() + " unexpectedly interrupted", e); if (Trace.isTracing()) { traceScope.getSpan().addTimelineAnnotation("unexpectedly interrupted: " + StringUtils.stringifyException(e)); if (Trace.isTracing()) { traceScope.getSpan().addTimelineAnnotation("Exception: " + StringUtils.stringifyException(e)); traceScope.close();
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; }
public void readWithTracing() throws Exception { String fileName = "testReadTraceHooks.dat"; writeTestFile(fileName); long startTime = System.currentTimeMillis(); TraceScope ts = Trace.startSpan("testReadTraceHooks", Sampler.ALWAYS); readTestFile(fileName); ts.close(); long endTime = System.currentTimeMillis(); String[] expectedSpanNames = { "testReadTraceHooks", "org.apache.hadoop.hdfs.protocol.ClientProtocol.getBlockLocations", "ClientNamenodeProtocol#getBlockLocations", "OpReadBlockProto" }; assertSpanNamesFound(expectedSpanNames); // The trace should last about the same amount of time as the test Map<String, List<Span>> map = SetSpanReceiver.SetHolder.getMap(); Span s = map.get("testReadTraceHooks").get(0); Assert.assertNotNull(s); long spanStart = s.getStartTimeMillis(); long spanEnd = s.getStopTimeMillis(); Assert.assertTrue(spanStart - startTime < 100); Assert.assertTrue(spanEnd - endTime < 100); // There should only be one trace id as it should all be homed in the // top trace. for (Span span : SetSpanReceiver.SetHolder.spans.values()) { Assert.assertEquals(ts.getSpan().getTraceId(), span.getTraceId()); } SetSpanReceiver.SetHolder.spans.clear(); }
@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(); } }
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();
protected void tracedWriteRequest(Call call, int priority, Span span) throws IOException { TraceScope ts = Trace.continueSpan(span); try { writeRequest(call, priority, span); } finally { ts.close(); } }
/** * 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; } }
/** * 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(); } }
/** * 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; }
null: this.ringBufferEventHandler.attainSafePoint(); afterCreatingZigZagLatch(); TraceScope scope = Trace.startSpan("FSHFile.replaceWriter"); try { Trace.addTimelineAnnotation("awaiting safepoint"); syncFuture = zigzagLatch.waitSafePoint(publishSyncOnRingBuffer()); Trace.addTimelineAnnotation("closing writer"); this.writer.close(); Trace.addTimelineAnnotation("writer closed"); scope.close();
/** * Get the trace id of the current span. */ public static long currentTraceId() { return org.apache.htrace.Trace.currentSpan().getTraceId(); }
/** * 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)); }