Update hibernate to new agent api
MODIFY
dd-java-agent/instrumentation/hibernate/core-3.3/src/main/java/datadog/trace/instrumentation/hibernate/core/v3_3/SessionFactoryInstrumentation.java
dd-java-agent/instrumentation/hibernate/core-3.3/src/main/java/datadog/trace/instrumentation/hibernate/core/v3_3/SessionFactoryInstrumentation.java
package datadog.trace.instrumentation.hibernate.core.v3_3;
import static datadog.trace.agent.tooling.ByteBuddyElementMatchers.safeHasSuperType;
+import static datadog.trace.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.instrumentation.hibernate.HibernateDecorator.DECORATOR;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
@@ -14,9 +15,8 @@ import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.bootstrap.ContextStore;
import datadog.trace.bootstrap.InstrumentationContext;
+import datadog.trace.instrumentation.api.AgentSpan;
import datadog.trace.instrumentation.hibernate.SessionState;
-import io.opentracing.Span;
-import io.opentracing.util.GlobalTracer;
import java.util.HashMap;
import java.util.Map;
import net.bytebuddy.asm.Advice;
@@ -62,7 +62,7 @@ public class SessionFactoryInstrumentation extends AbstractHibernateInstrumentat
@Advice.OnMethodExit(suppress = Throwable.class)
public static void openSession(@Advice.Return final Object session) {
- final Span span = GlobalTracer.get().buildSpan("hibernate.session").start();
+ final AgentSpan span = startSpan("hibernate.session");
DECORATOR.afterStart(span);
DECORATOR.onConnection(span, session);

MODIFY
dd-java-agent/instrumentation/hibernate/core-3.3/src/main/java/datadog/trace/instrumentation/hibernate/core/v3_3/SessionInstrumentation.java
dd-java-agent/instrumentation/hibernate/core-3.3/src/main/java/datadog/trace/instrumentation/hibernate/core/v3_3/SessionInstrumentation.java
@@ -15,9 +15,9 @@ import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.bootstrap.ContextStore;
import datadog.trace.bootstrap.InstrumentationContext;
+import datadog.trace.instrumentation.api.AgentSpan;
import datadog.trace.instrumentation.hibernate.SessionMethodUtils;
import datadog.trace.instrumentation.hibernate.SessionState;
-import io.opentracing.Span;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -131,7 +131,7 @@ public class SessionInstrumentation extends AbstractHibernateInstrumentation {
state.getMethodScope().close();
}
- final Span span = state.getSessionSpan();
+ final AgentSpan span = state.getSessionSpan();
DECORATOR.onError(span, throwable);
DECORATOR.beforeFinish(span);
span.finish();

MODIFY
dd-java-agent/instrumentation/hibernate/core-4.0/src/main/java/datadog/trace/instrumentation/hibernate/core/v4_0/SessionFactoryInstrumentation.java
dd-java-agent/instrumentation/hibernate/core-4.0/src/main/java/datadog/trace/instrumentation/hibernate/core/v4_0/SessionFactoryInstrumentation.java
package datadog.trace.instrumentation.hibernate.core.v4_0;
import static datadog.trace.agent.tooling.ByteBuddyElementMatchers.safeHasSuperType;
+import static datadog.trace.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.instrumentation.hibernate.HibernateDecorator.DECORATOR;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
@@ -14,9 +15,8 @@ import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.bootstrap.ContextStore;
import datadog.trace.bootstrap.InstrumentationContext;
+import datadog.trace.instrumentation.api.AgentSpan;
import datadog.trace.instrumentation.hibernate.SessionState;
-import io.opentracing.Span;
-import io.opentracing.util.GlobalTracer;
import java.util.Map;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
@@ -54,7 +54,7 @@ public class SessionFactoryInstrumentation extends AbstractHibernateInstrumentat
@Advice.OnMethodExit(suppress = Throwable.class)
public static void openSession(@Advice.Return final SharedSessionContract session) {
- final Span span = GlobalTracer.get().buildSpan("hibernate.session").start();
+ final AgentSpan span = startSpan("hibernate.session");
DECORATOR.afterStart(span);
DECORATOR.onConnection(span, session);

MODIFY
dd-java-agent/instrumentation/hibernate/core-4.0/src/main/java/datadog/trace/instrumentation/hibernate/core/v4_0/SessionInstrumentation.java
dd-java-agent/instrumentation/hibernate/core-4.0/src/main/java/datadog/trace/instrumentation/hibernate/core/v4_0/SessionInstrumentation.java
@@ -15,9 +15,9 @@ import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.bootstrap.ContextStore;
import datadog.trace.bootstrap.InstrumentationContext;
+import datadog.trace.instrumentation.api.AgentSpan;
import datadog.trace.instrumentation.hibernate.SessionMethodUtils;
import datadog.trace.instrumentation.hibernate.SessionState;
-import io.opentracing.Span;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -119,7 +119,7 @@ public class SessionInstrumentation extends AbstractHibernateInstrumentation {
state.getMethodScope().close();
}
- final Span span = state.getSessionSpan();
+ final AgentSpan span = state.getSessionSpan();
DECORATOR.onError(span, throwable);
DECORATOR.beforeFinish(span);
span.finish();

MODIFY
dd-java-agent/instrumentation/hibernate/src/main/java/datadog/trace/instrumentation/hibernate/SessionMethodUtils.java
dd-java-agent/instrumentation/hibernate/src/main/java/datadog/trace/instrumentation/hibernate/SessionMethodUtils.java
package datadog.trace.instrumentation.hibernate;
+import static datadog.trace.instrumentation.api.AgentTracer.activateSpan;
+import static datadog.trace.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.instrumentation.hibernate.HibernateDecorator.DECORATOR;
import datadog.trace.bootstrap.CallDepthThreadLocalMap;
import datadog.trace.bootstrap.ContextStore;
-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.Arrays;
import java.util.HashSet;
import java.util.Set;
@@ -36,17 +37,14 @@ public class SessionMethodUtils {
return null; // This method call is being traced already.
}
- final Scope scope;
+ final AgentScope scope;
if (createSpan) {
- scope =
- GlobalTracer.get()
- .buildSpan(operationName)
- .asChildOf(sessionState.getSessionSpan())
- .startActive(true);
- DECORATOR.afterStart(scope.span());
- DECORATOR.onOperation(scope.span(), entity);
+ final AgentSpan span = startSpan(operationName, sessionState.getSessionSpan().context());
+ DECORATOR.afterStart(span);
+ DECORATOR.onOperation(span, entity);
+ scope = activateSpan(span, true);
} else {
- scope = GlobalTracer.get().scopeManager().activate(sessionState.getSessionSpan(), false);
+ scope = activateSpan(sessionState.getSessionSpan(), false);
sessionState.setHasChildSpan(false);
}
@@ -65,8 +63,8 @@ public class SessionMethodUtils {
}
CallDepthThreadLocalMap.reset(SessionMethodUtils.class);
- final Scope scope = sessionState.getMethodScope();
- final Span span = scope.span();
+ final AgentScope scope = sessionState.getMethodScope();
+ final AgentSpan span = scope.span();
if (span != null && sessionState.hasChildSpan) {
DECORATOR.onError(span, throwable);
if (entity != null) {

MODIFY
dd-java-agent/instrumentation/hibernate/src/main/java/datadog/trace/instrumentation/hibernate/SessionState.java
dd-java-agent/instrumentation/hibernate/src/main/java/datadog/trace/instrumentation/hibernate/SessionState.java
package datadog.trace.instrumentation.hibernate;
-import io.opentracing.Scope;
-import io.opentracing.Span;
+import datadog.trace.instrumentation.api.AgentScope;
+import datadog.trace.instrumentation.api.AgentSpan;
import lombok.Data;
import lombok.NonNull;
@Data
public class SessionState {
- @NonNull public Span sessionSpan;
- public Scope methodScope;
+ @NonNull public AgentSpan sessionSpan;
+ public AgentScope methodScope;
public boolean hasChildSpan = true;
}

Update hibernate to new agent api