@@ -39,6 +39,8 @@ import datadog.trace.bootstrap.instrumentation.api.URIUtils
3939import datadog.trace.core.DDSpan
4040import datadog.trace.core.datastreams.StatsGroup
4141import datadog.trace.test.util.Flaky
42+ import groovy.json.JsonOutput
43+ import groovy.json.JsonSlurper
4244import groovy.transform.Canonical
4345import groovy.transform.CompileStatic
4446import net.bytebuddy.utility.RandomString
@@ -1590,9 +1592,10 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
15901592 void ' test instrumentation gateway json response body' () {
15911593 setup :
15921594 assumeTrue(testResponseBodyJson())
1595+ final body = [a : ' x' ]
15931596 def request = request(
15941597 BODY_JSON , ' POST' ,
1595- RequestBody . create(MediaType . get(' application/json' ), ' {"a": "x"} ' ))
1598+ RequestBody . create(MediaType . get(' application/json' ), JsonOutput . toJson(body) ))
15961599 .header(IG_RESPONSE_BODY_TAG , ' true' )
15971600 .build()
15981601 def response = client. newCall(request). execute()
@@ -1605,11 +1608,14 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
16051608
16061609 when :
16071610 TEST_WRITER . waitForTraces(1 )
1611+ def trace = TEST_WRITER . get(0 )
16081612
16091613 then :
1610- TEST_WRITER . get(0 ). any {
1611- it. getTag(' response.body' ) == ' [a:[x]]'
1612- }
1614+ ! trace. isEmpty()
1615+ def rootSpan = trace. find { it. parentId == 0 }
1616+ assert rootSpan != null
1617+ final responseBody = rootSpan. getTag(' response.body' ) as String
1618+ new JsonSlurper (). parseText(responseBody) == body
16131619
16141620 and :
16151621 if (isDataStreamsEnabled()) {
@@ -2497,21 +2503,10 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
24972503
24982504 final BiFunction<RequestContext , Object , Flow<Void > > responseBodyObjectCb =
24992505 ({ RequestContext rqCtxt , Object obj ->
2500- if (obj instanceof Map ) {
2501- obj = obj. collectEntries {
2502- [
2503- it. key,
2504- (it. value instanceof Iterable || it. value instanceof String []) ? it. value : [it. value]
2505- ]
2506- }
2507- } else if (! (obj instanceof String ) && ! (obj instanceof List )) {
2508- obj = obj. properties
2509- .findAll { it. key != ' class' }
2510- .collectEntries { [it. key, it. value instanceof Iterable ? it. value : [it. value]] }
2511- }
2506+ String body = obj. toString()
25122507 Context context = rqCtxt. getData(RequestContextSlot . APPSEC )
25132508 if (context. responseBodyTag) {
2514- rqCtxt. traceSegment. setTagTop(' response.body' , obj as String )
2509+ rqCtxt. traceSegment. setTagTop(' response.body' , body )
25152510 }
25162511 if (context. responseBlock) {
25172512 new RbaFlow (
0 commit comments