@@ -48,6 +48,8 @@ abstract class AbstractServlet3Test<CONTEXT> extends AgentTestRunner {
4848 addServlet(context, " /blocking" , TestServlet3.BlockingAsync )
4949 addServlet(context, " /dispatch/sync" , TestServlet3.DispatchSync )
5050 addServlet(context, " /dispatch/async" , TestServlet3.DispatchAsync )
51+ addServlet(context, " /dispatch/recursive" , TestServlet3.DispatchRecursive )
52+ addServlet(context, " /recursive" , TestServlet3.DispatchRecursive )
5153 addServlet(context, " /fake" , TestServlet3.FakeAsync )
5254 }
5355
@@ -116,10 +118,10 @@ abstract class AbstractServlet3Test<CONTEXT> extends AgentTestRunner {
116118 " fake" | " Hello FakeAsync" | false | " FakeAsync" | true
117119 }
118120
119- def " test dispatch #path" () {
121+ def " test dispatch #path with depth #depth " () {
120122 setup :
121123 def requestBuilder = new Request.Builder ()
122- .url(" http://localhost:$port /$context /dispatch/$path " )
124+ .url(" http://localhost:$port /$context /dispatch/$path ?depth= $d epth " )
123125 .get()
124126 if (distributedTracing) {
125127 requestBuilder. header(" x-datadog-trace-id" , " 123" )
@@ -130,14 +132,51 @@ abstract class AbstractServlet3Test<CONTEXT> extends AgentTestRunner {
130132 expect :
131133 response. body(). string(). trim() == " Hello $origin "
132134
133- assertTraces(2 ) {
134- trace(0 , 1 ) {
135+ assertTraces(2 + depth) {
136+ for (int i = 0 ; i < depth; i++ ) {
137+ trace(i, 1 ) {
138+ span(0 ) {
139+ if (i == 0 ) {
140+ if (distributedTracing) {
141+ traceId " 123"
142+ parentId " 456"
143+ } else {
144+ parent()
145+ }
146+ } else {
147+ childOf TEST_WRITER [i - 1 ][0 ]
148+ }
149+ serviceName context
150+ operationName " servlet.request"
151+ resourceName " GET /$context /dispatch/$path "
152+ spanType DDSpanTypes . WEB_SERVLET
153+ errored false
154+ tags {
155+ " http.url" " http://localhost:$port /$context /dispatch/$path "
156+ " http.method" " GET"
157+ " span.kind" " server"
158+ " component" " java-web-servlet"
159+ " span.origin.type" { it == " TestServlet3\$ Dispatch$origin " || it == ApplicationFilterChain . name }
160+ " span.type" DDSpanTypes . WEB_SERVLET
161+ " http.status_code" 200
162+ " servlet.context" " /$context "
163+ " servlet.dispatch" " /dispatch/recursive?depth=${ depth - i - 1} "
164+ defaultTags(i > 0 ? true : distributedTracing)
165+ }
166+ }
167+ }
168+ }
169+ trace(depth, 1 ) {
135170 span(0 ) {
136- if (distributedTracing) {
137- traceId " 123"
138- parentId " 456"
171+ if (depth > 0 ) {
172+ childOf TEST_WRITER [depth - 1 ][0 ]
139173 } else {
140- parent()
174+ if (distributedTracing) {
175+ traceId " 123"
176+ parentId " 456"
177+ } else {
178+ parent()
179+ }
141180 }
142181 serviceName context
143182 operationName " servlet.request"
@@ -154,24 +193,26 @@ abstract class AbstractServlet3Test<CONTEXT> extends AgentTestRunner {
154193 " http.status_code" 200
155194 " servlet.context" " /$context "
156195 " servlet.dispatch" " /$path "
157- defaultTags(distributedTracing)
196+ defaultTags(depth > 0 ? true : distributedTracing)
158197 }
159198 }
160199 }
161- trace(1 , 1 ) {
200+ trace(depth + 1 , 1 ) {
162201 span(0 ) {
163202 serviceName context
164203 operationName " servlet.request"
165204 resourceName " GET /$context /$path "
166205 spanType DDSpanTypes . WEB_SERVLET
167206 errored false
168- childOf TEST_WRITER [0 ][0 ]
207+ childOf TEST_WRITER [depth ][0 ]
169208 tags {
170209 " http.url" " http://localhost:$port /$context /$path "
171210 " http.method" " GET"
172211 " span.kind" " server"
173212 " component" " java-web-servlet"
174- " span.origin.type" { it == " TestServlet3\$ $origin " || it == ApplicationFilterChain . name }
213+ " span.origin.type" {
214+ it == " TestServlet3\$ $origin " || it == " TestServlet3\$ DispatchRecursive" || it == ApplicationFilterChain . name
215+ }
175216 " span.type" DDSpanTypes . WEB_SERVLET
176217 " http.status_code" 200
177218 " servlet.context" " /$context "
@@ -182,11 +223,17 @@ abstract class AbstractServlet3Test<CONTEXT> extends AgentTestRunner {
182223 }
183224
184225 where :
185- path | distributedTracing
186- " sync" | true
187- " sync" | false
188- " async" | true
189- " async" | false
226+ path | distributedTracing | depth
227+ " sync" | true | 0
228+ " sync" | false | 0
229+ " async" | true | 0
230+ " async" | false | 0
231+ " recursive" | true | 0
232+ " recursive" | false | 0
233+ " recursive" | true | 1
234+ " recursive" | false | 1
235+ " recursive" | true | 20
236+ " recursive" | false | 20
190237
191238 origin = path. capitalize()
192239 }
0 commit comments