Update mongo to new agent api
MODIFY
dd-java-agent/instrumentation/mongo/driver-3.1/src/main/java/datadog/trace/instrumentation/mongo/MongoClientDecorator.java
dd-java-agent/instrumentation/mongo/driver-3.1/src/main/java/datadog/trace/instrumentation/mongo/MongoClientDecorator.java
@@ -8,7 +8,7 @@ import com.mongodb.event.CommandStartedEvent;
import datadog.trace.agent.decorator.DatabaseClientDecorator;
import datadog.trace.api.DDSpanTypes;
import datadog.trace.api.DDTags;
-import io.opentracing.Span;
+import datadog.trace.instrumentation.api.AgentSpan;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@@ -59,9 +59,9 @@ public class MongoClientDecorator extends DatabaseClientDecorator<CommandStarted
if (connectionId != null) {
final ServerId serverId = connectionId.getServerId();
if (serverId != null) {
- ClusterId clusterId = serverId.getClusterId();
+ final ClusterId clusterId = serverId.getClusterId();
if (clusterId != null) {
- String description = clusterId.getDescription();
+ final String description = clusterId.getDescription();
if (description != null) {
return description;
}
@@ -73,7 +73,7 @@ public class MongoClientDecorator extends DatabaseClientDecorator<CommandStarted
return event.getDatabaseName();
}
- public Span onStatement(final Span span, final BsonDocument statement) {
+ public AgentSpan onStatement(final AgentSpan span, final BsonDocument statement) {
// scrub the Mongo command so that parameters are removed from the string
final BsonDocument scrubbed = scrub(statement);

MODIFY
dd-java-agent/instrumentation/mongo/driver-3.1/src/main/java/datadog/trace/instrumentation/mongo/TracingCommandListener.java
dd-java-agent/instrumentation/mongo/driver-3.1/src/main/java/datadog/trace/instrumentation/mongo/TracingCommandListener.java
package datadog.trace.instrumentation.mongo;
+import static datadog.trace.instrumentation.api.AgentTracer.activateSpan;
+import static datadog.trace.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.instrumentation.mongo.MongoClientDecorator.DECORATE;
import com.mongodb.event.CommandFailedEvent;
import com.mongodb.event.CommandListener;
import com.mongodb.event.CommandStartedEvent;
import com.mongodb.event.CommandSucceededEvent;
-import io.opentracing.Scope;
-import io.opentracing.Span;
-import io.opentracing.util.GlobalTracer;
+import datadog.trace.instrumentation.api.AgentScope;
+import datadog.trace.instrumentation.api.AgentSpan;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import lombok.extern.slf4j.Slf4j;
@@ -16,12 +17,12 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class TracingCommandListener implements CommandListener {
- private final Map<Integer, Span> spanMap = new ConcurrentHashMap<>();
+ private final Map<Integer, AgentSpan> spanMap = new ConcurrentHashMap<>();
@Override
public void commandStarted(final CommandStartedEvent event) {
- final Span span = GlobalTracer.get().buildSpan("mongo.query").start();
- try (final Scope scope = GlobalTracer.get().scopeManager().activate(span, false)) {
+ final AgentSpan span = startSpan("mongo.query");
+ try (final AgentScope scope = activateSpan(span, false)) {
DECORATE.afterStart(span);
DECORATE.onConnection(span, event);
if (event.getConnectionDescription() != null
@@ -37,7 +38,7 @@ public class TracingCommandListener implements CommandListener {
@Override
public void commandSucceeded(final CommandSucceededEvent event) {
- final Span span = spanMap.remove(event.getRequestId());
+ final AgentSpan span = spanMap.remove(event.getRequestId());
if (span != null) {
DECORATE.beforeFinish(span);
span.finish();
@@ -46,7 +47,7 @@ public class TracingCommandListener implements CommandListener {
@Override
public void commandFailed(final CommandFailedEvent event) {
- final Span span = spanMap.remove(event.getRequestId());
+ final AgentSpan span = spanMap.remove(event.getRequestId());
if (span != null) {
DECORATE.onError(span, event.getThrowable());
DECORATE.beforeFinish(span);

Update mongo to new agent api