Use a Dectorator for the Hibernate instrumentation
ADD
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/decorator/OrmClientDecorator.java
+package datadog.trace.agent.decorator;
+
+import datadog.trace.api.DDTags;
+import io.opentracing.Span;
+
+public abstract class OrmClientDecorator extends DatabaseClientDecorator {
+
+ public abstract <ENTITY> String entityName(final ENTITY entity);
+
+ public <ENTITY> Span onOperation(final Span span, final ENTITY entity) {
+
+ assert span != null;
+ if (entity != null) {
+ final String name = entityName(entity);
+ if (name != null) {
+ span.setTag(DDTags.RESOURCE_NAME, name);
+ } // else we keep any existing resource.
+ }
+ return span;
+ }
+}

MODIFY
dd-java-agent/instrumentation/hibernate/src/main/java/datadog/trace/instrumentation/hibernate/CriteriaInstrumentation.java
dd-java-agent/instrumentation/hibernate/src/main/java/datadog/trace/instrumentation/hibernate/CriteriaInstrumentation.java
@@ -16,6 +16,7 @@ import java.util.Map;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
+import net.bytebuddy.implementation.bytecode.assign.Assigner;
import net.bytebuddy.matcher.ElementMatcher;
import org.hibernate.Criteria;
@@ -66,16 +67,17 @@ public class CriteriaInstrumentation extends Instrumenter.Default {
InstrumentationContext.get(Criteria.class, SessionState.class);
return SessionMethodUtils.startScopeFrom(
- contextStore, criteria, "hibernate.criteria." + name);
+ contextStore, criteria, "hibernate.criteria." + name, null);
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void endMethod(
@Advice.This final Criteria criteria,
@Advice.Enter final SessionState state,
- @Advice.Thrown final Throwable throwable) {
+ @Advice.Thrown final Throwable throwable,
+ @Advice.Return(typing = Assigner.Typing.DYNAMIC) final Object entity) {
- SessionMethodUtils.closeScope(state, throwable);
+ SessionMethodUtils.closeScope(state, throwable, entity);
}
}
}

ADD
dd-java-agent/instrumentation/hibernate/src/main/java/datadog/trace/instrumentation/hibernate/HibernateDecorator.java
+package datadog.trace.instrumentation.hibernate;
+
+import datadog.trace.agent.decorator.OrmClientDecorator;
+import datadog.trace.api.DDSpanTypes;
+import java.util.List;
+import javax.persistence.Entity;
+
+public class HibernateDecorator extends OrmClientDecorator {
+ public static final HibernateDecorator INSTANCE = new HibernateDecorator();
+
+ @Override
+ protected String service() {
+ return "hibernate";
+ }
+
+ @Override
+ protected String[] instrumentationNames() {
+ return new String[] {"hibernate"};
+ }
+
+ @Override
+ protected String spanType() {
+ return DDSpanTypes.HIBERNATE;
+ }
+
+ @Override
+ protected String component() {
+ return "java-hibernate";
+ }
+
+ @Override
+ protected String dbType() {
+ return null;
+ }
+
+ @Override
+ protected String dbUser(final Object o) {
+ return null;
+ }
+
+ @Override
+ protected String dbInstance(final Object o) {
+ return null;
+ }
+
+ @Override
+ public <ENTITY> String entityName(final ENTITY entity) {
+ String name = null;
+ if (entity instanceof String) {
+ // We were given an entity name, not the entity itself.
+ name = (String) entity;
+ } else if (entity.getClass().isAnnotationPresent(Entity.class)) {
+ // We were given an instance of an entity.
+ name = entity.getClass().getName();
+ } else if (entity instanceof List && ((List) entity).size() > 0) {
+ // We have a list of entities.
+ name = entityName(((List) entity).get(0));
+ }
+ return name;
+ }
+}

MODIFY
dd-java-agent/instrumentation/hibernate/src/main/java/datadog/trace/instrumentation/hibernate/IteratorInstrumentation.java
dd-java-agent/instrumentation/hibernate/src/main/java/datadog/trace/instrumentation/hibernate/IteratorInstrumentation.java
@@ -16,6 +16,7 @@ import java.util.Map;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
+import net.bytebuddy.implementation.bytecode.assign.Assigner;
import net.bytebuddy.matcher.ElementMatcher;
import org.hibernate.engine.HibernateIterator;
@@ -65,16 +66,17 @@ public class IteratorInstrumentation extends Instrumenter.Default {
InstrumentationContext.get(HibernateIterator.class, SessionState.class);
return SessionMethodUtils.startScopeFrom(
- contextStore, iterator, "hibernate.iterator." + name);
+ contextStore, iterator, "hibernate.iterator." + name, null);
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void endMethod(
@Advice.This final HibernateIterator iterator,
@Advice.Enter final SessionState state,
- @Advice.Thrown final Throwable throwable) {
+ @Advice.Thrown final Throwable throwable,
+ @Advice.Return(typing = Assigner.Typing.DYNAMIC) final Object entity) {
- SessionMethodUtils.closeScope(state, throwable);
+ SessionMethodUtils.closeScope(state, throwable, entity);
}
}
}

MODIFY
dd-java-agent/instrumentation/hibernate/src/main/java/datadog/trace/instrumentation/hibernate/QueryInstrumentation.java
dd-java-agent/instrumentation/hibernate/src/main/java/datadog/trace/instrumentation/hibernate/QueryInstrumentation.java
@@ -16,8 +16,10 @@ import java.util.Map;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
+import net.bytebuddy.implementation.bytecode.assign.Assigner;
import net.bytebuddy.matcher.ElementMatcher;
import org.hibernate.Query;
+import org.hibernate.SQLQuery;
@AutoService(Instrumenter.class)
public class QueryInstrumentation extends Instrumenter.Default {
@@ -55,7 +57,6 @@ public class QueryInstrumentation extends Instrumenter.Default {
named("list")
.or(named("executeUpdate"))
.or(named("uniqueResult"))
- .or(named("iterate"))
.or(named("scroll"))),
QueryMethodAdvice.class.getName());
@@ -71,16 +72,29 @@ public class QueryInstrumentation extends Instrumenter.Default {
final ContextStore<Query, SessionState> contextStore =
InstrumentationContext.get(Query.class, SessionState.class);
- return SessionMethodUtils.startScopeFrom(contextStore, query, "hibernate.query." + name);
+ // Note: We don't know what the entity is until the method is returning.
+ final SessionState state =
+ SessionMethodUtils.startScopeFrom(contextStore, query, "hibernate.query." + name, null);
+ HibernateDecorator.INSTANCE.onStatement(
+ state.getMethodScope().span(), query.getQueryString());
+ return state;
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void endMethod(
@Advice.This final Query query,
@Advice.Enter final SessionState state,
- @Advice.Thrown final Throwable throwable) {
+ @Advice.Thrown final Throwable throwable,
+ @Advice.Return(typing = Assigner.Typing.DYNAMIC) final Object returned) {
- SessionMethodUtils.closeScope(state, throwable);
+ Object entity = returned;
+ if (returned == null || query instanceof SQLQuery) {
+ // Not a method that returns results, or the query returns a table rather than an ORM
+ // object.
+ entity = query.getQueryString();
+ }
+
+ SessionMethodUtils.closeScope(state, throwable, entity);
}
}
}

MODIFY
dd-java-agent/instrumentation/hibernate/src/main/java/datadog/trace/instrumentation/hibernate/SessionFactoryInstrumentation.java
dd-java-agent/instrumentation/hibernate/src/main/java/datadog/trace/instrumentation/hibernate/SessionFactoryInstrumentation.java
@@ -10,12 +10,9 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;
-import datadog.trace.api.DDSpanTypes;
-import datadog.trace.api.DDTags;
import datadog.trace.bootstrap.ContextStore;
import datadog.trace.bootstrap.InstrumentationContext;
import io.opentracing.Span;
-import io.opentracing.tag.Tags;
import io.opentracing.util.GlobalTracer;
import java.util.Collections;
import java.util.HashMap;
@@ -44,6 +41,11 @@ public class SessionFactoryInstrumentation extends Instrumenter.Default {
public String[] helperClassNames() {
return new String[] {
"datadog.trace.instrumentation.hibernate.SessionState",
+ "datadog.trace.agent.decorator.BaseDecorator",
+ "datadog.trace.agent.decorator.ClientDecorator",
+ "datadog.trace.agent.decorator.DatabaseClientDecorator",
+ "datadog.trace.agent.decorator.OrmClientDecorator",
+ packageName + ".HibernateDecorator",
};
}
@@ -74,14 +76,9 @@ public class SessionFactoryInstrumentation extends Instrumenter.Default {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void openSession(@Advice.Return final SharedSessionContract session) {
- final Span span =
- GlobalTracer.get()
- .buildSpan("hibernate.session")
- .withTag(DDTags.SERVICE_NAME, "hibernate")
- .withTag(DDTags.SPAN_TYPE, DDSpanTypes.HIBERNATE)
- .withTag(Tags.COMPONENT.getKey(), "hibernate-java")
- .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT)
- .start();
+ final Span span = GlobalTracer.get().buildSpan("hibernate.session").start();
+ HibernateDecorator.INSTANCE.afterStart(span);
+ HibernateDecorator.INSTANCE.onSession(span, session);
final ContextStore<SharedSessionContract, SessionState> contextStore =
InstrumentationContext.get(SharedSessionContract.class, SessionState.class);

MODIFY
dd-java-agent/instrumentation/hibernate/src/main/java/datadog/trace/instrumentation/hibernate/SessionInstrumentation.java
dd-java-agent/instrumentation/hibernate/src/main/java/datadog/trace/instrumentation/hibernate/SessionInstrumentation.java
package datadog.trace.instrumentation.hibernate;
import static datadog.trace.agent.tooling.ByteBuddyElementMatchers.safeHasSuperType;
-import static datadog.trace.instrumentation.hibernate.SessionMethodUtils.entityName;
-import static io.opentracing.log.Fields.ERROR_OBJECT;
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.named;
@@ -16,7 +14,6 @@ import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.bootstrap.ContextStore;
import datadog.trace.bootstrap.InstrumentationContext;
import io.opentracing.Span;
-import io.opentracing.tag.Tags;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -54,6 +51,11 @@ public class SessionInstrumentation extends Instrumenter.Default {
return new String[] {
"datadog.trace.instrumentation.hibernate.SessionMethodUtils",
"datadog.trace.instrumentation.hibernate.SessionState",
+ "datadog.trace.agent.decorator.BaseDecorator",
+ "datadog.trace.agent.decorator.ClientDecorator",
+ "datadog.trace.agent.decorator.DatabaseClientDecorator",
+ "datadog.trace.agent.decorator.OrmClientDecorator",
+ packageName + ".HibernateDecorator",
};
}
@@ -132,12 +134,10 @@ public class SessionInstrumentation extends Instrumenter.Default {
if (state.getMethodScope() != null) {
System.err.println("THIS IS WRONG"); // TODO: proper warning/logging.
}
- final Span span = state.getSessionSpan();
- if (throwable != null) {
- Tags.ERROR.set(span, true);
- span.log(Collections.singletonMap(ERROR_OBJECT, throwable));
- }
+ final Span span = state.getSessionSpan();
+ HibernateDecorator.INSTANCE.onError(span, throwable);
+ HibernateDecorator.INSTANCE.beforeFinish(span);
span.finish();
}
}
@@ -152,8 +152,7 @@ public class SessionInstrumentation extends Instrumenter.Default {
final ContextStore<SharedSessionContract, SessionState> contextStore =
InstrumentationContext.get(SharedSessionContract.class, SessionState.class);
- return SessionMethodUtils.startScopeFrom(
- contextStore, session, "hibernate." + name, entityName(entity));
+ return SessionMethodUtils.startScopeFrom(contextStore, session, "hibernate." + name, entity);
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
@@ -163,9 +162,9 @@ public class SessionInstrumentation extends Instrumenter.Default {
@Advice.Thrown final Throwable throwable,
@Advice.Return(typing = Assigner.Typing.DYNAMIC) final Object returned) {
- SessionMethodUtils.closeScope(sessionState, throwable);
+ SessionMethodUtils.closeScope(sessionState, throwable, returned);
- // Attach instrumentation to any returned object.
+ // Attach instrumentation to any returned object (of eligible type).
if (returned == null) {
return;
}

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
@@ -2,76 +2,51 @@ package datadog.trace.instrumentation.hibernate;
import static io.opentracing.log.Fields.ERROR_OBJECT;
-import datadog.trace.api.DDSpanTypes;
-import datadog.trace.api.DDTags;
import datadog.trace.bootstrap.ContextStore;
import io.opentracing.Scope;
import io.opentracing.Span;
import io.opentracing.tag.Tags;
import io.opentracing.util.GlobalTracer;
import java.util.Collections;
-import javax.persistence.Entity;
public class SessionMethodUtils {
- public static String entityName(final Object entityOrName) {
- String name = "unknown object";
- if (entityOrName == null) {
- return name; // Hibernate can internally call save(null, Entity).
- }
- if (entityOrName instanceof String) {
- name = (String) entityOrName;
- } else if (entityOrName.getClass().isAnnotationPresent(Entity.class)) {
- // This is the object being replicated.
- name = entityOrName.getClass().getName();
- }
- return name;
- }
-
// Starts a scope as a child from a Span, where the Span is attached to the given spanKey using
// the given contextStore.
- public static <T> SessionState startScopeFrom(
- final ContextStore<T, SessionState> contextStore,
- final T spanKey,
+ public static <TARGET, ENTITY> SessionState startScopeFrom(
+ final ContextStore<TARGET, SessionState> contextStore,
+ final TARGET spanKey,
final String operationName,
- final String resourceName) {
+ final ENTITY entity) {
final SessionState sessionState = contextStore.get(spanKey);
if (sessionState == null) {
- // No state found. Maybe the instrumentation isn't working correctly.
+ // No state found. We aren't in a Session.
return null;
}
if (sessionState.getMethodScope() != null) {
// This method call was re-entrant. Do nothing, since it is being traced by the parent/first
// call.
- return sessionState;
+ return null;
}
final Scope scope =
GlobalTracer.get()
.buildSpan(operationName)
.asChildOf(sessionState.getSessionSpan())
- .withTag(DDTags.SERVICE_NAME, "hibernate")
- .withTag(DDTags.SPAN_TYPE, DDSpanTypes.HIBERNATE)
- .withTag(DDTags.RESOURCE_NAME, resourceName)
- .withTag(Tags.COMPONENT.getKey(), "hibernate-java")
.startActive(true);
- sessionState.setMethodScope(scope);
+ HibernateDecorator.INSTANCE.afterStart(scope.span());
+ HibernateDecorator.INSTANCE.onOperation(scope.span(), entity);
+ sessionState.setMethodScope(scope);
return sessionState;
}
- public static <T> SessionState startScopeFrom(
- final ContextStore<T, SessionState> contextStore,
- final T spanKey,
- final String operationName) {
- return startScopeFrom(contextStore, spanKey, operationName, operationName);
- }
-
// Closes a Scope/Span, adding an error tag if the given Throwable is not null.
- public static void closeScope(final SessionState sessionState, final Throwable throwable) {
+ public static void closeScope(
+ final SessionState sessionState, final Throwable throwable, final Object entity) {
if (sessionState == null || sessionState.getMethodScope() == null) {
// This method call was re-entrant. Do nothing, since it is being traced by the parent/first
@@ -86,6 +61,10 @@ public class SessionMethodUtils {
Tags.ERROR.set(span, true);
span.log(Collections.singletonMap(ERROR_OBJECT, throwable));
}
+ if (entity != null) {
+ HibernateDecorator.INSTANCE.onOperation(span, entity);
+ }
+ HibernateDecorator.INSTANCE.beforeFinish(span);
span.finish();
}

MODIFY
dd-java-agent/instrumentation/hibernate/src/main/java/datadog/trace/instrumentation/hibernate/TransactionInstrumentation.java
dd-java-agent/instrumentation/hibernate/src/main/java/datadog/trace/instrumentation/hibernate/TransactionInstrumentation.java
@@ -69,7 +69,7 @@ public class TransactionInstrumentation extends Instrumenter.Default {
InstrumentationContext.get(Transaction.class, SessionState.class);
return SessionMethodUtils.startScopeFrom(
- contextStore, transaction, "hibernate.transaction.commit");
+ contextStore, transaction, "hibernate.transaction.commit", null);
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
@@ -78,7 +78,7 @@ public class TransactionInstrumentation extends Instrumenter.Default {
@Advice.Enter final SessionState state,
@Advice.Thrown final Throwable throwable) {
- SessionMethodUtils.closeScope(state, throwable);
+ SessionMethodUtils.closeScope(state, throwable, null);
}
}
}

MODIFY
dd-java-agent/instrumentation/hibernate/src/test/groovy/CriteriaTest.groovy
dd-java-agent/instrumentation/hibernate/src/test/groovy/CriteriaTest.groovy
@@ -64,7 +64,7 @@ class CriteriaTest extends AgentTestRunner {
spanType DDSpanTypes.HIBERNATE
parent()
tags {
- "$Tags.COMPONENT.key" "hibernate-java"
+ "$Tags.COMPONENT.key" "java-hibernate"
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
"$DDTags.SPAN_TYPE" DDSpanTypes.HIBERNATE
defaultTags()
@@ -77,7 +77,8 @@ class CriteriaTest extends AgentTestRunner {
spanType DDSpanTypes.HIBERNATE
childOf span(0)
tags {
- "$Tags.COMPONENT.key" "hibernate-java"
+ "$Tags.COMPONENT.key" "java-hibernate"
+ "$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
"$DDTags.SPAN_TYPE" DDSpanTypes.HIBERNATE
defaultTags()
}
@@ -89,7 +90,8 @@ class CriteriaTest extends AgentTestRunner {
spanType DDSpanTypes.HIBERNATE
childOf span(0)
tags {
- "$Tags.COMPONENT.key" "hibernate-java"
+ "$Tags.COMPONENT.key" "java-hibernate"
+ "$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
"$DDTags.SPAN_TYPE" DDSpanTypes.HIBERNATE
defaultTags()
}

MODIFY
dd-java-agent/instrumentation/hibernate/src/test/groovy/QueryTest.groovy
dd-java-agent/instrumentation/hibernate/src/test/groovy/QueryTest.groovy
@@ -25,7 +25,7 @@ class QueryTest extends AbstractHibernateTest {
spanType DDSpanTypes.HIBERNATE
parent()
tags {
- "$Tags.COMPONENT.key" "hibernate-java"
+ "$Tags.COMPONENT.key" "java-hibernate"
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
"$DDTags.SPAN_TYPE" DDSpanTypes.HIBERNATE
defaultTags()
@@ -38,19 +38,21 @@ class QueryTest extends AbstractHibernateTest {
spanType DDSpanTypes.HIBERNATE
childOf span(0)
tags {
- "$Tags.COMPONENT.key" "hibernate-java"
+ "$Tags.COMPONENT.key" "java-hibernate"
+ "$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
"$DDTags.SPAN_TYPE" DDSpanTypes.HIBERNATE
defaultTags()
}
}
span(2) {
serviceName "hibernate"
- resourceName "hibernate.query.$queryMethodName"
- operationName "hibernate.query.$queryMethodName"
+ resourceName "$resource"
+ operationName "hibernate.$queryMethodName"
spanType DDSpanTypes.HIBERNATE
childOf span(0)
tags {
- "$Tags.COMPONENT.key" "hibernate-java"
+ "$Tags.COMPONENT.key" "java-hibernate"
+ "$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
"$DDTags.SPAN_TYPE" DDSpanTypes.HIBERNATE
defaultTags()
}
@@ -63,24 +65,24 @@ class QueryTest extends AbstractHibernateTest {
}
where:
- queryMethodName | isError | queryInteraction
- "list" | false | { sess ->
+ queryMethodName | isError | resource | queryInteraction
+ "query.list" | false | "Value" | { sess ->
Query q = sess.createQuery("from Value")
q.list()
}
- "executeUpdate" | false | { sess ->
+ "query.executeUpdate" | false | "update Value set name = 'alyx'" | { sess ->
Query q = sess.createQuery("update Value set name = 'alyx'")
q.executeUpdate()
}
- "uniqueResult" | false | { sess ->
+ "query.uniqueResult" | false | "Value" | { sess ->
Query q = sess.createQuery("from Value where id = 1")
q.uniqueResult()
}
- "iterate" | false | { sess ->
+ "iterate" | false | "from Value" | { sess ->
Query q = sess.createQuery("from Value")
q.iterate()
}
- "scroll" | false | { sess ->
+ "query.scroll" | false | "from Value" | { sess ->
Query q = sess.createQuery("from Value")
q.scroll()
}
@@ -109,7 +111,7 @@ class QueryTest extends AbstractHibernateTest {
spanType DDSpanTypes.HIBERNATE
parent()
tags {
- "$Tags.COMPONENT.key" "hibernate-java"
+ "$Tags.COMPONENT.key" "java-hibernate"
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
"$DDTags.SPAN_TYPE" DDSpanTypes.HIBERNATE
defaultTags()
@@ -122,7 +124,8 @@ class QueryTest extends AbstractHibernateTest {
spanType DDSpanTypes.HIBERNATE
childOf span(0)
tags {
- "$Tags.COMPONENT.key" "hibernate-java"
+ "$Tags.COMPONENT.key" "java-hibernate"
+ "$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
"$DDTags.SPAN_TYPE" DDSpanTypes.HIBERNATE
defaultTags()
}
@@ -134,7 +137,8 @@ class QueryTest extends AbstractHibernateTest {
spanType DDSpanTypes.HIBERNATE
childOf span(0)
tags {
- "$Tags.COMPONENT.key" "hibernate-java"
+ "$Tags.COMPONENT.key" "java-hibernate"
+ "$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
"$DDTags.SPAN_TYPE" DDSpanTypes.HIBERNATE
defaultTags()
}
@@ -146,19 +150,21 @@ class QueryTest extends AbstractHibernateTest {
spanType DDSpanTypes.HIBERNATE
childOf span(0)
tags {
- "$Tags.COMPONENT.key" "hibernate-java"
+ "$Tags.COMPONENT.key" "java-hibernate"
+ "$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
"$DDTags.SPAN_TYPE" DDSpanTypes.HIBERNATE
defaultTags()
}
}
span(4) {
serviceName "hibernate"
- resourceName "hibernate.query.iterate"
- operationName "hibernate.query.iterate"
+ resourceName "from Value"
+ operationName "hibernate.iterate"
spanType DDSpanTypes.HIBERNATE
childOf span(0)
tags {
- "$Tags.COMPONENT.key" "hibernate-java"
+ "$Tags.COMPONENT.key" "java-hibernate"
+ "$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
"$DDTags.SPAN_TYPE" DDSpanTypes.HIBERNATE
defaultTags()
}

MODIFY
dd-java-agent/instrumentation/hibernate/src/test/groovy/SessionTest.groovy
dd-java-agent/instrumentation/hibernate/src/test/groovy/SessionTest.groovy
@@ -47,7 +47,7 @@ class SessionTest extends AbstractHibernateTest {
spanType DDSpanTypes.HIBERNATE
parent()
tags {
- "$Tags.COMPONENT.key" "hibernate-java"
+ "$Tags.COMPONENT.key" "java-hibernate"
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
"$DDTags.SPAN_TYPE" DDSpanTypes.HIBERNATE
defaultTags()
@@ -60,7 +60,8 @@ class SessionTest extends AbstractHibernateTest {
spanType DDSpanTypes.HIBERNATE
childOf span(0)
tags {
- "$Tags.COMPONENT.key" "hibernate-java"
+ "$Tags.COMPONENT.key" "java-hibernate"
+ "$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
"$DDTags.SPAN_TYPE" DDSpanTypes.HIBERNATE
defaultTags()
}
@@ -78,7 +79,8 @@ class SessionTest extends AbstractHibernateTest {
if (isError) {
errorTags(MappingException, "Unknown entity: java.lang.Long")
}
- "$Tags.COMPONENT.key" "hibernate-java"
+ "$Tags.COMPONENT.key" "java-hibernate"
+ "$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
"$DDTags.SPAN_TYPE" DDSpanTypes.HIBERNATE
defaultTags()
}
@@ -144,7 +146,7 @@ class SessionTest extends AbstractHibernateTest {
spanType DDSpanTypes.HIBERNATE
parent()
tags {
- "$Tags.COMPONENT.key" "hibernate-java"
+ "$Tags.COMPONENT.key" "java-hibernate"
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
"$DDTags.SPAN_TYPE" DDSpanTypes.HIBERNATE
defaultTags()
@@ -157,7 +159,8 @@ class SessionTest extends AbstractHibernateTest {
spanType DDSpanTypes.HIBERNATE
childOf span(0)
tags {
- "$Tags.COMPONENT.key" "hibernate-java"
+ "$Tags.COMPONENT.key" "java-hibernate"
+ "$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
"$DDTags.SPAN_TYPE" DDSpanTypes.HIBERNATE
defaultTags()
}
@@ -179,7 +182,8 @@ class SessionTest extends AbstractHibernateTest {
if (isError) {
errorTags(MappingException, "Unknown entity: java.lang.Long")
}
- "$Tags.COMPONENT.key" "hibernate-java"
+ "$Tags.COMPONENT.key" "java-hibernate"
+ "$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
"$DDTags.SPAN_TYPE" DDSpanTypes.HIBERNATE
defaultTags()
}
@@ -232,7 +236,7 @@ class SessionTest extends AbstractHibernateTest {
spanType DDSpanTypes.HIBERNATE
parent()
tags {
- "$Tags.COMPONENT.key" "hibernate-java"
+ "$Tags.COMPONENT.key" "java-hibernate"
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
"$DDTags.SPAN_TYPE" DDSpanTypes.HIBERNATE
defaultTags()
@@ -245,21 +249,23 @@ class SessionTest extends AbstractHibernateTest {
spanType DDSpanTypes.HIBERNATE
childOf span(0)
tags {
- "$Tags.COMPONENT.key" "hibernate-java"
+ "$Tags.COMPONENT.key" "java-hibernate"
+ "$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
"$DDTags.SPAN_TYPE" DDSpanTypes.HIBERNATE
defaultTags()
}
}
span(2) {
serviceName "hibernate"
- resourceName "unknown object"
+ resourceName "hibernate.replicate"
operationName "hibernate.replicate"
spanType DDSpanTypes.HIBERNATE
childOf span(0)
tags {
errorTags(MappingException, "Unknown entity: java.lang.Long")
- "$Tags.COMPONENT.key" "hibernate-java"
+ "$Tags.COMPONENT.key" "java-hibernate"
+ "$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
"$DDTags.SPAN_TYPE" DDSpanTypes.HIBERNATE
defaultTags()
}
@@ -299,7 +305,7 @@ class SessionTest extends AbstractHibernateTest {
spanType DDSpanTypes.HIBERNATE
parent()
tags {
- "$Tags.COMPONENT.key" "hibernate-java"
+ "$Tags.COMPONENT.key" "java-hibernate"
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
"$DDTags.SPAN_TYPE" DDSpanTypes.HIBERNATE
defaultTags()
@@ -312,7 +318,8 @@ class SessionTest extends AbstractHibernateTest {
spanType DDSpanTypes.HIBERNATE
childOf span(0)
tags {
- "$Tags.COMPONENT.key" "hibernate-java"
+ "$Tags.COMPONENT.key" "java-hibernate"
+ "$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
"$DDTags.SPAN_TYPE" DDSpanTypes.HIBERNATE
defaultTags()
}
@@ -334,7 +341,8 @@ class SessionTest extends AbstractHibernateTest {
if (isError) {
errorTags(MappingException, "Unknown entity: java.lang.Long")
}
- "$Tags.COMPONENT.key" "hibernate-java"
+ "$Tags.COMPONENT.key" "java-hibernate"
+ "$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
"$DDTags.SPAN_TYPE" DDSpanTypes.HIBERNATE
defaultTags()
}
@@ -394,7 +402,7 @@ class SessionTest extends AbstractHibernateTest {
spanType DDSpanTypes.HIBERNATE
parent()
tags {
- "$Tags.COMPONENT.key" "hibernate-java"
+ "$Tags.COMPONENT.key" "java-hibernate"
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
"$DDTags.SPAN_TYPE" DDSpanTypes.HIBERNATE
defaultTags()
@@ -407,19 +415,21 @@ class SessionTest extends AbstractHibernateTest {
spanType DDSpanTypes.HIBERNATE
childOf span(0)
tags {
- "$Tags.COMPONENT.key" "hibernate-java"
+ "$Tags.COMPONENT.key" "java-hibernate"
+ "$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
"$DDTags.SPAN_TYPE" DDSpanTypes.HIBERNATE
defaultTags()
}
}
span(2) {
serviceName "hibernate"
- resourceName "hibernate.query.list"
+ resourceName "$resource"
operationName "hibernate.query.list"
spanType DDSpanTypes.HIBERNATE
childOf span(0)
tags {
- "$Tags.COMPONENT.key" "hibernate-java"
+ "$Tags.COMPONENT.key" "java-hibernate"
+ "$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
"$DDTags.SPAN_TYPE" DDSpanTypes.HIBERNATE
defaultTags()
}
@@ -432,10 +442,10 @@ class SessionTest extends AbstractHibernateTest {
}
where:
- queryMethodName | queryBuildMethod
- "createQuery" | { sess -> sess.createQuery("from Value") }
- "getNamedQuery" | { sess -> sess.getNamedQuery("TestNamedQuery") }
- "createSQLQuery" | { sess -> sess.createSQLQuery("SELECT * FROM Value") }
+ queryMethodName | resource | queryBuildMethod
+ "createQuery" | "Value" | { sess -> sess.createQuery("from Value") }
+ "getNamedQuery" | "Value" | { sess -> sess.getNamedQuery("TestNamedQuery") }
+ "createSQLQuery" | "SELECT * FROM Value" | { sess -> sess.createSQLQuery("SELECT * FROM Value") }
}
}

Use a Dectorator for the Hibernate instrumentation