Transition spring-data-1.8 module to instrumenter API
MODIFY
instrumentation/spring/spring-data-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/data/SpringDataInstrumentationModule.java
instrumentation/spring/spring-data-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/data/SpringDataInstrumentationModule.java
package io.opentelemetry.javaagent.instrumentation.spring.data;
-import static io.opentelemetry.javaagent.instrumentation.spring.data.SpringDataTracer.tracer;
+import static io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge.currentContext;
+import static io.opentelemetry.javaagent.instrumentation.spring.data.SpringDataSingletons.instrumenter;
import static java.util.Collections.singletonList;
import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
import static net.bytebuddy.matcher.ElementMatchers.named;
@@ -92,23 +93,22 @@ public class SpringDataInstrumentationModule extends InstrumentationModule {
@Override
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
- Method invokedMethod = methodInvocation.getMethod();
- Class<?> clazz = invokedMethod.getDeclaringClass();
-
- boolean isRepositoryOp = Repository.class.isAssignableFrom(clazz);
+ Context parentContext = currentContext();
+ Method method = methodInvocation.getMethod();
// Since this interceptor is the outer most interceptor, non-Repository methods
// including Object methods will also flow through here. Don't create spans for those.
- if (!isRepositoryOp) {
+ boolean isRepositoryOp = Repository.class.isAssignableFrom(method.getDeclaringClass());
+ if (!isRepositoryOp || !instrumenter().shouldStart(parentContext, method)) {
return methodInvocation.proceed();
}
- Context context = tracer().startSpan(invokedMethod);
+ Context context = instrumenter().start(parentContext, method);
try (Scope ignored = context.makeCurrent()) {
Object result = methodInvocation.proceed();
- tracer().end(context);
+ instrumenter().end(context, method, null, null);
return result;
} catch (Throwable t) {
- tracer().endExceptionally(context, t);
+ instrumenter().end(context, method, null, t);
throw t;
}
}

ADD
instrumentation/spring/spring-data-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/data/SpringDataSingletons.java
+/*
+ * Copyright The OpenTelemetry Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package io.opentelemetry.javaagent.instrumentation.spring.data;
+
+import io.opentelemetry.api.GlobalOpenTelemetry;
+import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
+import io.opentelemetry.instrumentation.api.tracer.SpanNames;
+import java.lang.reflect.Method;
+
+public final class SpringDataSingletons {
+
+ private static final Instrumenter<Method, Void> INSTRUMENTER =
+ Instrumenter.<Method, Void>newBuilder(
+ GlobalOpenTelemetry.get(), "io.opentelemetry.spring-data-1.8", SpanNames::fromMethod)
+ .newInstrumenter();
+
+ public static Instrumenter<Method, Void> instrumenter() {
+ return INSTRUMENTER;
+ }
+
+ private SpringDataSingletons() {}
+}

DELETE
instrumentation/spring/spring-data-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/data/SpringDataTracer.java
-/*
- * Copyright The OpenTelemetry Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-
-package io.opentelemetry.javaagent.instrumentation.spring.data;
-
-import io.opentelemetry.context.Context;
-import io.opentelemetry.instrumentation.api.tracer.BaseTracer;
-import io.opentelemetry.instrumentation.api.tracer.SpanNames;
-import java.lang.reflect.Method;
-
-public final class SpringDataTracer extends BaseTracer {
- private static final SpringDataTracer TRACER = new SpringDataTracer();
-
- public static SpringDataTracer tracer() {
- return TRACER;
- }
-
- private SpringDataTracer() {}
-
- @Override
- protected String getInstrumentationName() {
- return "io.opentelemetry.spring-data-1.8";
- }
-
- public Context startSpan(Method method) {
- return startSpan(SpanNames.fromMethod(method));
- }
-}

Transition spring-data-1.8 module to instrumenter API (#3991)