From 549943ec63d09f9f103de185bf2b4063bcaf6352 Mon Sep 17 00:00:00 2001 From: Guillaume Polaert Date: Mon, 29 May 2017 17:11:38 +0200 Subject: [PATCH 1/2] Backing decorators with a hash --- .../com/datadoghq/trace/DDSpanContext.java | 2 +- .../java/com/datadoghq/trace/DDTracer.java | 560 +++++++++--------- .../trace/resolver/TracerResolverTest.java | 17 +- .../test/resources/dd-trace-decorators.yaml | 3 + 4 files changed, 302 insertions(+), 280 deletions(-) diff --git a/dd-trace/src/main/java/com/datadoghq/trace/DDSpanContext.java b/dd-trace/src/main/java/com/datadoghq/trace/DDSpanContext.java index f05dda6d26..42f0e34257 100644 --- a/dd-trace/src/main/java/com/datadoghq/trace/DDSpanContext.java +++ b/dd-trace/src/main/java/com/datadoghq/trace/DDSpanContext.java @@ -175,7 +175,7 @@ public class DDSpanContext implements io.opentracing.SpanContext { this.tags.put(tag, value); //Call decorators - for (DDSpanContextDecorator decorator : tracer.getSpanContextDecorators()) { + for (DDSpanContextDecorator decorator : tracer.getSpanContextDecorators(tag)) { decorator.afterSetTag(this, tag, value); } //Error management diff --git a/dd-trace/src/main/java/com/datadoghq/trace/DDTracer.java b/dd-trace/src/main/java/com/datadoghq/trace/DDTracer.java index faf201e053..896d51f04a 100644 --- a/dd-trace/src/main/java/com/datadoghq/trace/DDTracer.java +++ b/dd-trace/src/main/java/com/datadoghq/trace/DDTracer.java @@ -1,14 +1,5 @@ package com.datadoghq.trace; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.datadoghq.trace.integration.DDSpanContextDecorator; import com.datadoghq.trace.propagation.Codec; import com.datadoghq.trace.propagation.HTTPCodec; @@ -16,10 +7,13 @@ import com.datadoghq.trace.sampling.AllSampler; import com.datadoghq.trace.sampling.Sampler; import com.datadoghq.trace.writer.DDAgentWriter; import com.datadoghq.trace.writer.Writer; - import io.opentracing.Span; import io.opentracing.SpanContext; import io.opentracing.propagation.Format; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.*; /** @@ -27,316 +21,336 @@ import io.opentracing.propagation.Format; */ public class DDTracer implements io.opentracing.Tracer { - /** - * Writer is an charge of reporting traces and spans to the desired endpoint - */ - private Writer writer; - /** - * Sampler defines the sampling policy in order to reduce the number of traces for instance - */ - private final Sampler sampler; + /** + * Writer is an charge of reporting traces and spans to the desired endpoint + */ + private Writer writer; + /** + * Sampler defines the sampling policy in order to reduce the number of traces for instance + */ + private final Sampler sampler; - /** - * Default service name if none provided on the trace or span - */ - private final String defaultServiceName; + /** + * Default service name if none provided on the trace or span + */ + private final String defaultServiceName; - /** - * Span context decorators - */ - private final List spanContextDecorators = new ArrayList(); + /** + * Span context decorators + */ + private final Map> spanContextDecorators = new HashMap<>(); - private final static Logger logger = LoggerFactory.getLogger(DDTracer.class); - private final CodecRegistry registry; + private final static Logger logger = LoggerFactory.getLogger(DDTracer.class); + private final CodecRegistry registry; - public static final String UNASSIGNED_DEFAULT_SERVICE_NAME = "unnamed-java-app"; - public static final Writer UNASSIGNED_WRITER = new DDAgentWriter(); - public static final Sampler UNASSIGNED_SAMPLER = new AllSampler(); + public static final String UNASSIGNED_DEFAULT_SERVICE_NAME = "unnamed-java-app"; + public static final Writer UNASSIGNED_WRITER = new DDAgentWriter(); + public static final Sampler UNASSIGNED_SAMPLER = new AllSampler(); - /** - * Default constructor, trace/spans are logged, no trace/span dropped - */ - public DDTracer() { - this(UNASSIGNED_WRITER); - } + /** + * Default constructor, trace/spans are logged, no trace/span dropped + */ + public DDTracer() { + this(UNASSIGNED_WRITER); + } - public DDTracer(Writer writer) { - this(writer, new AllSampler()); - } + public DDTracer(Writer writer) { + this(writer, new AllSampler()); + } - public DDTracer(Writer writer, Sampler sampler) { - this(UNASSIGNED_DEFAULT_SERVICE_NAME, writer, sampler); - } + public DDTracer(Writer writer, Sampler sampler) { + this(UNASSIGNED_DEFAULT_SERVICE_NAME, writer, sampler); + } - public DDTracer(String defaultServiceName, Writer writer, Sampler sampler) { - this.defaultServiceName = defaultServiceName; - this.writer = writer; - this.writer.start(); - this.sampler = sampler; - registry = new CodecRegistry(); - registry.register(Format.Builtin.HTTP_HEADERS, new HTTPCodec()); - } + public DDTracer(String defaultServiceName, Writer writer, Sampler sampler) { + this.defaultServiceName = defaultServiceName; + this.writer = writer; + this.writer.start(); + this.sampler = sampler; + registry = new CodecRegistry(); + registry.register(Format.Builtin.HTTP_HEADERS, new HTTPCodec()); + } - /** - * Returns the list of span context decorators - * - * @return the list of span context decorators - */ - public List getSpanContextDecorators() { - return Collections.unmodifiableList(spanContextDecorators); - } + /** + * Returns the list of span context decorators + * + * @return the list of span context decorators + */ + public List getSpanContextDecorators(String tag) { + List decorators = Collections.emptyList(); + String key = getHashKey(tag); - /** - * Add a new decorator in the list ({@link DDSpanContextDecorator}) - * - * @param decorator The decorator in the list - */ - public void addDecorator(DDSpanContextDecorator decorator) { - spanContextDecorators.add(decorator); - } + if (spanContextDecorators.containsKey(key)) { + decorators = Collections.unmodifiableList(spanContextDecorators.get(key)); + } - public DDSpanBuilder buildSpan(String operationName) { - return new DDSpanBuilder(operationName); - } + return decorators; + } + + /** + * Add a new decorator in the list ({@link DDSpanContextDecorator}) + * + * @param decorator The decorator in the list + */ + public void addDecorator(DDSpanContextDecorator decorator) { + String key = getHashKey(decorator.getMatchingTag()); + + List list = spanContextDecorators.get(key); + if (list == null) { + list = new ArrayList<>(); + } + list.add(decorator); + + spanContextDecorators.put(key, list); + } - public void inject(SpanContext spanContext, Format format, T carrier) { - - Codec codec = registry.get(format); - if (codec == null) { - logger.warn("Unsupported format for propagation - {}", format.getClass().getName()); - } else { - codec.inject((DDSpanContext) spanContext, carrier); - } - } - - public SpanContext extract(Format format, T carrier) { - - Codec codec = registry.get(format); - if (codec == null) { - logger.warn("Unsupported format for propagation - {}", format.getClass().getName()); - } else { - return codec.extract(carrier); - } - return null; - } + public DDSpanBuilder buildSpan(String operationName) { + return new DDSpanBuilder(operationName); + } - /** - * We use the sampler to know if the trace has to be reported/written. - * The sampler is called on the first span (root span) of the trace. - * If the trace is marked as a sample, we report it. - * - * @param trace a list of the spans related to the same trace - */ - public void write(List trace) { - if (trace.isEmpty()) { - return; - } - if (this.sampler.sample((DDSpan) trace.get(0))) { - this.writer.write(trace); - } - } + public void inject(SpanContext spanContext, Format format, T carrier) { - public void close() { - writer.close(); - } + Codec codec = registry.get(format); + if (codec == null) { + logger.warn("Unsupported format for propagation - {}", format.getClass().getName()); + } else { + codec.inject((DDSpanContext) spanContext, carrier); + } + } - /** - * Spans are built using this builder - */ - public class DDSpanBuilder implements SpanBuilder { + public SpanContext extract(Format format, T carrier) { - /** - * Each span must have an operationName according to the opentracing specification - */ - private String operationName; - - // Builder attributes - private Map tags = Collections.emptyMap(); - private long timestamp; - private SpanContext parent; - private String serviceName; - private String resourceName; - private boolean errorFlag; - private String spanType; - - /** - * This method actually build the span according to the builder settings - * DD-Agent requires a serviceName. If it has not been provided, the method will throw a RuntimeException - * - * @return An fresh span - */ - public DDSpan start() { - - // build the context - DDSpanContext context = buildSpanContext(); - DDSpan span = new DDSpan(this.timestamp, context); - - logger.debug("{} - Starting a new span.", span); - - return span; - } + Codec codec = registry.get(format); + if (codec == null) { + logger.warn("Unsupported format for propagation - {}", format.getClass().getName()); + } else { + return codec.extract(carrier); + } + return null; + } - public DDTracer.DDSpanBuilder withTag(String tag, Number number) { - return withTag(tag, (Object) number); - } + /** + * We use the sampler to know if the trace has to be reported/written. + * The sampler is called on the first span (root span) of the trace. + * If the trace is marked as a sample, we report it. + * + * @param trace a list of the spans related to the same trace + */ + public void write(List trace) { + if (trace.isEmpty()) { + return; + } + if (this.sampler.sample((DDSpan) trace.get(0))) { + this.writer.write(trace); + } + } - public DDTracer.DDSpanBuilder withTag(String tag, String string) { - if (tag.equals(DDTags.SERVICE_NAME)) { - return withServiceName(string); - } else if (tag.equals(DDTags.RESOURCE_NAME)) { - return withResourceName(string); - } else if (tag.equals(DDTags.SPAN_TYPE)) { - return withSpanType(string); - } else { - return withTag(tag, (Object) string); - } - } + public void close() { + writer.close(); + } - public DDTracer.DDSpanBuilder withTag(String tag, boolean bool) { - return withTag(tag, (Object) bool); - } + /** + * Spans are built using this builder + */ + public class DDSpanBuilder implements SpanBuilder { - public DDSpanBuilder(String operationName) { - this.operationName = operationName; - } + /** + * Each span must have an operationName according to the opentracing specification + */ + private String operationName; + + // Builder attributes + private Map tags = Collections.emptyMap(); + private long timestamp; + private SpanContext parent; + private String serviceName; + private String resourceName; + private boolean errorFlag; + private String spanType; + + /** + * This method actually build the span according to the builder settings + * DD-Agent requires a serviceName. If it has not been provided, the method will throw a RuntimeException + * + * @return An fresh span + */ + public DDSpan start() { + + // build the context + DDSpanContext context = buildSpanContext(); + DDSpan span = new DDSpan(this.timestamp, context); + + logger.debug("{} - Starting a new span.", span); + + return span; + } - public DDTracer.DDSpanBuilder withStartTimestamp(long timestampMillis) { - this.timestamp = timestampMillis; - return this; - } + public DDTracer.DDSpanBuilder withTag(String tag, Number number) { + return withTag(tag, (Object) number); + } - public DDTracer.DDSpanBuilder withServiceName(String serviceName) { - this.serviceName = serviceName; - return this; - } + public DDTracer.DDSpanBuilder withTag(String tag, String string) { + if (tag.equals(DDTags.SERVICE_NAME)) { + return withServiceName(string); + } else if (tag.equals(DDTags.RESOURCE_NAME)) { + return withResourceName(string); + } else if (tag.equals(DDTags.SPAN_TYPE)) { + return withSpanType(string); + } else { + return withTag(tag, (Object) string); + } + } - public DDTracer.DDSpanBuilder withResourceName(String resourceName) { - this.resourceName = resourceName; - return this; - } + public DDTracer.DDSpanBuilder withTag(String tag, boolean bool) { + return withTag(tag, (Object) bool); + } - public DDTracer.DDSpanBuilder withErrorFlag() { - this.errorFlag = true; - return this; - } + public DDSpanBuilder(String operationName) { + this.operationName = operationName; + } - public DDTracer.DDSpanBuilder withSpanType(String spanType) { - this.spanType = spanType; - return this; - } - public Iterable> baggageItems() { - if (parent == null) { - return Collections.emptyList(); - } - return parent.baggageItems(); - } + public DDTracer.DDSpanBuilder withStartTimestamp(long timestampMillis) { + this.timestamp = timestampMillis; + return this; + } - public DDTracer.DDSpanBuilder asChildOf(Span span) { - return asChildOf(span==null? null : span.context()); - } + public DDTracer.DDSpanBuilder withServiceName(String serviceName) { + this.serviceName = serviceName; + return this; + } - public DDTracer.DDSpanBuilder asChildOf(SpanContext spanContext) { - this.parent = spanContext; - return this; - } + public DDTracer.DDSpanBuilder withResourceName(String resourceName) { + this.resourceName = resourceName; + return this; + } - public DDTracer.DDSpanBuilder addReference(String referenceType, SpanContext spanContext) { - logger.debug("`addReference` method is not implemented. Doing nothing"); - return this; - } + public DDTracer.DDSpanBuilder withErrorFlag() { + this.errorFlag = true; + return this; + } - // Private methods - private DDTracer.DDSpanBuilder withTag(String tag, Object value) { - if (this.tags.isEmpty()) { - this.tags = new HashMap(); - } - this.tags.put(tag, value); - return this; - } + public DDTracer.DDSpanBuilder withSpanType(String spanType) { + this.spanType = spanType; + return this; + } - private long generateNewId() { - return System.nanoTime(); - } + public Iterable> baggageItems() { + if (parent == null) { + return Collections.emptyList(); + } + return parent.baggageItems(); + } - /** - * Build the SpanContext, if the actual span has a parent, the following attributes must be propagated: - * - ServiceName - * - Baggage - * - Trace (a list of all spans related) - * - SpanType - * - * @return the context - */ - private DDSpanContext buildSpanContext() { - long generatedId = generateNewId(); - DDSpanContext context; - DDSpanContext p = this.parent != null ? (DDSpanContext) this.parent : null; + public DDTracer.DDSpanBuilder asChildOf(Span span) { + return asChildOf(span == null ? null : span.context()); + } - String spanType = this.spanType; - if (spanType == null && this.parent != null) { - spanType = p.getSpanType(); - } + public DDTracer.DDSpanBuilder asChildOf(SpanContext spanContext) { + this.parent = spanContext; + return this; + } - String serviceName = this.serviceName; - if (serviceName == null) { - if (p != null && p.getServiceName() != null) { - serviceName = p.getServiceName(); - } else { - serviceName = defaultServiceName; - } - } - - String operationName = this.operationName != null ? this.operationName : this.resourceName; - - //this.operationName, this.tags, + public DDTracer.DDSpanBuilder addReference(String referenceType, SpanContext spanContext) { + logger.debug("`addReference` method is not implemented. Doing nothing"); + return this; + } - // some attributes are inherited from the parent - context = new DDSpanContext( - this.parent == null ? generatedId : p.getTraceId(), - generatedId, - this.parent == null ? 0L : p.getSpanId(), - serviceName, - operationName, - this.resourceName, - this.parent == null ? null : p.getBaggageItems(), - errorFlag, - spanType, - this.tags, - this.parent == null ? null : p.getTrace(), - DDTracer.this - ); + // Private methods + private DDTracer.DDSpanBuilder withTag(String tag, Object value) { + if (this.tags.isEmpty()) { + this.tags = new HashMap(); + } + this.tags.put(tag, value); + return this; + } - return context; - } + private long generateNewId() { + return System.nanoTime(); + } - } + /** + * Build the SpanContext, if the actual span has a parent, the following attributes must be propagated: + * - ServiceName + * - Baggage + * - Trace (a list of all spans related) + * - SpanType + * + * @return the context + */ + private DDSpanContext buildSpanContext() { + long generatedId = generateNewId(); + DDSpanContext context; + DDSpanContext p = this.parent != null ? (DDSpanContext) this.parent : null; - private static class CodecRegistry { + String spanType = this.spanType; + if (spanType == null && this.parent != null) { + spanType = p.getSpanType(); + } - private final Map, Codec> codecs = new HashMap, Codec>(); + String serviceName = this.serviceName; + if (serviceName == null) { + if (p != null && p.getServiceName() != null) { + serviceName = p.getServiceName(); + } else { + serviceName = defaultServiceName; + } + } - @SuppressWarnings("unchecked") + String operationName = this.operationName != null ? this.operationName : this.resourceName; + + //this.operationName, this.tags, + + // some attributes are inherited from the parent + context = new DDSpanContext( + this.parent == null ? generatedId : p.getTraceId(), + generatedId, + this.parent == null ? 0L : p.getSpanId(), + serviceName, + operationName, + this.resourceName, + this.parent == null ? null : p.getBaggageItems(), + errorFlag, + spanType, + this.tags, + this.parent == null ? null : p.getTrace(), + DDTracer.this + ); + + return context; + } + + } + + private String getHashKey(String tag) { + return tag; + } + + private static class CodecRegistry { + + private final Map, Codec> codecs = new HashMap, Codec>(); + + @SuppressWarnings("unchecked") Codec get(Format format) { - return (Codec) codecs.get(format); - } + return (Codec) codecs.get(format); + } - public void register(Format format, Codec codec) { - codecs.put(format, codec); - } + public void register(Format format, Codec codec) { + codecs.put(format, codec); + } - } + } - @Override - public String toString() { - return "DDTracer{" + - "writer=" + writer + - ", sampler=" + sampler + - '}'; - } + @Override + public String toString() { + return "DDTracer{" + + "writer=" + writer + + ", sampler=" + sampler + + '}'; + } } diff --git a/dd-trace/src/test/java/com/datadoghq/trace/resolver/TracerResolverTest.java b/dd-trace/src/test/java/com/datadoghq/trace/resolver/TracerResolverTest.java index efb1a23ebf..84023cfdf0 100644 --- a/dd-trace/src/test/java/com/datadoghq/trace/resolver/TracerResolverTest.java +++ b/dd-trace/src/test/java/com/datadoghq/trace/resolver/TracerResolverTest.java @@ -4,6 +4,7 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.List; +import io.opentracing.tag.Tags; import org.junit.Test; import com.datadoghq.trace.DDTracer; @@ -17,19 +18,23 @@ public class TracerResolverTest { public void test() { DDTracerResolver tracerResolver = new DDTracerResolver(); DDTracer tracer = (DDTracer) tracerResolver.resolve(); - - List decorators = tracer.getSpanContextDecorators(); - + + // for HTTP decorators + List decorators = tracer.getSpanContextDecorators(Tags.COMPONENT.getKey()); + assertThat(decorators.size()).isEqualTo(2); DDSpanContextDecorator decorator = decorators.get(0); assertThat(decorator.getClass()).isEqualTo(HTTPComponent.class); HTTPComponent httpServiceDecorator = (HTTPComponent) decorator; - assertThat(httpServiceDecorator.getMatchingTag()).isEqualTo("component"); assertThat(httpServiceDecorator.getMatchingValue()).isEqualTo("hello"); assertThat(httpServiceDecorator.getSetValue()).isEqualTo("world"); - - decorator = decorators.get(1); + + // for URL decorators + decorators = tracer.getSpanContextDecorators(Tags.HTTP_URL.getKey()); + assertThat(decorators.size()).isEqualTo(1); + + decorator = decorators.get(0); assertThat(decorator.getClass()).isEqualTo(URLAsResourceName.class); } diff --git a/dd-trace/src/test/resources/dd-trace-decorators.yaml b/dd-trace/src/test/resources/dd-trace-decorators.yaml index ff32f050ef..65adace662 100644 --- a/dd-trace/src/test/resources/dd-trace-decorators.yaml +++ b/dd-trace/src/test/resources/dd-trace-decorators.yaml @@ -2,4 +2,7 @@ decorators: - type: HTTPComponent matchingValue: hello setValue: world + - type: HTTPComponent + matchingValue: foo + setValue: bar - type: URLAsResourceName \ No newline at end of file From b1520363278255ef7a8135ea13cd1598727a3384 Mon Sep 17 00:00:00 2001 From: Guillaume Polaert Date: Mon, 29 May 2017 17:12:01 +0200 Subject: [PATCH 2/2] Updating decorators due the new behavior --- .../trace/integration/DBComponent.java | 11 ++++----- .../integration/DDSpanContextDecorator.java | 10 ++++---- .../trace/integration/HTTPComponent.java | 8 +++---- .../trace/integration/URLAsResourceName.java | 23 ++++++++----------- 4 files changed, 22 insertions(+), 30 deletions(-) diff --git a/dd-trace/src/main/java/com/datadoghq/trace/integration/DBComponent.java b/dd-trace/src/main/java/com/datadoghq/trace/integration/DBComponent.java index 0f3f66bd25..04040d9cd4 100644 --- a/dd-trace/src/main/java/com/datadoghq/trace/integration/DBComponent.java +++ b/dd-trace/src/main/java/com/datadoghq/trace/integration/DBComponent.java @@ -2,7 +2,6 @@ package com.datadoghq.trace.integration; import com.datadoghq.trace.DDSpanContext; import com.datadoghq.trace.DDTags; - import io.opentracing.tag.Tags; /** @@ -10,7 +9,7 @@ import io.opentracing.tag.Tags; * service name and retrieves some DB meta such as the statement */ public class DBComponent extends DDSpanContextDecorator { - + public DBComponent() { super(); this.setMatchingTag(Tags.COMPONENT.getKey()); @@ -20,14 +19,12 @@ public class DBComponent extends DDSpanContextDecorator { @Override public boolean afterSetTag(DDSpanContext context, String tag, Object value) { //Assign service name - if(super.afterSetTag(context, tag, value)){ + if (super.afterSetTag(context, tag, value)) { //Assign span type to DB context.setSpanType("db"); - + //Assign resource name - if(tag.equals(Tags.DB_STATEMENT.getKey())){ - context.setResourceName(String.valueOf(value)); - } + context.setResourceName(String.valueOf(value)); return true; } return false; diff --git a/dd-trace/src/main/java/com/datadoghq/trace/integration/DDSpanContextDecorator.java b/dd-trace/src/main/java/com/datadoghq/trace/integration/DDSpanContextDecorator.java index d8b7481e88..e46f5269e9 100644 --- a/dd-trace/src/main/java/com/datadoghq/trace/integration/DDSpanContextDecorator.java +++ b/dd-trace/src/main/java/com/datadoghq/trace/integration/DDSpanContextDecorator.java @@ -15,13 +15,13 @@ public abstract class DDSpanContextDecorator { private String setValue; - public boolean afterSetTag(DDSpanContext context, String tag, Object value){ - if(tag.equals(this.getMatchingTag()) && (this.getMatchingValue()==null || value.equals(this.getMatchingValue()))){ - String targetTag = getSetTag()==null?tag:getSetTag(); - String targetValue = getSetValue()==null?String.valueOf(value):getSetTag(); + public boolean afterSetTag(DDSpanContext context, String tag, Object value) { + if ((this.getMatchingValue() == null || value.equals(this.getMatchingValue()))) { + String targetTag = getSetTag() == null ? tag : getSetTag(); + String targetValue = getSetValue() == null ? String.valueOf(value) : getSetTag(); context.setTag(targetTag, targetValue); return true; - }else{ + } else { return false; } } diff --git a/dd-trace/src/main/java/com/datadoghq/trace/integration/HTTPComponent.java b/dd-trace/src/main/java/com/datadoghq/trace/integration/HTTPComponent.java index 6fa507054e..8371153747 100644 --- a/dd-trace/src/main/java/com/datadoghq/trace/integration/HTTPComponent.java +++ b/dd-trace/src/main/java/com/datadoghq/trace/integration/HTTPComponent.java @@ -2,7 +2,6 @@ package com.datadoghq.trace.integration; import com.datadoghq.trace.DDSpanContext; import com.datadoghq.trace.DDTags; - import io.opentracing.tag.Tags; @@ -11,7 +10,7 @@ import io.opentracing.tag.Tags; * service name and retrieves some HTTP meta such as the request path */ public class HTTPComponent extends DDSpanContextDecorator { - + public HTTPComponent() { super(); this.setMatchingTag(Tags.COMPONENT.getKey()); @@ -21,11 +20,12 @@ public class HTTPComponent extends DDSpanContextDecorator { @Override public boolean afterSetTag(DDSpanContext context, String tag, Object value) { //Assign service name - if(super.afterSetTag(context, tag, value)){ + if (super.afterSetTag(context, tag, value)) { + //Assign span type to WEB context.setSpanType("web"); return true; - }else{ + } else { return false; } } diff --git a/dd-trace/src/main/java/com/datadoghq/trace/integration/URLAsResourceName.java b/dd-trace/src/main/java/com/datadoghq/trace/integration/URLAsResourceName.java index 5efba3f686..d244abc1dc 100644 --- a/dd-trace/src/main/java/com/datadoghq/trace/integration/URLAsResourceName.java +++ b/dd-trace/src/main/java/com/datadoghq/trace/integration/URLAsResourceName.java @@ -1,14 +1,13 @@ package com.datadoghq.trace.integration; -import java.net.MalformedURLException; - import com.datadoghq.trace.DDSpanContext; import com.datadoghq.trace.DDTags; - import io.opentracing.tag.Tags; +import java.net.MalformedURLException; + public class URLAsResourceName extends DDSpanContextDecorator { - + public URLAsResourceName() { super(); this.setMatchingTag(Tags.HTTP_URL.getKey()); @@ -18,17 +17,13 @@ public class URLAsResourceName extends DDSpanContextDecorator { @Override public boolean afterSetTag(DDSpanContext context, String tag, Object value) { //Assign resource name - if(tag.equals(Tags.HTTP_URL.getKey())){ - try { - String path = new java.net.URL(String.valueOf(value)).getPath(); - context.setTag(this.getSetTag(),path); - } catch (MalformedURLException e) { - context.setResourceName(String.valueOf(value)); - } - return true; - }else{ - return false; + try { + String path = new java.net.URL(String.valueOf(value)).getPath(); + context.setTag(this.getSetTag(), path); + } catch (MalformedURLException e) { + context.setResourceName(String.valueOf(value)); } + return true; } }