Fixing issue with the tracer factory (decorators aren't loaded)
This commit is contained in:
parent
8f04fcaeba
commit
f67810e729
|
@ -1,6 +1,7 @@
|
|||
package com.datadoghq.trace.resolver;
|
||||
|
||||
import com.datadoghq.trace.DDTracer;
|
||||
import com.datadoghq.trace.integration.DDSpanContextDecorator;
|
||||
import com.datadoghq.trace.sampling.AbstractSampler;
|
||||
import com.datadoghq.trace.sampling.AllSampler;
|
||||
import com.datadoghq.trace.sampling.RateSampler;
|
||||
|
@ -9,6 +10,8 @@ import com.datadoghq.trace.writer.DDAgentWriter;
|
|||
import com.datadoghq.trace.writer.DDApi;
|
||||
import com.datadoghq.trace.writer.LoggingWriter;
|
||||
import com.datadoghq.trace.writer.Writer;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -99,6 +102,12 @@ public class DDTracerFactory {
|
|||
tracer = DDTracerFactory.create(tracerConfig);
|
||||
}
|
||||
|
||||
//Create decorators from resource files
|
||||
final List<DDSpanContextDecorator> decorators = DDDecoratorsFactory.createFromResources();
|
||||
for (final DDSpanContextDecorator decorator : decorators) {
|
||||
tracer.addDecorator(decorator);
|
||||
}
|
||||
|
||||
return tracer;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,11 +23,7 @@ public class DDTracerResolver extends TracerResolver {
|
|||
//Create tracer from resource files
|
||||
tracer = DDTracerFactory.createFromConfigurationFile();
|
||||
|
||||
//Create decorators from resource files
|
||||
final List<DDSpanContextDecorator> decorators = DDDecoratorsFactory.createFromResources();
|
||||
for (final DDSpanContextDecorator decorator : decorators) {
|
||||
tracer.addDecorator(decorator);
|
||||
}
|
||||
|
||||
|
||||
return tracer;
|
||||
}
|
||||
|
|
|
@ -17,4 +17,21 @@ class SpanFactory {
|
|||
null)
|
||||
return new DDSpan(timestampMicro, context)
|
||||
}
|
||||
|
||||
static newSpanTracer(DDTracer tracer) {
|
||||
def context = new DDSpanContext(
|
||||
1L,
|
||||
1L,
|
||||
0L,
|
||||
"fakeService",
|
||||
"fakeOperation",
|
||||
"fakeResource",
|
||||
Collections.emptyMap(),
|
||||
false,
|
||||
"fakeType",
|
||||
Collections.emptyMap(),
|
||||
null,
|
||||
tracer)
|
||||
return new DDSpan(0, context)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package com.datadoghq.trace.integration
|
||||
|
||||
import com.datadoghq.trace.DDSpanContext
|
||||
import com.datadoghq.trace.DDTracer
|
||||
import com.datadoghq.trace.SpanFactory
|
||||
import io.opentracing.tag.StringTag
|
||||
import spock.lang.Specification
|
||||
|
||||
class SpanDecoratorTest extends Specification {
|
||||
|
||||
def "adding span personalisation using Decorators"() {
|
||||
setup:
|
||||
def tracer = new DDTracer()
|
||||
def decorator = new DDSpanContextDecorator() {
|
||||
|
||||
@Override
|
||||
boolean afterSetTag(DDSpanContext context, String tag, Object value) {
|
||||
return super.afterSetTag(context, tag, value)
|
||||
}
|
||||
|
||||
}
|
||||
decorator.setMatchingTag("foo")
|
||||
decorator.setMatchingValue("bar")
|
||||
decorator.setSetTag("newFoo")
|
||||
decorator.setSetValue("newBar")
|
||||
tracer.addDecorator(decorator)
|
||||
|
||||
def span = SpanFactory.newSpanTracer(tracer)
|
||||
new StringTag("foo").set(span, "bar")
|
||||
|
||||
expect:
|
||||
span.getTags().containsKey("newFoo")
|
||||
((String) span.getTags().get("newFoo")) == "newBar"
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue