Skip to content

Commit 760e04d

Browse files
committed
revert instrumenter changes, move advicescope into advice class
1 parent ed566b9 commit 760e04d

File tree

3 files changed

+50
-68
lines changed

3 files changed

+50
-68
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: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88
import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext;
99
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed;
1010
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.implementsInterface;
11+
import static io.opentelemetry.javaagent.instrumentation.play.v2_4.Play24Singletons.instrumenter;
12+
import static io.opentelemetry.javaagent.instrumentation.play.v2_4.Play24Singletons.updateSpan;
1113
import static net.bytebuddy.matcher.ElementMatchers.named;
1214
import static net.bytebuddy.matcher.ElementMatchers.returns;
1315
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
1416

17+
import io.opentelemetry.context.Context;
18+
import io.opentelemetry.context.Scope;
1519
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
1620
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
1721
import javax.annotation.Nullable;
@@ -65,4 +69,45 @@ public static void stopTraceOnResponse(
6569
actionScope.end(throwable, responseFuture, (Action<?>) thisAction, req);
6670
}
6771
}
72+
73+
public static class AdviceScope {
74+
75+
private final Context context;
76+
private final Scope scope;
77+
78+
public AdviceScope(Context context, Scope scope) {
79+
this.context = context;
80+
this.scope = scope;
81+
}
82+
83+
@Nullable
84+
public static AdviceScope start(Context parentContext) {
85+
if (!instrumenter().shouldStart(parentContext, null)) {
86+
return null;
87+
}
88+
89+
Context context = instrumenter().start(parentContext, null);
90+
return new AdviceScope(context, context.makeCurrent());
91+
}
92+
93+
public void closeScope() {
94+
if (scope != null) {
95+
scope.close();
96+
}
97+
}
98+
99+
public void end(
100+
Throwable throwable, Future<Result> responseFuture, Action<?> thisAction, Request<?> req) {
101+
closeScope();
102+
updateSpan(context, req);
103+
104+
if (throwable == null) {
105+
// span finished in RequestCompleteCallback
106+
responseFuture.onComplete(
107+
new RequestCompleteCallback(context), thisAction.executionContext());
108+
} else {
109+
instrumenter().end(context, null, null, throwable);
110+
}
111+
}
112+
}
68113
}

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

Lines changed: 0 additions & 59 deletions
This file was deleted.

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,11 @@
1717

1818
public final class Play24Singletons {
1919
private static final String SPAN_NAME = "play.request";
20-
private static final Instrumenter<Void, Void> INSTRUMENTER;
21-
22-
static {
23-
INSTRUMENTER =
24-
Instrumenter.<Void, Void>builder(
25-
GlobalOpenTelemetry.get(), "io.opentelemetry.play-mvc-2.4", s -> SPAN_NAME)
26-
.setEnabled(ExperimentalConfig.get().controllerTelemetryEnabled())
27-
.buildInstrumenter();
28-
}
20+
private static final Instrumenter<Void, Void> INSTRUMENTER =
21+
Instrumenter.<Void, Void>builder(
22+
GlobalOpenTelemetry.get(), "io.opentelemetry.play-mvc-2.4", s -> SPAN_NAME)
23+
.setEnabled(ExperimentalConfig.get().controllerTelemetryEnabled())
24+
.buildInstrumenter();
2925

3026
public static Instrumenter<Void, Void> instrumenter() {
3127
return INSTRUMENTER;

0 commit comments

Comments
 (0)