Skip to content

Commit a6220e8

Browse files
committed
code review notes
1 parent 0450f64 commit a6220e8

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

instrumentation/play/play-mvc/play-mvc-2.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/play/v2_4/ActionInstrumentation.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
1818
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
1919
import java.lang.reflect.Method;
20+
import javax.annotation.Nullable;
2021
import net.bytebuddy.asm.Advice;
2122
import net.bytebuddy.description.type.TypeDescription;
2223
import net.bytebuddy.matcher.ElementMatcher;
@@ -65,22 +66,16 @@ public static void stopTraceOnResponse(
6566
@Advice.Thrown Throwable throwable,
6667
@Advice.Argument(0) Request<?> req,
6768
@Advice.Return(readOnly = false) Future<Result> responseFuture,
68-
@Advice.Enter AdviceScope actionScope) {
69-
if (actionScope == null || actionScope.getScope() == null) {
69+
@Advice.Enter @Nullable AdviceScope actionScope) {
70+
if (actionScope == null) {
7071
return;
7172
}
7273
actionScope.closeScope();
7374

7475
updateSpan(actionScope.getContext(), req);
7576

7677
// span finished in RequestCompleteCallback
77-
if (throwable == null) {
78-
responseFuture.onComplete(
79-
new RequestCompleteCallback(actionScope.getContext()),
80-
((Action<?>) thisAction).executionContext());
81-
} else {
82-
actionScope.end(throwable);
83-
}
78+
actionScope.end(throwable, responseFuture, (Action<?>) thisAction);
8479
}
8580
}
8681
}

instrumentation/play/play-mvc/play-mvc-2.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/play/v2_4/AdviceScope.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
import io.opentelemetry.context.Context;
1111
import io.opentelemetry.context.Scope;
12+
import javax.annotation.Nullable;
13+
import play.api.mvc.Action;
14+
import play.api.mvc.Result;
15+
import scala.concurrent.Future;
1216

1317
/** Container used to carry state between enter and exit advices */
1418
public final class AdviceScope {
@@ -27,10 +31,7 @@ public Context getContext() {
2731
return context;
2832
}
2933

30-
public Scope getScope() {
31-
return scope;
32-
}
33-
34+
@Nullable
3435
public static AdviceScope start(Context parentContext, ActionData actionData) {
3536
if (!instrumenter().shouldStart(parentContext, actionData)) {
3637
return null;
@@ -46,8 +47,14 @@ public void closeScope() {
4647
}
4748
}
4849

49-
public void end(Throwable throwable) {
50+
public void end(Throwable throwable, Future<Result> responseFuture, Action<?> thisAction) {
5051
closeScope();
51-
instrumenter().end(context, actionData, null, throwable);
52+
53+
if (throwable == null) {
54+
responseFuture.onComplete(
55+
new RequestCompleteCallback(getContext()), thisAction.executionContext());
56+
} else {
57+
instrumenter().end(context, actionData, null, throwable);
58+
}
5259
}
5360
}

0 commit comments

Comments
 (0)