Update jdbc to new agent api
MODIFY
dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/JDBCDecorator.java
dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/JDBCDecorator.java
@@ -3,7 +3,7 @@ package datadog.trace.instrumentation.jdbc;
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 io.opentracing.tag.Tags;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
@@ -54,7 +54,7 @@ public class JDBCDecorator extends DatabaseClientDecorator<DBInfo> {
}
}
- public Span onConnection(final Span span, final Connection connection) {
+ public AgentSpan onConnection(final AgentSpan span, final Connection connection) {
DBInfo dbInfo = JDBCMaps.connectionInfo.get(connection);
/**
* Logic to get the DBInfo from a JDBC Connection, if the connection was not created via
@@ -81,25 +81,25 @@ public class JDBCDecorator extends DatabaseClientDecorator<DBInfo> {
}
if (dbInfo != null) {
- Tags.DB_TYPE.set(span, dbInfo.getType());
+ span.setTag(Tags.DB_TYPE.getKey(), dbInfo.getType());
span.setTag(DDTags.SERVICE_NAME, dbInfo.getType());
}
return super.onConnection(span, dbInfo);
}
@Override
- public Span onStatement(final Span span, final String statement) {
+ public AgentSpan onStatement(final AgentSpan span, final String statement) {
final String resourceName = statement == null ? DB_QUERY : statement;
span.setTag(DDTags.RESOURCE_NAME, resourceName);
- Tags.COMPONENT.set(span, "java-jdbc-statement");
+ span.setTag(Tags.COMPONENT.getKey(), "java-jdbc-statement");
return super.onStatement(span, statement);
}
- public Span onPreparedStatement(final Span span, final PreparedStatement statement) {
+ public AgentSpan onPreparedStatement(final AgentSpan span, final PreparedStatement statement) {
final String sql = JDBCMaps.preparedStatements.get(statement);
final String resourceName = sql == null ? DB_QUERY : sql;
span.setTag(DDTags.RESOURCE_NAME, resourceName);
- Tags.COMPONENT.set(span, "java-jdbc-prepared_statement");
+ span.setTag(Tags.COMPONENT.getKey(), "java-jdbc-prepared_statement");
return super.onStatement(span, sql);
}
}

MODIFY
dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/PreparedStatementInstrumentation.java
dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/PreparedStatementInstrumentation.java
package datadog.trace.instrumentation.jdbc;
import static datadog.trace.agent.tooling.ByteBuddyElementMatchers.safeHasSuperType;
+import static datadog.trace.instrumentation.api.AgentTracer.activateSpan;
+import static datadog.trace.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.instrumentation.jdbc.JDBCDecorator.DECORATE;
import static datadog.trace.instrumentation.jdbc.JDBCUtils.connectionFromStatement;
import static java.util.Collections.singletonMap;
@@ -14,10 +16,8 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.bootstrap.CallDepthThreadLocalMap;
-import io.opentracing.Scope;
-import io.opentracing.Span;
-import io.opentracing.noop.NoopScopeManager;
-import io.opentracing.util.GlobalTracer;
+import datadog.trace.instrumentation.api.AgentScope;
+import datadog.trace.instrumentation.api.AgentSpan;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.ArrayList;
@@ -71,7 +71,7 @@ public final class PreparedStatementInstrumentation extends Instrumenter.Default
public static class PreparedStatementAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
- public static Scope startSpan(@Advice.This final PreparedStatement statement) {
+ public static AgentScope onEnter(@Advice.This final PreparedStatement statement) {
final int callDepth = CallDepthThreadLocalMap.incrementCallDepth(PreparedStatement.class);
if (callDepth > 0) {
return null;
@@ -79,21 +79,20 @@ public final class PreparedStatementInstrumentation extends Instrumenter.Default
final Connection connection = connectionFromStatement(statement);
if (connection == null) {
- return NoopScopeManager.NoopScope.INSTANCE;
+ return null;
}
- final Scope scope = GlobalTracer.get().buildSpan("database.query").startActive(true);
- final Span span = scope.span();
+ final AgentSpan span = startSpan("database.query");
DECORATE.afterStart(span);
DECORATE.onConnection(span, connection);
DECORATE.onPreparedStatement(span, statement);
span.setTag("span.origin.type", statement.getClass().getName());
- return scope;
+ return activateSpan(span, true);
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void stopSpan(
- @Advice.Enter final Scope scope, @Advice.Thrown final Throwable throwable) {
+ @Advice.Enter final AgentScope scope, @Advice.Thrown final Throwable throwable) {
if (scope != null) {
DECORATE.onError(scope.span(), throwable);
DECORATE.beforeFinish(scope.span());

MODIFY
dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/StatementInstrumentation.java
dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/StatementInstrumentation.java
package datadog.trace.instrumentation.jdbc;
import static datadog.trace.agent.tooling.ByteBuddyElementMatchers.safeHasSuperType;
+import static datadog.trace.instrumentation.api.AgentTracer.activateSpan;
+import static datadog.trace.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.instrumentation.jdbc.JDBCDecorator.DECORATE;
import static datadog.trace.instrumentation.jdbc.JDBCUtils.connectionFromStatement;
import static java.util.Collections.singletonMap;
@@ -14,10 +16,8 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.bootstrap.CallDepthThreadLocalMap;
-import io.opentracing.Scope;
-import io.opentracing.Span;
-import io.opentracing.noop.NoopScopeManager;
-import io.opentracing.util.GlobalTracer;
+import datadog.trace.instrumentation.api.AgentScope;
+import datadog.trace.instrumentation.api.AgentSpan;
import java.sql.Connection;
import java.sql.Statement;
import java.util.ArrayList;
@@ -71,7 +71,7 @@ public final class StatementInstrumentation extends Instrumenter.Default {
public static class StatementAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
- public static Scope startSpan(
+ public static AgentScope onEnter(
@Advice.Argument(0) final String sql, @Advice.This final Statement statement) {
final int callDepth = CallDepthThreadLocalMap.incrementCallDepth(Statement.class);
if (callDepth > 0) {
@@ -80,21 +80,20 @@ public final class StatementInstrumentation extends Instrumenter.Default {
final Connection connection = connectionFromStatement(statement);
if (connection == null) {
- return NoopScopeManager.NoopScope.INSTANCE;
+ return null;
}
- final Scope scope = GlobalTracer.get().buildSpan("database.query").startActive(true);
- final Span span = scope.span();
+ final AgentSpan span = startSpan("database.query");
DECORATE.afterStart(span);
DECORATE.onConnection(span, connection);
DECORATE.onStatement(span, sql);
span.setTag("span.origin.type", statement.getClass().getName());
- return scope;
+ return activateSpan(span, true);
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void stopSpan(
- @Advice.Enter final Scope scope, @Advice.Thrown final Throwable throwable) {
+ @Advice.Enter final AgentScope scope, @Advice.Thrown final Throwable throwable) {
if (scope != null) {
DECORATE.onError(scope.span(), throwable);
DECORATE.beforeFinish(scope.span());

Update jdbc to new agent api