Skip to content

Commit 4f428b1

Browse files
authored
Fix HttpServer AppSec Flaky Tests (#9956)
1 parent 29d5c2d commit 4f428b1

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

dd-java-agent/instrumentation-testing/src/main/groovy/datadog/trace/agent/test/base/HttpServerTest.groovy

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2432,15 +2432,18 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
24322432

24332433
final BiFunction<RequestContext, IGSpanInfo, Flow<Void>> requestEndedCb =
24342434
({ RequestContext rqCtxt, IGSpanInfo info ->
2435-
Context context = rqCtxt.getData(RequestContextSlot.APPSEC)
2436-
if (context.responseBodyTag) {
2437-
rqCtxt.traceSegment.setTagTop('response.body', context.responseBody)
2438-
}
2439-
if (context.extraSpanName) {
2440-
runUnderTrace(context.extraSpanName, false) {
2441-
def span = activeSpan()
2442-
context.tags.each { key, val ->
2443-
span.setTag(key, val)
2435+
Object contextObj = rqCtxt.getData(RequestContextSlot.APPSEC)
2436+
if (contextObj instanceof Context) {
2437+
Context context = (Context) contextObj
2438+
if (context.responseBodyTag) {
2439+
rqCtxt.traceSegment.setTagTop('response.body', context.responseBody)
2440+
}
2441+
if (context.extraSpanName) {
2442+
runUnderTrace(context.extraSpanName, false) {
2443+
def span = activeSpan()
2444+
context.tags.each { key, val ->
2445+
span.setTag(key, val)
2446+
}
24442447
}
24452448
}
24462449
}
@@ -2649,8 +2652,9 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
26492652

26502653
final BiFunction<RequestContext, String, Flow<Void>> requestSessionCb =
26512654
{ RequestContext rqCtxt, String sessionId ->
2652-
Context context = rqCtxt.getData(RequestContextSlot.APPSEC)
2653-
if (sessionId != null) {
2655+
Object contextObj = rqCtxt.getData(RequestContextSlot.APPSEC)
2656+
if (contextObj instanceof Context && sessionId != null) {
2657+
Context context = (Context) contextObj
26542658
context.extraSpanName = 'appsec-span'
26552659
context.tags.put(IG_SESSION_ID_TAG, sessionId)
26562660
}

0 commit comments

Comments
 (0)