HDDS-1421. Avoid unnecessary object allocations in TracingUtil
Closes #722
This commit is contained in:
parent
fd676e190a
commit
a9b46c58fe
@ -34,6 +34,8 @@
|
|||||||
*/
|
*/
|
||||||
public final class TracingUtil {
|
public final class TracingUtil {
|
||||||
|
|
||||||
|
private static final String NULL_SPAN_AS_STRING = "";
|
||||||
|
|
||||||
private TracingUtil() {
|
private TracingUtil() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,13 +61,14 @@ public static void initTracing(String serviceName) {
|
|||||||
* @return encoded tracing context.
|
* @return encoded tracing context.
|
||||||
*/
|
*/
|
||||||
public static String exportCurrentSpan() {
|
public static String exportCurrentSpan() {
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
if (GlobalTracer.get().activeSpan() != null) {
|
if (GlobalTracer.get().activeSpan() != null) {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
GlobalTracer.get().inject(GlobalTracer.get().activeSpan().context(),
|
GlobalTracer.get().inject(GlobalTracer.get().activeSpan().context(),
|
||||||
StringCodec.FORMAT, builder);
|
StringCodec.FORMAT, builder);
|
||||||
}
|
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
return NULL_SPAN_AS_STRING;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Export the specific span as a string.
|
* Export the specific span as a string.
|
||||||
@ -73,12 +76,13 @@ public static String exportCurrentSpan() {
|
|||||||
* @return encoded tracing context.
|
* @return encoded tracing context.
|
||||||
*/
|
*/
|
||||||
public static String exportSpan(Span span) {
|
public static String exportSpan(Span span) {
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
if (span != null) {
|
if (span != null) {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
GlobalTracer.get().inject(span.context(), StringCodec.FORMAT, builder);
|
GlobalTracer.get().inject(span.context(), StringCodec.FORMAT, builder);
|
||||||
}
|
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
return NULL_SPAN_AS_STRING;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new scope and use the imported span as the parent.
|
* Create a new scope and use the imported span as the parent.
|
||||||
|
Loading…
Reference in New Issue
Block a user