Merge pull request #216 from DataDog/tyler/error-object

Use Field.ERROR_OBJECT instead of string
This commit is contained in:
Tyler Benson 2018-02-07 12:17:52 +10:00 committed by GitHub
commit 103d7d7b64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 58 additions and 37 deletions

View File

@ -1,5 +1,7 @@
package datadog.trace.instrumentation.apachehttpclient;
import static io.opentracing.log.Fields.ERROR_OBJECT;
import datadog.trace.api.DDSpanTypes;
import datadog.trace.api.DDTags;
import io.opentracing.Scope;
@ -158,7 +160,7 @@ public class DDTracingClientExec implements ClientExecChain {
} catch (IOException | HttpException | RuntimeException e) {
// error tags
Tags.ERROR.set(networkSpan, Boolean.TRUE);
networkSpan.log(Collections.singletonMap("error.object", e));
networkSpan.log(Collections.singletonMap(ERROR_OBJECT, e));
throw e;
} finally {

View File

@ -1,5 +1,6 @@
package datadog.trace.instrumentation.jdbc;
import static io.opentracing.log.Fields.ERROR_OBJECT;
import static net.bytebuddy.matcher.ElementMatchers.hasSuperType;
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
@ -87,7 +88,7 @@ public final class PreparedStatementInstrumentation extends Instrumenter.Configu
if (throwable != null) {
final Span span = scope.span();
Tags.ERROR.set(span, true);
span.log(Collections.singletonMap("error.object", throwable));
span.log(Collections.singletonMap(ERROR_OBJECT, throwable));
}
scope.close();
}

View File

@ -1,5 +1,6 @@
package datadog.trace.instrumentation.jdbc;
import static io.opentracing.log.Fields.ERROR_OBJECT;
import static net.bytebuddy.matcher.ElementMatchers.hasSuperType;
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
@ -88,7 +89,7 @@ public final class StatementInstrumentation extends Instrumenter.Configurable {
if (throwable != null) {
final Span span = scope.span();
Tags.ERROR.set(span, true);
span.log(Collections.singletonMap("error.object", throwable));
span.log(Collections.singletonMap(ERROR_OBJECT, throwable));
}
scope.close();
}

View File

@ -2,6 +2,7 @@ package datadog.trace.instrumentation.jms1;
import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasClasses;
import static datadog.trace.instrumentation.jms.util.JmsUtil.toResourceName;
import static io.opentracing.log.Fields.ERROR_OBJECT;
import static net.bytebuddy.matcher.ElementMatchers.hasSuperType;
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
@ -90,7 +91,7 @@ public final class JMS1MessageConsumerInstrumentation extends Instrumenter.Confi
if (throwable != null) {
Tags.ERROR.set(span, Boolean.TRUE);
span.log(Collections.singletonMap("error.object", throwable));
span.log(Collections.singletonMap(ERROR_OBJECT, throwable));
}
span.setTag(DDTags.RESOURCE_NAME, "Consumed from " + toResourceName(message, null));
scope.close();

View File

@ -2,6 +2,7 @@ package datadog.trace.instrumentation.jms1;
import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasClasses;
import static datadog.trace.instrumentation.jms.util.JmsUtil.toResourceName;
import static io.opentracing.log.Fields.ERROR_OBJECT;
import static net.bytebuddy.matcher.ElementMatchers.hasSuperType;
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
@ -80,7 +81,7 @@ public final class JMS1MessageListenerInstrumentation extends Instrumenter.Confi
if (throwable != null) {
final Span span = scope.span();
Tags.ERROR.set(span, Boolean.TRUE);
span.log(Collections.singletonMap("error.object", throwable));
span.log(Collections.singletonMap(ERROR_OBJECT, throwable));
}
scope.close();
}

View File

@ -2,6 +2,7 @@ package datadog.trace.instrumentation.jms1;
import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasClasses;
import static datadog.trace.instrumentation.jms.util.JmsUtil.toResourceName;
import static io.opentracing.log.Fields.ERROR_OBJECT;
import static net.bytebuddy.matcher.ElementMatchers.hasSuperType;
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
@ -95,7 +96,7 @@ public final class JMS1MessageProducerInstrumentation extends Instrumenter.Confi
if (throwable != null) {
final Span span = scope.span();
Tags.ERROR.set(span, Boolean.TRUE);
span.log(Collections.singletonMap("error.object", throwable));
span.log(Collections.singletonMap(ERROR_OBJECT, throwable));
}
scope.close();
}
@ -135,7 +136,7 @@ public final class JMS1MessageProducerInstrumentation extends Instrumenter.Confi
if (throwable != null) {
final Span span = scope.span();
Tags.ERROR.set(span, Boolean.TRUE);
span.log(Collections.singletonMap("error.object", throwable));
span.log(Collections.singletonMap(ERROR_OBJECT, throwable));
}
scope.close();
}

View File

@ -2,6 +2,7 @@ package datadog.trace.instrumentation.jms2;
import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasClasses;
import static datadog.trace.instrumentation.jms.util.JmsUtil.toResourceName;
import static io.opentracing.log.Fields.ERROR_OBJECT;
import static net.bytebuddy.matcher.ElementMatchers.hasSuperType;
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
@ -91,7 +92,7 @@ public final class JMS2MessageConsumerInstrumentation extends Instrumenter.Confi
if (throwable != null) {
Tags.ERROR.set(span, Boolean.TRUE);
span.log(Collections.singletonMap("error.object", throwable));
span.log(Collections.singletonMap(ERROR_OBJECT, throwable));
}
span.setTag(DDTags.RESOURCE_NAME, "Consumed from " + toResourceName(message, null));
scope.close();

View File

@ -2,6 +2,7 @@ package datadog.trace.instrumentation.jms2;
import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasClasses;
import static datadog.trace.instrumentation.jms.util.JmsUtil.toResourceName;
import static io.opentracing.log.Fields.ERROR_OBJECT;
import static net.bytebuddy.matcher.ElementMatchers.hasSuperType;
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
@ -80,7 +81,7 @@ public final class JMS2MessageListenerInstrumentation extends Instrumenter.Confi
if (throwable != null) {
final Span span = scope.span();
Tags.ERROR.set(span, Boolean.TRUE);
span.log(Collections.singletonMap("error.object", throwable));
span.log(Collections.singletonMap(ERROR_OBJECT, throwable));
}
scope.close();
}

View File

@ -2,6 +2,7 @@ package datadog.trace.instrumentation.jms2;
import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasClasses;
import static datadog.trace.instrumentation.jms.util.JmsUtil.toResourceName;
import static io.opentracing.log.Fields.ERROR_OBJECT;
import static net.bytebuddy.matcher.ElementMatchers.hasSuperType;
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
@ -95,7 +96,7 @@ public final class JMS2MessageProducerInstrumentation extends Instrumenter.Confi
if (throwable != null) {
final Span span = scope.span();
Tags.ERROR.set(span, Boolean.TRUE);
span.log(Collections.singletonMap("error.object", throwable));
span.log(Collections.singletonMap(ERROR_OBJECT, throwable));
}
scope.close();
}
@ -134,7 +135,7 @@ public final class JMS2MessageProducerInstrumentation extends Instrumenter.Confi
if (throwable != null) {
final Span span = scope.span();
Tags.ERROR.set(span, Boolean.TRUE);
span.log(Collections.singletonMap("error.object", throwable));
span.log(Collections.singletonMap(ERROR_OBJECT, throwable));
}
scope.close();
}

View File

@ -1,6 +1,7 @@
package datadog.trace.instrumentation.kafka_clients;
import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasClasses;
import static io.opentracing.log.Fields.ERROR_OBJECT;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
import static net.bytebuddy.matcher.ElementMatchers.named;
@ -120,7 +121,7 @@ public final class KafkaProducerInstrumentation extends Instrumenter.Configurabl
if (throwable != null) {
final Span span = scope.span();
Tags.ERROR.set(span, true);
span.log(Collections.singletonMap("error.object", throwable));
span.log(Collections.singletonMap(ERROR_OBJECT, throwable));
span.finish();
}
scope.close();
@ -140,7 +141,7 @@ public final class KafkaProducerInstrumentation extends Instrumenter.Configurabl
public void onCompletion(final RecordMetadata metadata, final Exception exception) {
if (exception != null) {
Tags.ERROR.set(scope.span(), Boolean.TRUE);
scope.span().log(Collections.singletonMap("error.object", exception));
scope.span().log(Collections.singletonMap(ERROR_OBJECT, exception));
}
try {
if (callback != null) {

View File

@ -1,6 +1,7 @@
package datadog.trace.instrumentation.kafka_streams;
import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasClasses;
import static io.opentracing.log.Fields.ERROR_OBJECT;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.isPackagePrivate;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
@ -134,7 +135,7 @@ public class KafkaStreamsProcessorInstrumentation {
if (throwable != null) {
final Span span = scope.span();
Tags.ERROR.set(span, Boolean.TRUE);
span.log(Collections.singletonMap("error.object", throwable));
span.log(Collections.singletonMap(ERROR_OBJECT, throwable));
}
scope.close();
}

View File

@ -1,5 +1,7 @@
package datadog.trace.instrumentation.mongo;
import static io.opentracing.log.Fields.ERROR_OBJECT;
import com.mongodb.event.CommandFailedEvent;
import com.mongodb.event.CommandListener;
import com.mongodb.event.CommandStartedEvent;
@ -39,36 +41,36 @@ public class DDTracingCommandListener implements CommandListener {
/** requestID -> span */
private final Map<Integer, Span> cache = new ConcurrentHashMap<>();
public DDTracingCommandListener(Tracer tracer) {
public DDTracingCommandListener(final Tracer tracer) {
this.tracer = tracer;
}
@Override
public void commandStarted(CommandStartedEvent event) {
Span span = buildSpan(event);
public void commandStarted(final CommandStartedEvent event) {
final Span span = buildSpan(event);
cache.put(event.getRequestId(), span);
}
@Override
public void commandSucceeded(CommandSucceededEvent event) {
Span span = cache.remove(event.getRequestId());
public void commandSucceeded(final CommandSucceededEvent event) {
final Span span = cache.remove(event.getRequestId());
if (span != null) {
span.finish();
}
}
@Override
public void commandFailed(CommandFailedEvent event) {
Span span = cache.remove(event.getRequestId());
public void commandFailed(final CommandFailedEvent event) {
final Span span = cache.remove(event.getRequestId());
if (span != null) {
Tags.ERROR.set(span, Boolean.TRUE);
span.log(Collections.singletonMap("error.object", event.getThrowable()));
span.log(Collections.singletonMap(ERROR_OBJECT, event.getThrowable()));
span.finish();
}
}
private Span buildSpan(CommandStartedEvent event) {
Tracer.SpanBuilder spanBuilder =
private Span buildSpan(final CommandStartedEvent event) {
final Tracer.SpanBuilder spanBuilder =
tracer.buildSpan(MONGO_OPERATION).withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT);
final Span span = spanBuilder.startManual();
@ -81,7 +83,7 @@ public class DDTracingCommandListener implements CommandListener {
return span;
}
public static void decorate(Span span, CommandStartedEvent event) {
public static void decorate(final Span span, final CommandStartedEvent event) {
// scrub the Mongo command so that parameters are removed from the string
final BsonDocument scrubbed = scrub(event.getCommand());
final String mongoCmd = scrubbed.toString();
@ -92,7 +94,7 @@ public class DDTracingCommandListener implements CommandListener {
Tags.PEER_HOSTNAME.set(span, event.getConnectionDescription().getServerAddress().getHost());
InetAddress inetAddress =
final InetAddress inetAddress =
event.getConnectionDescription().getServerAddress().getSocketAddress().getAddress();
if (inetAddress instanceof Inet4Address) {
Tags.PEER_HOST_IPV4.set(span, inetAddress.getHostAddress());

View File

@ -1,6 +1,7 @@
package datadog.trace.instrumentation.servlet2;
import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasClasses;
import static io.opentracing.log.Fields.ERROR_OBJECT;
import static net.bytebuddy.matcher.ElementMatchers.hasSuperType;
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
@ -109,7 +110,7 @@ public final class FilterChain2Instrumentation extends Instrumenter.Configurable
if (throwable != null) {
ServletFilterSpanDecorator.STANDARD_TAGS.onError(req, resp, throwable, span);
span.log(Collections.singletonMap("error.object", throwable));
span.log(Collections.singletonMap(ERROR_OBJECT, throwable));
} else {
ServletFilterSpanDecorator.STANDARD_TAGS.onResponse(req, resp, span);
}

View File

@ -1,6 +1,7 @@
package datadog.trace.instrumentation.servlet2;
import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasClasses;
import static io.opentracing.log.Fields.ERROR_OBJECT;
import static net.bytebuddy.matcher.ElementMatchers.hasSuperType;
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
import static net.bytebuddy.matcher.ElementMatchers.isProtected;
@ -109,7 +110,7 @@ public final class HttpServlet2Instrumentation extends Instrumenter.Configurable
if (throwable != null) {
ServletFilterSpanDecorator.STANDARD_TAGS.onError(req, resp, throwable, span);
span.log(Collections.singletonMap("error.object", throwable));
span.log(Collections.singletonMap(ERROR_OBJECT, throwable));
} else {
ServletFilterSpanDecorator.STANDARD_TAGS.onResponse(req, resp, span);
}

View File

@ -1,6 +1,7 @@
package datadog.trace.instrumentation.servlet3;
import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasClasses;
import static io.opentracing.log.Fields.ERROR_OBJECT;
import static net.bytebuddy.matcher.ElementMatchers.hasSuperType;
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
@ -110,7 +111,7 @@ public final class FilterChain3Instrumentation extends Instrumenter.Configurable
if (throwable != null) {
ServletFilterSpanDecorator.STANDARD_TAGS.onError(req, resp, throwable, span);
span.log(Collections.singletonMap("error.object", throwable));
span.log(Collections.singletonMap(ERROR_OBJECT, throwable));
scope.close();
scope.span().finish(); // Finish the span manually since finishSpanOnClose was false
} else if (req.isAsyncStarted()) {
@ -169,7 +170,7 @@ public final class FilterChain3Instrumentation extends Instrumenter.Configurable
(HttpServletResponse) event.getSuppliedResponse(),
event.getThrowable(),
span);
span.log(Collections.singletonMap("error.object", event.getThrowable()));
span.log(Collections.singletonMap(ERROR_OBJECT, event.getThrowable()));
}
}
}

View File

@ -1,6 +1,7 @@
package datadog.trace.instrumentation.servlet3;
import static datadog.trace.agent.tooling.ClassLoaderMatcher.classLoaderHasClasses;
import static io.opentracing.log.Fields.ERROR_OBJECT;
import static net.bytebuddy.matcher.ElementMatchers.hasSuperType;
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
import static net.bytebuddy.matcher.ElementMatchers.isProtected;
@ -102,7 +103,7 @@ public final class HttpServlet3Instrumentation extends Instrumenter.Configurable
final Span span = scope.span();
if (throwable != null) {
ServletFilterSpanDecorator.STANDARD_TAGS.onError(req, resp, throwable, span);
span.log(Collections.singletonMap("error.object", throwable));
span.log(Collections.singletonMap(ERROR_OBJECT, throwable));
scope.close();
scope.span().finish(); // Finish the span manually since finishSpanOnClose was false
} else if (req.isAsyncStarted()) {
@ -160,7 +161,7 @@ public final class HttpServlet3Instrumentation extends Instrumenter.Configurable
(HttpServletResponse) event.getSuppliedResponse(),
event.getThrowable(),
span);
span.log(Collections.singletonMap("error.object", event.getThrowable()));
span.log(Collections.singletonMap(ERROR_OBJECT, event.getThrowable()));
}
}
}

View File

@ -1,5 +1,6 @@
package datadog.trace.instrumentation.trace_annotation;
import static io.opentracing.log.Fields.ERROR_OBJECT;
import static net.bytebuddy.matcher.ElementMatchers.declaresMethod;
import static net.bytebuddy.matcher.ElementMatchers.hasSuperType;
import static net.bytebuddy.matcher.ElementMatchers.isAnnotatedWith;
@ -52,7 +53,7 @@ public final class TraceAnnotationInstrumentation extends Instrumenter.Configura
if (throwable != null) {
final Span span = scope.span();
Tags.ERROR.set(span, true);
span.log(Collections.singletonMap("error.object", throwable));
span.log(Collections.singletonMap(ERROR_OBJECT, throwable));
}
scope.close();
}

View File

@ -125,7 +125,7 @@ Errors are manually captured in a span by setting the error flag and logging the
// capture error
ActiveSpan span = GlobalTracer.get().activeSpan();
Tags.ERROR.set(span, Boolean.TRUE);
span.log(Collections.singletonMap("error.object", e));
span.log(Collections.singletonMap(io.opentracing.log.Fields.ERROR_OBJECT, e));
// recovery code
}

View File

@ -1,5 +1,7 @@
package datadog.opentracing;
import static io.opentracing.log.Fields.ERROR_OBJECT;
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
@ -121,8 +123,8 @@ public class DDSpan implements Span {
}
private boolean extractError(final Map<String, ?> map) {
if (map.get("error.object") instanceof Throwable) {
final Throwable error = (Throwable) map.get("error.object");
if (map.get(ERROR_OBJECT) instanceof Throwable) {
final Throwable error = (Throwable) map.get(ERROR_OBJECT);
setErrorMeta(error);
return true;
}
@ -245,7 +247,7 @@ public class DDSpan implements Span {
*
* <p>Has no effect if the span priority has been propagated (injected or extracted).
*/
public final DDSpan setSamplingPriority(int newPriority) {
public final DDSpan setSamplingPriority(final int newPriority) {
this.context().setSamplingPriority(newPriority);
return this;
}