HDDS-1421. Avoid unnecessary object allocations in TracingUtil

Closes #722
This commit is contained in:
Arpit Agarwal 2019-04-12 11:51:58 +02:00 committed by Márton Elek
parent fd676e190a
commit a9b46c58fe
No known key found for this signature in database
GPG Key ID: D51EA8F00EE79B28

View File

@ -34,6 +34,8 @@
*/
public final class TracingUtil {
private static final String NULL_SPAN_AS_STRING = "";
private TracingUtil() {
}
@ -59,13 +61,14 @@ public static void initTracing(String serviceName) {
* @return encoded tracing context.
*/
public static String exportCurrentSpan() {
StringBuilder builder = new StringBuilder();
if (GlobalTracer.get().activeSpan() != null) {
StringBuilder builder = new StringBuilder();
GlobalTracer.get().inject(GlobalTracer.get().activeSpan().context(),
StringCodec.FORMAT, builder);
}
return builder.toString();
}
return NULL_SPAN_AS_STRING;
}
/**
* Export the specific span as a string.
@ -73,12 +76,13 @@ public static String exportCurrentSpan() {
* @return encoded tracing context.
*/
public static String exportSpan(Span span) {
StringBuilder builder = new StringBuilder();
if (span != null) {
StringBuilder builder = new StringBuilder();
GlobalTracer.get().inject(span.context(), StringCodec.FORMAT, builder);
}
return builder.toString();
}
return NULL_SPAN_AS_STRING;
}
/**
* Create a new scope and use the imported span as the parent.