Move ErrorFlag to TraceProcessor
This commit is contained in:
parent
97efa307d3
commit
2028b10009
|
@ -1,4 +1,3 @@
|
|||
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()
|
||||
|
|
|
@ -18,7 +18,6 @@ public class DDDecoratorsFactory {
|
|||
new AnalyticsSampleRateDecorator(),
|
||||
new DBStatementAsResourceName(),
|
||||
new DBTypeDecorator(),
|
||||
new ErrorFlag(),
|
||||
new ForceManualDropDecorator(),
|
||||
new ForceManualKeepDecorator(),
|
||||
new OperationDecorator(),
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
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
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue