Move implementation of manual sampling via tag from span to decorators
MODIFY
dd-trace-api/src/main/java/datadog/trace/api/interceptor/MutableSpan.java
dd-trace-api/src/main/java/datadog/trace/api/interceptor/MutableSpan.java
@@ -25,7 +25,7 @@ public interface MutableSpan {
Integer getSamplingPriority();
/**
- * @deprecated Use {@link MutableSpan#setTag(String, boolean)} instead using either tag names
+ * @deprecated Use {@link io.opentracing.Span#setTag(String, boolean)} instead using either tag names
* {@link datadog.trace.api.sampling.ForcedTracing#manual_KEEP} or {@link
* datadog.trace.api.sampling.ForcedTracing#manual_DROP}.
* @param newPriority

MODIFY
dd-trace-ot/src/main/java/datadog/opentracing/DDSpanContext.java
dd-trace-ot/src/main/java/datadog/opentracing/DDSpanContext.java
@@ -203,13 +203,6 @@ public class DDSpanContext implements io.opentracing.SpanContext {
} else {
setMetric(PRIORITY_SAMPLING_KEY, newPriority);
log.debug("Set sampling priority to {}", getMetrics().get(PRIORITY_SAMPLING_KEY));
-
- // Keep in sync forced tracing tags with sampling priority
- if (newPriority == PrioritySampling.USER_KEEP) {
- tags.put(ForcedTracing.manual_KEEP, true);
- } else if (newPriority == PrioritySampling.USER_DROP) {
- tags.put(ForcedTracing.manual_DROP, true);
- }
}
}
}
@@ -321,15 +314,6 @@ public class DDSpanContext implements io.opentracing.SpanContext {
return;
}
- // For priority sampling we use tags ForcedTracing#manual_DROP and ForcedTracing#manual_KEEP as
- // vectors to set the respective priority sample values. A decorator is not a viable option to
- // achieve this as handles primarily tags and does not expose an API to perform more complex
- // operations. We may want to revisit this functionality, but for now we do it manually here.
- if (tag.equals(ForcedTracing.manual_KEEP) || tag.equals(ForcedTracing.manual_DROP)) {
- this.processForcedTracingTag(tag, value);
- return;
- }
-
boolean addTag = true;
// Call decorators

MODIFY
dd-trace-ot/src/main/java/datadog/opentracing/decorators/DDDecoratorsFactory.java
dd-trace-ot/src/main/java/datadog/opentracing/decorators/DDDecoratorsFactory.java
@@ -21,6 +21,9 @@ public class DDDecoratorsFactory {
new SpanTypeDecorator(),
new Status5XXDecorator(),
new Status404Decorator(),
- new URLAsResourceName());
+ new URLAsResourceName(),
+ new ForceManualKeepDecorator(),
+ new ForceManualDropDecorator()
+ );
}
}

ADD
dd-trace-ot/src/main/java/datadog/opentracing/decorators/ForceManualDropDecorator.java
+package datadog.opentracing.decorators;
+
+import datadog.opentracing.DDSpanContext;
+import datadog.trace.api.sampling.ForcedTracing;
+import datadog.trace.api.sampling.PrioritySampling;
+
+/**
+ * Tag decorator to replace tag 'manual.drop: true' with the appropriate priority sampling value.
+ */
+public class ForceManualDropDecorator extends AbstractDecorator {
+
+ public ForceManualDropDecorator() {
+ super();
+ setMatchingTag(ForcedTracing.manual_DROP);
+ }
+
+ @Override
+ public boolean shouldSetTag(final DDSpanContext context, final String tag, final Object value) {
+ if (value instanceof Boolean && (boolean)value) {
+ context.setSamplingPriority(PrioritySampling.USER_DROP);
+ }
+ return false;
+ }
+}

ADD
dd-trace-ot/src/main/java/datadog/opentracing/decorators/ForceManualKeepDecorator.java
+package datadog.opentracing.decorators;
+
+import datadog.opentracing.DDSpanContext;
+import datadog.trace.api.sampling.ForcedTracing;
+import datadog.trace.api.sampling.PrioritySampling;
+
+/**
+ * Tag decorator to replace tag 'manual.keep: true' with the appropriate priority sampling value.
+ */
+public class ForceManualKeepDecorator extends AbstractDecorator {
+
+ public ForceManualKeepDecorator() {
+ super();
+ setMatchingTag(ForcedTracing.manual_KEEP);
+ }
+
+ @Override
+ public boolean shouldSetTag(final DDSpanContext context, final String tag, final Object value) {
+ if (value instanceof Boolean && (boolean)value) {
+ context.setSamplingPriority(PrioritySampling.USER_KEEP);
+ }
+ return false;
+ }
+}

MODIFY
dd-trace-ot/src/test/groovy/datadog/opentracing/DDSpanTest.groovy
dd-trace-ot/src/test/groovy/datadog/opentracing/DDSpanTest.groovy
@@ -230,9 +230,7 @@ class DDSpanTest extends Specification {
}
expect:
- // Tag and sampling priority kept in sync
span.getSamplingPriority() == expectedPriority
- span.getTags()[tagName] == true
cleanup:
span.finish()
@@ -267,19 +265,4 @@ class DDSpanTest extends Specification {
'manual.drop' | 1
'manual.keep' | 1
}
-
- def "setting sampling priority via deprecated method keep tag in sync"() {
-
- setup:
- def span = tracer.buildSpan("root").start()
- span.samplingPriority = PrioritySampling.USER_KEEP
-
- expect:
- // Tag and sampling priority kept in sync
- span.getSamplingPriority() == PrioritySampling.USER_KEEP
- span.getTags()['manual.keep'] == true
-
- cleanup:
- span.finish()
- }
}

Move implementation of manual sampling via tag from span to decorators