Skip to content

Commit 2bfc1e8

Browse files
Ensure all response body advices are OnMethodEnter (#9046)
1 parent dd59589 commit 2bfc1e8

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

dd-java-agent/instrumentation/play-2.4/src/main/java_play25/datadog/trace/instrumentation/play25/appsec/ResultsStatusApplyAdvice.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
public class ResultsStatusApplyAdvice {
2121

2222
@Advice.OnMethodEnter(suppress = Throwable.class)
23-
static void after(
24-
@Advice.Argument(0) final Object content, @ActiveRequestContext RequestContext reqCtx) {
23+
static void before(
24+
@Advice.Argument(0) final Object content, @ActiveRequestContext final RequestContext reqCtx) {
2525

2626
if (!(content instanceof JsValue)) {
2727
return;

dd-java-agent/instrumentation/play-2.4/src/main/java_play25/datadog/trace/instrumentation/play25/appsec/StatusHeaderSendJsonAdvice.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,10 @@
2121
public class StatusHeaderSendJsonAdvice {
2222

2323
@Advice.OnMethodEnter(suppress = Throwable.class)
24-
static void before() {
25-
CallDepthThreadLocalMap.incrementCallDepth(StatusHeader.class);
26-
}
24+
static void before(
25+
@Advice.Argument(0) final JsonNode json, @ActiveRequestContext final RequestContext reqCtx) {
2726

28-
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
29-
static void after(
30-
@Advice.Argument(0) final JsonNode json, @ActiveRequestContext RequestContext reqCtx) {
31-
final int depth = CallDepthThreadLocalMap.decrementCallDepth(StatusHeader.class);
32-
if (depth > 0) {
27+
if (CallDepthThreadLocalMap.incrementCallDepth(StatusHeader.class) > 0) {
3328
return;
3429
}
3530

@@ -64,4 +59,9 @@ static void after(
6459
throw new BlockingException("Blocked request (for StatusHeader/sendJson)");
6560
}
6661
}
62+
63+
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
64+
static void after() {
65+
CallDepthThreadLocalMap.decrementCallDepth(StatusHeader.class);
66+
}
6767
}

dd-java-agent/instrumentation/play-2.6/src/main/java/datadog/trace/instrumentation/play26/appsec/StatusHeaderInstrumentation.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,11 @@ public void methodAdvice(MethodTransformer transformer) {
5858
public static class StatusHeaderSendJsonAdvice {
5959

6060
@Advice.OnMethodEnter(suppress = Throwable.class)
61-
static void before() {
62-
CallDepthThreadLocalMap.incrementCallDepth(StatusHeader.class);
63-
}
61+
static void before(
62+
@Advice.Argument(0) final JsonNode json,
63+
@ActiveRequestContext final RequestContext reqCtx) {
6464

65-
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
66-
static void after(
67-
@Advice.Argument(0) final JsonNode json, @ActiveRequestContext RequestContext reqCtx) {
68-
final int depth = CallDepthThreadLocalMap.decrementCallDepth(StatusHeader.class);
69-
if (depth > 0) {
65+
if (CallDepthThreadLocalMap.incrementCallDepth(StatusHeader.class) > 0) {
7066
return;
7167
}
7268

@@ -102,4 +98,9 @@ static void after(
10298
}
10399
}
104100
}
101+
102+
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class)
103+
static void after() {
104+
CallDepthThreadLocalMap.decrementCallDepth(StatusHeader.class);
105+
}
105106
}

0 commit comments

Comments
 (0)