1
1
package datadog.trace.agent.test.base
2
2
3
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.BODY_JSON
4
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.BODY_MULTIPART
5
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.BODY_URLENCODED
6
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.CREATED
7
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.CREATED_IS
8
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.CUSTOM_EXCEPTION
9
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.ERROR
10
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
11
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.FORWARDED
12
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
13
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
14
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.QUERY_ENCODED_BOTH
15
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.QUERY_ENCODED_QUERY
16
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
17
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.REDIRECT
18
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.SESSION_ID
19
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.SUCCESS
20
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.TIMEOUT
21
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.TIMEOUT_ERROR
22
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.UNKNOWN
23
+ import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.USER_BLOCK
24
+ import static datadog.trace.agent.test.utils.TraceUtils.basicSpan
25
+ import static datadog.trace.agent.test.utils.TraceUtils.runUnderTrace
26
+ import static datadog.trace.api.config.TraceInstrumentationConfig.HTTP_SERVER_RAW_QUERY_STRING
27
+ import static datadog.trace.api.config.TraceInstrumentationConfig.HTTP_SERVER_RAW_RESOURCE
28
+ import static datadog.trace.api.config.TraceInstrumentationConfig.HTTP_SERVER_TAG_QUERY_STRING
29
+ import static datadog.trace.api.config.TraceInstrumentationConfig.SERVLET_ASYNC_TIMEOUT_ERROR
30
+ import static datadog.trace.api.config.TracerConfig.HEADER_TAGS
31
+ import static datadog.trace.api.config.TracerConfig.REQUEST_HEADER_TAGS
32
+ import static datadog.trace.api.config.TracerConfig.RESPONSE_HEADER_TAGS
33
+ import static datadog.trace.bootstrap.blocking.BlockingActionHelper.TemplateType.JSON
34
+ import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeScope
35
+ import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan
36
+ import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.get
37
+ import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopSpan
38
+ import static datadog.trace.bootstrap.instrumentation.decorator.HttpServerDecorator.SERVER_PATHWAY_EDGE_TAGS
39
+ import static java.nio.charset.StandardCharsets.UTF_8
40
+ import static org.junit.Assume.assumeTrue
41
+
3
42
import ch.qos.logback.classic.Level
4
43
import datadog.appsec.api.blocking.Blocking
5
44
import datadog.appsec.api.blocking.BlockingContentType
@@ -28,6 +67,7 @@ import datadog.trace.api.iast.IastContext
28
67
import datadog.trace.api.normalize.SimpleHttpPathNormalizer
29
68
import datadog.trace.bootstrap.blocking.BlockingActionHelper
30
69
import datadog.trace.bootstrap.instrumentation.api.AgentTracer
70
+ import datadog.trace.bootstrap.instrumentation.api.InstrumentationTags
31
71
import datadog.trace.bootstrap.instrumentation.api.Tags
32
72
import datadog.trace.bootstrap.instrumentation.api.URIDataAdapter
33
73
import datadog.trace.bootstrap.instrumentation.api.URIUtils
@@ -50,45 +90,6 @@ import java.util.function.BiFunction
50
90
import java.util.function.Function
51
91
import java.util.function.Supplier
52
92
53
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.BODY_JSON
54
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.BODY_MULTIPART
55
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.BODY_URLENCODED
56
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.CREATED
57
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.CREATED_IS
58
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.CUSTOM_EXCEPTION
59
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.ERROR
60
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
61
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.FORWARDED
62
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
63
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
64
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.QUERY_ENCODED_BOTH
65
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.QUERY_ENCODED_QUERY
66
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
67
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.REDIRECT
68
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.SESSION_ID
69
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.SUCCESS
70
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.TIMEOUT
71
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.TIMEOUT_ERROR
72
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.UNKNOWN
73
- import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.USER_BLOCK
74
- import static datadog.trace.agent.test.utils.TraceUtils.basicSpan
75
- import static datadog.trace.agent.test.utils.TraceUtils.runUnderTrace
76
- import static datadog.trace.api.config.TraceInstrumentationConfig.HTTP_SERVER_RAW_QUERY_STRING
77
- import static datadog.trace.api.config.TraceInstrumentationConfig.HTTP_SERVER_RAW_RESOURCE
78
- import static datadog.trace.api.config.TraceInstrumentationConfig.HTTP_SERVER_TAG_QUERY_STRING
79
- import static datadog.trace.api.config.TraceInstrumentationConfig.SERVLET_ASYNC_TIMEOUT_ERROR
80
- import static datadog.trace.api.config.TracerConfig.HEADER_TAGS
81
- import static datadog.trace.api.config.TracerConfig.REQUEST_HEADER_TAGS
82
- import static datadog.trace.api.config.TracerConfig.RESPONSE_HEADER_TAGS
83
- import static datadog.trace.bootstrap.blocking.BlockingActionHelper.TemplateType.JSON
84
- import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeScope
85
- import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan
86
- import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.get
87
- import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopSpan
88
- import static datadog.trace.bootstrap.instrumentation.decorator.HttpServerDecorator.SERVER_PATHWAY_EDGE_TAGS
89
- import static java.nio.charset.StandardCharsets.UTF_8
90
- import static org.junit.Assume.assumeTrue
91
-
92
93
abstract class HttpServerTest <SERVER> extends WithHttpServer<SERVER> {
93
94
94
95
public static final Logger SERVER_LOGGER = LoggerFactory . getLogger(" http-server" )
@@ -208,9 +209,9 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
208
209
// Only used if hasExtraErrorInformation is true
209
210
Map<String , Serializable > expectedExtraErrorInformation (ServerEndpoint endpoint ) {
210
211
if (endpoint. errored) {
211
- [" error.message" : { it == null || it == EXCEPTION . body },
212
- " error.type" : { it == null || it == Exception . name },
213
- " error.stack" : { it == null || it instanceof String }]
212
+ [" error.message" : { it == null || it == EXCEPTION . body },
213
+ " error.type" : { it == null || it == Exception . name },
214
+ " error.stack" : { it == null || it instanceof String }]
214
215
} else {
215
216
Collections . emptyMap()
216
217
}
@@ -492,8 +493,8 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
492
493
}
493
494
494
495
private static final Map<String , ServerEndpoint > PATH_MAP = {
495
- Map<String , ServerEndpoint > map = values(). collectEntries { [it. path, it]}
496
- map. putAll(values(). collectEntries { [it. rawPath, it]})
496
+ Map<String , ServerEndpoint > map = values(). collectEntries { [it. path, it] }
497
+ map. putAll(values(). collectEntries { [it. rawPath, it] })
497
498
map
498
499
}. call()
499
500
@@ -701,9 +702,9 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
701
702
}
702
703
703
704
where :
704
- method | body | header | value | tags
705
- ' GET' | null | ' x-datadog-test-both-header' | ' foo' | [ ' both_header_tag' : ' foo' ]
706
- ' GET' | null | ' x-datadog-test-request-header' | ' bar' | [ ' request_header_tag' : ' bar' ]
705
+ method | body | header | value | tags
706
+ ' GET' | null | ' x-datadog-test-both-header' | ' foo' | [' both_header_tag' : ' foo' ]
707
+ ' GET' | null | ' x-datadog-test-request-header' | ' bar' | [' request_header_tag' : ' bar' ]
707
708
}
708
709
709
710
@Flaky (value = " https://github.com/DataDog/dd-trace-java/issues/4690" , suites = [" MuleHttpServerForkedTest" ])
@@ -715,7 +716,7 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
715
716
def body = null
716
717
def header = IG_RESPONSE_HEADER
717
718
def mapping = ' mapped_response_header_tag'
718
- def tags = [' mapped_response_header_tag' : " $IG_RESPONSE_HEADER_VALUE " ]
719
+ def tags = [' mapped_response_header_tag' : " $IG_RESPONSE_HEADER_VALUE " ]
719
720
720
721
injectSysConfig(HTTP_SERVER_TAG_QUERY_STRING , " true" )
721
722
injectSysConfig(RESPONSE_HEADER_TAGS , " $header :$mapping " )
@@ -798,13 +799,13 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
798
799
}
799
800
800
801
where :
801
- rawQuery | endpoint | encoded
802
- true | SUCCESS | false
803
- true | QUERY_PARAM | false
804
- true | QUERY_ENCODED_QUERY | true
805
- false | SUCCESS | false
806
- false | QUERY_PARAM | false
807
- false | QUERY_ENCODED_QUERY | true
802
+ rawQuery | endpoint | encoded
803
+ true | SUCCESS | false
804
+ true | QUERY_PARAM | false
805
+ true | QUERY_ENCODED_QUERY | true
806
+ false | SUCCESS | false
807
+ false | QUERY_PARAM | false
808
+ false | QUERY_ENCODED_QUERY | true
808
809
809
810
method = " GET"
810
811
body = null
@@ -917,7 +918,7 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
917
918
}
918
919
919
920
then :
920
- DDSpan span = TEST_WRITER . flatten(). find {it. operationName == ' appsec-span' }
921
+ DDSpan span = TEST_WRITER . flatten(). find { it. operationName == ' appsec-span' }
921
922
span. getTag(IG_PATH_PARAMS_TAG ) == expectedIGPathParams()
922
923
923
924
and :
@@ -1611,7 +1612,7 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
1611
1612
then :
1612
1613
TEST_WRITER . waitForTraces(1 )
1613
1614
def trace = TEST_WRITER . get(0 )
1614
- assert trace. find {it. isError() } == null
1615
+ assert trace. find { it. isError() } == null
1615
1616
}
1616
1617
1617
1618
def ' test blocking of request for path parameters' () {
@@ -1692,7 +1693,8 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
1692
1693
spans. find { it. tags[' appsec.blocked' ] == ' true' } != null
1693
1694
spans. find {
1694
1695
it. error &&
1695
- it. tags[' error.type' ] == BlockingException . name } != null
1696
+ it. tags[' error.type' ] == BlockingException . name
1697
+ } != null
1696
1698
1697
1699
and :
1698
1700
if (isDataStreamsEnabled()) {
@@ -1872,7 +1874,7 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
1872
1874
if (isDataStreamsEnabled()) {
1873
1875
TEST_DATA_STREAMS_WRITER . waitForGroups(1 )
1874
1876
}
1875
- DDSpan span = TEST_WRITER . flatten(). find {it. operationName == ' appsec-span' }
1877
+ DDSpan span = TEST_WRITER . flatten(). find { it. operationName == ' appsec-span' }
1876
1878
span != null
1877
1879
final sessionId = span. tags[IG_SESSION_ID_TAG ]
1878
1880
sessionId != null
@@ -1964,7 +1966,10 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
1964
1966
" $Tags . HTTP_FORWARDED_IP " endpoint. body
1965
1967
}
1966
1968
if (null != expectedServerSpanRoute) {
1967
- " $Tags . HTTP_ROUTE " expectedServerSpanRoute
1969
+ " $Tags . HTTP_ROUTE " . expectedServerSpanRoute
1970
+ }
1971
+ if (span. getTag(InstrumentationTags . SERVLET_PATH ) != null ) {
1972
+ assert span. getTag(InstrumentationTags . SERVLET_PATH ). toString(). startsWith(" /" )
1968
1973
}
1969
1974
if (null != expectedExtraErrorInformation) {
1970
1975
addTags(expectedExtraErrorInformation)
0 commit comments