Skip to content

Commit 3058c33

Browse files
authored
Indy-ready - tomcat (#14866)
1 parent fdfa3ef commit 3058c33

File tree

5 files changed

+98
-41
lines changed

5 files changed

+98
-41
lines changed

instrumentation/tomcat/tomcat-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/v10_0/Tomcat10InstrumentationModule.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
import com.google.auto.service.AutoService;
1212
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
1313
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
14+
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
1415
import io.opentelemetry.javaagent.instrumentation.tomcat.common.TomcatServerHandlerInstrumentation;
1516
import java.util.List;
1617
import net.bytebuddy.matcher.ElementMatcher;
1718

1819
@AutoService(InstrumentationModule.class)
19-
public class Tomcat10InstrumentationModule extends InstrumentationModule {
20+
public class Tomcat10InstrumentationModule extends InstrumentationModule
21+
implements ExperimentalInstrumentationModule {
2022

2123
public Tomcat10InstrumentationModule() {
2224
super("tomcat", "tomcat-10.0");
@@ -42,4 +44,9 @@ public List<TypeInstrumentation> typeInstrumentations() {
4244
packageName + ".Tomcat10ServerHandlerAdvice",
4345
packageName + ".Tomcat10AttachResponseAdvice"));
4446
}
47+
48+
@Override
49+
public boolean isIndyReady() {
50+
return true;
51+
}
4552
}

instrumentation/tomcat/tomcat-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/v10_0/Tomcat10ServerHandlerAdvice.java

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,61 @@
99

1010
import io.opentelemetry.context.Context;
1111
import io.opentelemetry.context.Scope;
12-
import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge;
1312
import io.opentelemetry.javaagent.bootstrap.http.HttpServerResponseCustomizerHolder;
13+
import javax.annotation.Nullable;
1414
import net.bytebuddy.asm.Advice;
1515
import org.apache.coyote.Request;
1616
import org.apache.coyote.Response;
1717

1818
@SuppressWarnings("unused")
1919
public class Tomcat10ServerHandlerAdvice {
2020

21-
@Advice.OnMethodEnter(suppress = Throwable.class)
22-
public static void onEnter(
23-
@Advice.Argument(0) Request request,
24-
@Advice.Argument(1) Response response,
25-
@Advice.Local("otelContext") Context context,
26-
@Advice.Local("otelScope") Scope scope) {
21+
public static class AdviceScope {
22+
private final Context context;
23+
private final Scope scope;
2724

28-
Context parentContext = Java8BytecodeBridge.currentContext();
29-
if (!helper().shouldStart(parentContext, request)) {
30-
return;
25+
private AdviceScope(Context context, Scope scope) {
26+
this.context = context;
27+
this.scope = scope;
3128
}
3229

33-
context = helper().start(parentContext, request);
30+
@Nullable
31+
public static AdviceScope start(Request request, Response response) {
32+
Context parentContext = Context.current();
33+
if (!helper().shouldStart(parentContext, request)) {
34+
return null;
35+
}
36+
37+
Context context = helper().start(parentContext, request);
3438

35-
scope = context.makeCurrent();
39+
Scope scope = context.makeCurrent();
40+
41+
HttpServerResponseCustomizerHolder.getCustomizer()
42+
.customize(context, response, Tomcat10ResponseMutator.INSTANCE);
43+
44+
return new AdviceScope(context, scope);
45+
}
3646

37-
HttpServerResponseCustomizerHolder.getCustomizer()
38-
.customize(context, response, Tomcat10ResponseMutator.INSTANCE);
47+
public void end(Request request, Response response, Throwable throwable) {
48+
helper().end(request, response, throwable, context, scope);
49+
}
50+
}
51+
52+
@Nullable
53+
@Advice.OnMethodEnter(suppress = Throwable.class)
54+
public static AdviceScope onEnter(
55+
@Advice.Argument(0) Request request, @Advice.Argument(1) Response response) {
56+
return AdviceScope.start(request, response);
3957
}
4058

4159
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
4260
public static void stopSpan(
4361
@Advice.Argument(0) Request request,
4462
@Advice.Argument(1) Response response,
45-
@Advice.Thrown Throwable throwable,
46-
@Advice.Local("otelContext") Context context,
47-
@Advice.Local("otelScope") Scope scope) {
48-
49-
helper().end(request, response, throwable, context, scope);
63+
@Advice.Thrown @Nullable Throwable throwable,
64+
@Advice.Enter @Nullable AdviceScope adviceScope) {
65+
if (adviceScope != null) {
66+
adviceScope.end(request, response, throwable);
67+
}
5068
}
5169
}

instrumentation/tomcat/tomcat-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/v7_0/Tomcat7InstrumentationModule.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
import com.google.auto.service.AutoService;
1212
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
1313
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
14+
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
1415
import io.opentelemetry.javaagent.instrumentation.tomcat.common.TomcatServerHandlerInstrumentation;
1516
import java.util.List;
1617
import net.bytebuddy.matcher.ElementMatcher;
1718

1819
@AutoService(InstrumentationModule.class)
19-
public class Tomcat7InstrumentationModule extends InstrumentationModule {
20+
public class Tomcat7InstrumentationModule extends InstrumentationModule
21+
implements ExperimentalInstrumentationModule {
2022

2123
public Tomcat7InstrumentationModule() {
2224
super("tomcat", "tomcat-7.0");
@@ -39,4 +41,9 @@ public List<TypeInstrumentation> typeInstrumentations() {
3941
packageName + ".Tomcat7ServerHandlerAdvice",
4042
packageName + ".Tomcat7AttachResponseAdvice"));
4143
}
44+
45+
@Override
46+
public boolean isIndyReady() {
47+
return true;
48+
}
4249
}

instrumentation/tomcat/tomcat-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/v7_0/Tomcat7ServerHandlerAdvice.java

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,61 @@
99

1010
import io.opentelemetry.context.Context;
1111
import io.opentelemetry.context.Scope;
12-
import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge;
1312
import io.opentelemetry.javaagent.bootstrap.http.HttpServerResponseCustomizerHolder;
13+
import javax.annotation.Nullable;
1414
import net.bytebuddy.asm.Advice;
1515
import org.apache.coyote.Request;
1616
import org.apache.coyote.Response;
1717

1818
@SuppressWarnings("unused")
1919
public class Tomcat7ServerHandlerAdvice {
2020

21-
@Advice.OnMethodEnter(suppress = Throwable.class)
22-
public static void onEnter(
23-
@Advice.Argument(0) Request request,
24-
@Advice.Argument(1) Response response,
25-
@Advice.Local("otelContext") Context context,
26-
@Advice.Local("otelScope") Scope scope) {
21+
public static class AdviceScope {
22+
private final Context context;
23+
private final Scope scope;
2724

28-
Context parentContext = Java8BytecodeBridge.currentContext();
29-
if (!helper().shouldStart(parentContext, request)) {
30-
return;
25+
private AdviceScope(Context context, Scope scope) {
26+
this.context = context;
27+
this.scope = scope;
3128
}
3229

33-
context = helper().start(parentContext, request);
30+
@Nullable
31+
public static AdviceScope start(Request request, Response response) {
32+
Context parentContext = Context.current();
33+
if (!helper().shouldStart(parentContext, request)) {
34+
return null;
35+
}
36+
37+
Context context = helper().start(parentContext, request);
3438

35-
scope = context.makeCurrent();
39+
Scope scope = context.makeCurrent();
40+
41+
HttpServerResponseCustomizerHolder.getCustomizer()
42+
.customize(context, response, Tomcat7ResponseMutator.INSTANCE);
43+
44+
return new AdviceScope(context, scope);
45+
}
3646

37-
HttpServerResponseCustomizerHolder.getCustomizer()
38-
.customize(context, response, Tomcat7ResponseMutator.INSTANCE);
47+
public void end(Request request, Response response, Throwable throwable) {
48+
helper().end(request, response, throwable, context, scope);
49+
}
50+
}
51+
52+
@Nullable
53+
@Advice.OnMethodEnter(suppress = Throwable.class)
54+
public static AdviceScope onEnter(
55+
@Advice.Argument(0) Request request, @Advice.Argument(1) Response response) {
56+
return AdviceScope.start(request, response);
3957
}
4058

4159
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
4260
public static void stopSpan(
4361
@Advice.Argument(0) Request request,
4462
@Advice.Argument(1) Response response,
45-
@Advice.Thrown Throwable throwable,
46-
@Advice.Local("otelContext") Context context,
47-
@Advice.Local("otelScope") Scope scope) {
48-
49-
helper().end(request, response, throwable, context, scope);
63+
@Advice.Thrown @Nullable Throwable throwable,
64+
@Advice.Enter AdviceScope adviceScope) {
65+
if (adviceScope != null) {
66+
adviceScope.end(request, response, throwable);
67+
}
5068
}
5169
}

instrumentation/tomcat/tomcat-jdbc/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/jdbc/TomcatJdbcInstrumentationModule.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
import com.google.auto.service.AutoService;
1111
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
1212
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
13+
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
1314
import java.util.List;
1415

1516
@AutoService(InstrumentationModule.class)
16-
public class TomcatJdbcInstrumentationModule extends InstrumentationModule {
17+
public class TomcatJdbcInstrumentationModule extends InstrumentationModule
18+
implements ExperimentalInstrumentationModule {
1719
public TomcatJdbcInstrumentationModule() {
1820
super("tomcat-jdbc");
1921
}
@@ -22,4 +24,9 @@ public TomcatJdbcInstrumentationModule() {
2224
public List<TypeInstrumentation> typeInstrumentations() {
2325
return singletonList(new DataSourceProxyInstrumentation());
2426
}
27+
28+
@Override
29+
public boolean isIndyReady() {
30+
return true;
31+
}
2532
}

0 commit comments

Comments
 (0)