Handle case where SQL is not saved in map properly.
Otherwise this could result in an NPE.
This commit is contained in:
parent
e21ed1052f
commit
f61935452b
|
@ -23,6 +23,7 @@ import net.bytebuddy.asm.Advice;
|
|||
|
||||
@AutoService(Instrumenter.class)
|
||||
public final class PreparedStatementInstrumentation implements Instrumenter {
|
||||
private static final String UNKNOWN_QUERY = "Unknown Query";
|
||||
|
||||
@Override
|
||||
public AgentBuilder instrument(final AgentBuilder agentBuilder) {
|
||||
|
@ -61,7 +62,7 @@ public final class PreparedStatementInstrumentation implements Instrumenter {
|
|||
Tags.COMPONENT.set(span, "java-jdbc-prepared_statement");
|
||||
|
||||
span.setTag(DDTags.SERVICE_NAME, dbInfo.getType());
|
||||
span.setTag(DDTags.RESOURCE_NAME, sql);
|
||||
span.setTag(DDTags.RESOURCE_NAME, sql == null ? UNKNOWN_QUERY : sql);
|
||||
span.setTag(DDTags.SPAN_TYPE, "sql");
|
||||
span.setTag("span.origin.type", statement.getClass().getName());
|
||||
span.setTag("db.jdbc.url", dbInfo.getUrl());
|
||||
|
|
|
@ -176,9 +176,13 @@ public class DDSpanContext implements io.opentracing.SpanContext {
|
|||
* Add a tag to the span. Tags are not propagated to the children
|
||||
*
|
||||
* @param tag the tag-name
|
||||
* @param value the value of the value
|
||||
* @param value the value of the tag. tags with null values are ignored.
|
||||
*/
|
||||
public synchronized void setTag(final String tag, final Object value) {
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (tag.equals(DDTags.SERVICE_NAME)) {
|
||||
setServiceName(value.toString());
|
||||
return;
|
||||
|
@ -210,14 +214,10 @@ public class DDSpanContext implements io.opentracing.SpanContext {
|
|||
}
|
||||
}
|
||||
// Error management
|
||||
if (Tags.ERROR.getKey().equals(tag) && Boolean.TRUE.equals(value)) {
|
||||
if (Tags.ERROR.getKey().equals(tag)
|
||||
&& Boolean.TRUE.equals(value instanceof String ? Boolean.valueOf((String) value) : value)) {
|
||||
this.errorFlag = true;
|
||||
}
|
||||
|
||||
// Remove null values
|
||||
if (value == null) {
|
||||
this.tags.remove(tag);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized Map<String, Object> getTags() {
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package com.datadoghq.trace
|
||||
|
||||
import spock.lang.Specification
|
||||
|
||||
class DDSpanContextTest extends Specification {
|
||||
|
||||
}
|
Loading…
Reference in New Issue