[sql] removing db.statement field so Agent can set sql.query tag
MODIFY
dd-trace/src/main/java/com/datadoghq/trace/DDSpanContext.java
dd-trace/src/main/java/com/datadoghq/trace/DDSpanContext.java
@@ -194,7 +194,7 @@ public class DDSpanContext implements io.opentracing.SpanContext {
//Call decorators
final List<AbstractDecorator> decorators = tracer.getSpanContextDecorators(tag);
- if (decorators != null) {
+ if (decorators != null && value != null) {
for (final AbstractDecorator decorator : decorators) {
try {
decorator.afterSetTag(this, tag, value);
@@ -210,6 +210,11 @@ public class DDSpanContext implements io.opentracing.SpanContext {
if (Tags.ERROR.getKey().equals(tag) && Boolean.TRUE.equals(value)) {
this.errorFlag = true;
}
+
+ // Remove null values
+ if (value == null) {
+ this.tags.remove(tag);
+ }
}
public synchronized Map<String, Object> getTags() {

MODIFY
dd-trace/src/main/java/com/datadoghq/trace/integration/DBStatementAsResourceName.java
dd-trace/src/main/java/com/datadoghq/trace/integration/DBStatementAsResourceName.java
@@ -14,10 +14,22 @@ public class DBStatementAsResourceName extends AbstractDecorator {
@Override
public boolean afterSetTag(final DDSpanContext context, final String tag, final Object value) {
+
+ // Special case: Mongo
+ // Skip the decorators
+ if (context.getTags().containsKey(Tags.COMPONENT.getKey())
+ && "java-mongo".equals(context.getTags().get(Tags.COMPONENT.getKey()))) {
+ return true;
+ }
+
//Assign service name
if (super.afterSetTag(context, tag, value)) {
- // Replace the OT db.statement by the DD sql.query
- context.setTag(DDTags.DB_STATEMENT, value);
+ // TODO: remove properly the tag (immutable at this time)
+ // the `db.statement` tag must be removed because it will be set
+ // by the Datadog Trace Agent as `sql.query`; here we're removing
+ // a duplicate that will not be obfuscated with the current Datadog
+ // Trace Agent version.
+ context.setTag(Tags.DB_STATEMENT.getKey(), null);
return true;
}
return false;

MODIFY
dd-trace/src/main/java/com/datadoghq/trace/integration/DBTypeDecorator.java
dd-trace/src/main/java/com/datadoghq/trace/integration/DBTypeDecorator.java
@@ -18,10 +18,16 @@ public class DBTypeDecorator extends AbstractDecorator {
@Override
public boolean afterSetTag(final DDSpanContext context, final String tag, final Object value) {
+
//Assign service name
if (super.afterSetTag(context, tag, value)) {
//Assign span type to DB
+ // Special case: Mongo, set to mongodb
+ if ("mongo".equals(value)) {
+ context.setSpanType("mongodb");
+ } else {
context.setSpanType("sql");
+ }
// Works for: mongo, cassandra, jdbc
context.setOperationName(String.valueOf(value) + ".query");
return true;

MODIFY
dd-trace/src/test/groovy/com/datadoghq/trace/integration/SpanDecoratorTest.groovy
dd-trace/src/test/groovy/com/datadoghq/trace/integration/SpanDecoratorTest.groovy
@@ -68,9 +68,45 @@ class SpanDecoratorTest extends Specification {
span.getOperationName() == type + ".query"
span.context().getSpanType() == "sql"
+
+ when:
+ Tags.DB_TYPE.set(span, "mongo")
+
+ then:
+ span.getOperationName() == "mongo.query"
+ span.context().getSpanType() == "mongodb"
+
+
where:
type = "foo"
}
+
+ def "DBStatementAsResource should not interact on Mongo queries"() {
+ setup:
+ def tracer = new DDTracer()
+ def span = SpanFactory.newSpanOf(tracer)
+ tracer.addDecorator(new DBStatementAsResourceName())
+
+ when:
+ span.setResourceName("not-change-me")
+ Tags.COMPONENT.set(span, "java-mongo")
+ Tags.DB_STATEMENT.set(span, something)
+
+ then:
+ span.getResourceName() == "not-change-me"
+
+
+ when:
+ span.setResourceName("change-me")
+ Tags.COMPONENT.set(span, "other-contrib")
+ Tags.DB_STATEMENT.set(span, something)
+
+ then:
+ span.getResourceName() == something
+
+ where:
+ something = "fake-query"
+ }
}

[sql] removing db.statement field so Agent can set sql.query tag