Move ErrorFlag to TraceProcessor
MODIFY
dd-java-agent/instrumentation/trace-annotation/src/test/groovy/TraceAnnotationsTest.groovy
dd-java-agent/instrumentation/trace-annotation/src/test/groovy/TraceAnnotationsTest.groovy
-import datadog.opentracing.decorators.ErrorFlag
import datadog.trace.agent.test.AgentTestRunner
import datadog.trace.agent.test.utils.ConfigUtils
import datadog.trace.api.Trace
@@ -243,9 +242,6 @@ class TraceAnnotationsTest extends AgentTestRunner {
def "test exception exit"() {
setup:
-
- TEST_TRACER.addDecorator(new ErrorFlag())
-
Throwable error = null
try {
SayTracedHello.sayERROR()
@@ -272,9 +268,6 @@ class TraceAnnotationsTest extends AgentTestRunner {
def "test exception exit with resource name"() {
setup:
-
- TEST_TRACER.addDecorator(new ErrorFlag())
-
Throwable error = null
try {
SayTracedHello.sayERRORWithResource()

MODIFY
dd-trace-ot/src/main/java/datadog/opentracing/decorators/DDDecoratorsFactory.java
dd-trace-ot/src/main/java/datadog/opentracing/decorators/DDDecoratorsFactory.java
@@ -18,7 +18,6 @@ public class DDDecoratorsFactory {
new AnalyticsSampleRateDecorator(),
new DBStatementAsResourceName(),
new DBTypeDecorator(),
- new ErrorFlag(),
new ForceManualDropDecorator(),
new ForceManualKeepDecorator(),
new OperationDecorator(),

DELETE
dd-trace-ot/src/main/java/datadog/opentracing/decorators/ErrorFlag.java
-package datadog.opentracing.decorators;
-
-import datadog.opentracing.DDSpanContext;
-import io.opentracing.tag.Tags;
-
-public class ErrorFlag extends AbstractDecorator {
- public ErrorFlag() {
- super();
- setMatchingTag(Tags.ERROR.getKey());
- }
-
- @Override
- public boolean shouldSetTag(final DDSpanContext context, final String tag, final Object value) {
- // Assign resource name
- try {
- context.setErrorFlag(Boolean.parseBoolean(String.valueOf(value)));
- } catch (final Throwable t) {
- // DO NOTHING
- }
- return false;
- }
-}

MODIFY
dd-trace-ot/src/main/java/datadog/trace/common/processor/TraceProcessor.java
dd-trace-ot/src/main/java/datadog/trace/common/processor/TraceProcessor.java
@@ -2,6 +2,7 @@ package datadog.trace.common.processor;
import datadog.opentracing.DDSpan;
import datadog.trace.api.Config;
+import datadog.trace.common.processor.rule.ErrorRule;
import datadog.trace.common.processor.rule.Status404Rule;
import datadog.trace.common.processor.rule.Status5XXRule;
import datadog.trace.common.processor.rule.URLAsResourceNameRule;
@@ -16,7 +17,7 @@ public class TraceProcessor {
final Rule[] DEFAULT_RULES =
new Rule[] {
// Rules are applied in order.
- new Status5XXRule(), new URLAsResourceNameRule(), new Status404Rule(),
+ new Status5XXRule(), new ErrorRule(), new URLAsResourceNameRule(), new Status404Rule(),
};
private final List<Rule> rules;

ADD
dd-trace-ot/src/main/java/datadog/trace/common/processor/rule/ErrorRule.java
+package datadog.trace.common.processor.rule;
+
+import datadog.opentracing.DDSpan;
+import datadog.trace.common.processor.TraceProcessor;
+import io.opentracing.tag.Tags;
+import java.util.Collection;
+import java.util.Map;
+
+/** Converts error tag to error field */
+public class ErrorRule implements TraceProcessor.Rule {
+ @Override
+ public String[] aliases() {
+ return new String[] {"ErrorFlag"};
+ }
+
+ @Override
+ public void processSpan(
+ final DDSpan span, final Map<String, String> meta, final Collection<DDSpan> trace) {
+ if (meta.containsKey(Tags.ERROR.getKey())) {
+ span.setError(Boolean.parseBoolean(meta.get(Tags.ERROR.getKey())));
+ span.setTag(Tags.ERROR, null); // Remove the tag
+ }
+ }
+}

Move ErrorFlag to TraceProcessor