use of org.apache.htrace.core.TraceScope in project hadoop by apache.
the class FSOutputSummer method writeChecksumChunks.
/** Generate checksums for the given data chunks and output chunks & checksums
* to the underlying output stream.
*/
private void writeChecksumChunks(byte[] b, int off, int len) throws IOException {
sum.calculateChunkedSums(b, off, len, checksum, 0);
TraceScope scope = createWriteTraceScope();
try {
for (int i = 0; i < len; i += sum.getBytesPerChecksum()) {
int chunkLen = Math.min(sum.getBytesPerChecksum(), len - i);
int ckOffset = i / sum.getBytesPerChecksum() * getChecksumSize();
writeChunk(b, off + i, chunkLen, checksum, ckOffset, getChecksumSize());
}
} finally {
if (scope != null) {
scope.close();
}
}
}
use of org.apache.htrace.core.TraceScope in project cxf by apache.
the class AbstractHTraceClientProvider method startTraceSpan.
protected TraceScopeHolder<TraceScope> startTraceSpan(final Map<String, List<String>> requestHeaders, String path, String method) {
Span span = Tracer.getCurrentSpan();
TraceScope traceScope = null;
if (span == null) {
traceScope = tracer.newScope(buildSpanDescription(path, method));
span = traceScope.getSpan();
}
if (span != null) {
final String spanIdHeader = getSpanIdHeader();
// Transfer tracing headers into the response headers
requestHeaders.put(spanIdHeader, Collections.singletonList(span.getSpanId().toString()));
}
// In case of asynchronous client invocation, the span should be detached as JAX-RS
// client request / response filters are going to be executed in different threads.
boolean detached = false;
if (isAsyncInvocation() && traceScope != null) {
traceScope.detach();
detached = true;
}
return new TraceScopeHolder<TraceScope>(traceScope, detached);
}
use of org.apache.htrace.core.TraceScope in project cxf by apache.
the class AbstractHTraceClientProvider method stopTraceSpan.
protected void stopTraceSpan(final TraceScopeHolder<TraceScope> holder) {
if (holder == null) {
return;
}
final TraceScope scope = holder.getScope();
if (scope != null) {
// in another thread and should be re-attached to the current one.
if (holder.isDetached()) {
scope.reattach();
scope.close();
} else {
scope.close();
}
}
}
use of org.apache.htrace.core.TraceScope in project cxf by apache.
the class AbstractHTraceProvider method stopTraceSpan.
protected void stopTraceSpan(final Map<String, List<String>> requestHeaders, final Map<String, List<Object>> responseHeaders, final TraceScopeHolder<TraceScope> holder) {
final String spanIdHeader = getSpanIdHeader();
// Transfer tracing headers into the response headers
if (requestHeaders.containsKey(spanIdHeader)) {
responseHeaders.put(spanIdHeader, CastUtils.cast(requestHeaders.get(spanIdHeader)));
}
if (holder == null) {
return;
}
final TraceScope span = holder.getScope();
if (span != null) {
// one.
if (holder.isDetached()) {
span.reattach();
span.close();
} else {
span.close();
}
}
}
use of org.apache.htrace.core.TraceScope in project cxf by apache.
the class AbstractHTraceProvider method startTraceSpan.
protected TraceScopeHolder<TraceScope> startTraceSpan(final Map<String, List<String>> requestHeaders, String path, String method) {
// Try to extract the Span Id value from the request header
final SpanId spanId = getFirstValueOrDefault(requestHeaders, getSpanIdHeader(), SpanId.INVALID);
TraceScope traceScope = null;
if (SpanId.INVALID.equals(spanId)) {
traceScope = tracer.newScope(buildSpanDescription(path, method));
} else {
traceScope = tracer.newScope(buildSpanDescription(path, method), spanId);
}
// If the service resource is using asynchronous processing mode, the trace
// scope will be closed in another thread and as such should be detached.
boolean detached = false;
if (isAsyncResponse()) {
traceScope.detach();
propagateContinuationSpan(traceScope);
detached = true;
}
return new TraceScopeHolder<TraceScope>(traceScope, detached);
}
Aggregations