adding static factory
package com.datadoghq.trace.resolver;
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-import java.util.Enumeration;
-import java.util.Map;
-import java.util.ServiceLoader;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import com.datadoghq.trace.DDTracer;
import com.datadoghq.trace.integration.DBServiceDecorator;
import com.datadoghq.trace.integration.DDSpanContextDecorator;
@@ -24,9 +14,19 @@ import com.datadoghq.trace.writer.Writer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.google.auto.service.AutoService;
-
+import io.opentracing.NoopTracerFactory;
import io.opentracing.Tracer;
import io.opentracing.contrib.tracerresolver.TracerResolver;
+import io.opentracing.util.GlobalTracer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Map;
+import java.util.ServiceLoader;
@AutoService(TracerResolver.class)
@@ -116,13 +116,23 @@ public class DDTracerResolver extends TracerResolver{
return tracer;
}
+ public static Tracer registerTracer() {
-
- public static void main(String[] args){
ServiceLoader<TracerResolver> RESOLVERS = ServiceLoader.load(TracerResolver.class);
+ Tracer tracer = null;
for (TracerResolver value : RESOLVERS) {
- value.resolveTracer();
+ tracer = value.resolveTracer();
+ if (tracer != null) {
+ break;
+ }
}
+
+ if (tracer == null) {
+ tracer = NoopTracerFactory.create();
+ }
+
+ GlobalTracer.register(tracer);
+ return tracer;
}
}
