Skip to content

Commit 4f9a237

Browse files
otelbot[bot]trask
andauthored
Review fixes for jfinal-3.2:javaagent (#18094)
Co-authored-by: otelbot <197425009+otelbot@users.noreply.github.com> Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
1 parent b4903c1 commit 4f9a237

4 files changed

Lines changed: 17 additions & 10 deletions

File tree

instrumentation/jfinal-3.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jfinal/v3_2/ActionMappingInstrumentation.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.jfinal.core.Action;
1111
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
1212
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
13+
import javax.annotation.Nullable;
1314
import net.bytebuddy.asm.Advice;
1415
import net.bytebuddy.description.type.TypeDescription;
1516
import net.bytebuddy.matcher.ElementMatcher;
@@ -30,7 +31,7 @@ public void transform(TypeTransformer transformer) {
3031
public static class GetActionAdvice {
3132

3233
@Advice.OnMethodExit(suppress = Throwable.class, inline = false)
33-
public static void exitGetAction(@Advice.Return Action action) {
34+
public static void exitGetAction(@Advice.Return @Nullable Action action) {
3435
JFinalSingletons.updateRoute(action);
3536
}
3637
}

instrumentation/jfinal-3.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jfinal/v3_2/InvocationInstrumentation.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,22 @@ public static class InvokeAdvice {
4040

4141
public static class AdviceScope {
4242
private final CallDepth callDepth;
43-
private final ClassAndMethod request;
44-
private final Context context;
45-
private final Scope scope;
43+
@Nullable private final ClassAndMethod request;
44+
@Nullable private final Context context;
45+
@Nullable private final Scope scope;
4646

4747
public AdviceScope(
48-
CallDepth callDepth, ClassAndMethod request, Context context, Scope scope) {
48+
CallDepth callDepth,
49+
@Nullable ClassAndMethod request,
50+
@Nullable Context context,
51+
@Nullable Scope scope) {
4952
this.callDepth = callDepth;
5053
this.request = request;
5154
this.context = context;
5255
this.scope = scope;
5356
}
5457

55-
public static AdviceScope start(CallDepth callDepth, Action action) {
58+
public static AdviceScope start(CallDepth callDepth, @Nullable Action action) {
5659
if (callDepth.getAndIncrement() > 0 || action == null) {
5760
return new AdviceScope(callDepth, null, null, null);
5861
}
@@ -69,6 +72,7 @@ public static AdviceScope start(CallDepth callDepth, Action action) {
6972
}
7073

7174
public void end(@Nullable Throwable throwable) {
75+
// when no tracing scope is started, request and context are also null
7276
if (callDepth.decrementAndGet() > 0 || scope == null) {
7377
return;
7478
}
@@ -78,7 +82,7 @@ public void end(@Nullable Throwable throwable) {
7882
}
7983

8084
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
81-
public static AdviceScope onEnter(@Advice.FieldValue("action") Action action) {
85+
public static AdviceScope onEnter(@Advice.FieldValue("action") @Nullable Action action) {
8286
CallDepth callDepth = CallDepth.forClass(Invocation.class);
8387
return AdviceScope.start(callDepth, action);
8488
}

instrumentation/jfinal-3.2/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jfinal/JFinalTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import static org.assertj.core.api.Assertions.assertThat;
1818

1919
import com.jfinal.core.JFinalFilter;
20-
import io.opentelemetry.api.common.Attributes;
2120
import io.opentelemetry.api.trace.SpanKind;
2221
import io.opentelemetry.instrumentation.api.internal.HttpConstants;
2322
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
@@ -32,6 +31,7 @@
3231
import java.util.EnumSet;
3332
import java.util.Locale;
3433
import javax.servlet.DispatcherType;
34+
import org.eclipse.jetty.server.Response;
3535
import org.eclipse.jetty.server.Server;
3636
import org.eclipse.jetty.servlet.FilterHolder;
3737
import org.eclipse.jetty.servlet.ServletContextHandler;
@@ -98,7 +98,8 @@ protected SpanDataAssert assertResponseSpan(
9898
return span.satisfies(spanData -> assertThat(spanData.getName()).endsWith(".sendRedirect"))
9999
.hasParent(serverSpan)
100100
.hasKind(SpanKind.INTERNAL)
101-
.hasAttributesSatisfying(Attributes::isEmpty);
101+
.hasAttributesSatisfyingExactly(
102+
SemconvCodeStabilityUtil.codeFunctionAssertions(Response.class, "sendRedirect"));
102103
}
103104

104105
@Override

instrumentation/jfinal-3.2/metadata.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ features:
88
library_link: https://github.com/jfinal/jfinal
99
configurations:
1010
- name: otel.instrumentation.common.experimental.controller-telemetry.enabled
11+
declarative_name: java.common.controller_telemetry/development.enabled
1112
description: Enables the creation of experimental controller spans.
1213
type: boolean
13-
default: false
14+
default: false

0 commit comments

Comments
 (0)